Skip to content

Commit

Permalink
Issue #6497 - Fix AllowedResourceAliasChecker if protectedTarget does…
Browse files Browse the repository at this point in the history
… not exist

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jul 30, 2021
1 parent a7639bc commit 32bff77
Showing 1 changed file with 8 additions and 5 deletions.
Expand Up @@ -84,7 +84,7 @@ protected void doStart() throws Exception
{
for (String s : protectedTargets)
{
_protectedPaths.add(_basePath.resolve(s));
_protectedPaths.add(new File(_basePath.toFile(), s).toPath());
}
}
}
Expand Down Expand Up @@ -155,12 +155,15 @@ protected boolean isProtectedPath(Path resourcePath, LinkOption[] linkOptions) t

for (Path protectedPath : _protectedPaths)
{
// We know the targetPath exists, so if protectedPath doesn't exist then targetPath cannot be a child of it.
if (!Files.exists(protectedPath, linkOptions))
continue;
String protect;
if (Files.exists(protectedPath, linkOptions))
protect = protectedPath.toRealPath(linkOptions).toString();
else if (linkOptions == NO_FOLLOW_LINKS)
protect = protectedPath.normalize().toAbsolutePath().toString();
else
protect = protectedPath.toFile().getCanonicalPath();

// If the target path is protected then we will not allow it.
String protect = protectedPath.toRealPath(linkOptions).toString();
if (StringUtil.startsWithIgnoreCase(target, protect))
{
if (target.length() == protect.length())
Expand Down

0 comments on commit 32bff77

Please sign in to comment.