-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Make multiple slash sanitization optional in web util #34242
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,8 @@ public class UrlPathHelper { | |
|
||
private boolean removeSemicolonContent = true; | ||
|
||
private boolean sanitizePath = true; | ||
|
||
private String defaultEncoding = WebUtils.DEFAULT_CHARACTER_ENCODING; | ||
|
||
private boolean readOnly = false; | ||
|
@@ -145,6 +147,22 @@ public boolean shouldRemoveSemicolonContent() { | |
return this.removeSemicolonContent; | ||
} | ||
|
||
/** | ||
* Set if double slashes to be replaced by single slash in the request URI. | ||
* <p>Default is "true". | ||
*/ | ||
public void setSanitizePath(boolean sanitizePath) { | ||
checkReadOnly(); | ||
this.sanitizePath = sanitizePath; | ||
} | ||
|
||
/** | ||
* Whether configured to replace double slashes with single slash from the request URI. | ||
*/ | ||
public boolean shouldSanitizePath() { | ||
return this.sanitizePath; | ||
} | ||
|
||
/** | ||
* Set the default character encoding to use for URL decoding. | ||
* Default is ISO-8859-1, according to the Servlet spec. | ||
|
@@ -392,12 +410,16 @@ else if (index1 == requestUri.length()) { | |
} | ||
|
||
/** | ||
* Sanitize the given path. Uses the following rules: | ||
* Sanitize the given path if {code shouldSanitizePath()} is true. | ||
* Uses the following rules: | ||
* <ul> | ||
* <li>replace all "//" by "/"</li> | ||
* </ul> | ||
*/ | ||
private static String getSanitizedPath(final String path) { | ||
private String getSanitizedPath(final String path) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a private static method that had 2 usages in the class, made it non-static to use the flag. |
||
if (!shouldSanitizePath()) { | ||
return path; | ||
} | ||
int start = path.indexOf("//"); | ||
if (start == -1) { | ||
return path; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here we don't use the sanitizePath flag, but I couldn't come up with any other approach that requires minimal changes while addressing the sanitizePath flag, especially considering that two of the three implementations make use of it. If you have a better solution, I’d be happy to implement it.