-
Couldn't load subscription status.
- Fork 38.8k
Make multiple slash sanitization optional in web util #34242
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.