-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #6497 - Replace the Alias checkers with new implementation. (Jetty-10) #6668
Conversation
Signed-off-by: Lachlan Roberts <[email protected]>
{ | ||
return String.format("%s@%x{checkSymlinkTargets=%s}", AllowedResourceAliasChecker.class.getSimpleName(), hashCode(), _checkSymlinkTargets); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
|
||
/** | ||
* <p>This will approve any alias to anything inside of the {@link ContextHandler}s resource base which | ||
* is not protected by {@link ContextHandler#isProtectedTarget(String)}.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* is not protected by {@link ContextHandler#isProtectedTarget(String)}.</p> | |
* is not protected by {@link #isProtectedTarget(Path, LinkOption[])}.</p> |
* <p>The resource path is protected if it is under one of the protected targets defined by | ||
* {@link ContextHandler#isProtectedTarget(String)} in which case the alias should not be allowed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <p>The resource path is protected if it is under one of the protected targets defined by | |
* {@link ContextHandler#isProtectedTarget(String)} in which case the alias should not be allowed. | |
* <p>The resource path is protected if it, or one of it's parents is in | |
* {@link ContextHandler#getProtectedTargets()} when fetched from {@link #doStart()}.</p> | |
* {@link ContextHandler#isProtectedTarget(String)} in which case the alias should not be allowed. |
for (Path protectedPath : _protectedPaths) | ||
{ | ||
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. | ||
if (StringUtil.startsWithIgnoreCase(target, protect)) | ||
{ | ||
if (target.length() == protect.length()) | ||
return true; | ||
|
||
// Check that the target prefix really is a path segment. | ||
if (target.charAt(protect.length()) == File.separatorChar) | ||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me of why we can't walk the parent tree again?
if (File.separatorChar == '/') | ||
addAliasCheck(new AllowSymLinkAliasChecker()); | ||
addAliasCheck(new SymlinkAllowedResourceAliasChecker(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we really still need this by default? I guesss too late to change in a dot release, but let's put a TODO in to remove if/when we go to 10.1
@@ -0,0 +1 @@ | |||
This file is inside a sibling dir to webroot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
@@ -0,0 +1 @@ | |||
This is the web.xml file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
@@ -0,0 +1 @@ | |||
This file is inside webroot/documents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
@@ -0,0 +1 @@ | |||
This file is inside webroot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
<html> | ||
<h1>hello world</h1> | ||
<p>body of index.html</p> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class AliasCheckerSymlinkTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be combined with or replace AllowSymlinkAliasCheckerTest
Replaced with PR #6681. |
Issue #6497
Deprecate and replace the
SameFileAliasChecker
with theAllowedResourceAliasChecker
which does some additional safety checks.This new AliasChecker is extended to also replace the
AllowSymLinkAliasChecker
withSymlinkAllowedResourceAliasChecker
.