Skip to content
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

Closed

Conversation

lachlan-roberts
Copy link
Contributor

Issue #6497

Deprecate and replace the SameFileAliasChecker with the AllowedResourceAliasChecker which does some additional safety checks.

This new AliasChecker is extended to also replace the AllowSymLinkAliasChecker with SymlinkAllowedResourceAliasChecker.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
{
return String.format("%s@%x{checkSymlinkTargets=%s}", AllowedResourceAliasChecker.class.getSimpleName(), hashCode(), _checkSymlinkTargets);
}
}
Copy link
Contributor

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* is not protected by {@link ContextHandler#isProtectedTarget(String)}.</p>
* is not protected by {@link #isProtectedTarget(Path, LinkOption[])}.</p>

Comment on lines +138 to +139
* <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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* <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.

Comment on lines +161 to +181
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;
}
}
Copy link
Contributor

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));
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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>
Copy link
Contributor

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
Copy link
Contributor

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

@lachlan-roberts
Copy link
Contributor Author

Replaced with PR #6681.

@lachlan-roberts lachlan-roberts deleted the jetty-10.0.x-6497-AliasCheckers branch September 2, 2021 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants