-
Notifications
You must be signed in to change notification settings - Fork 3.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
Prevent duplicated encoding in mvc #3658
base: main
Are you sure you want to change the base?
Prevent duplicated encoding in mvc #3658
Conversation
The setPath method was causing URLs to be encoded twice under certain conditions. This fix ensures proper handling of parameters to avoid redundant encoding.
The stripPrefix method was causing URLs to be encoded twice under certain conditions. This fix ensures proper handling of parameters to avoid redundant encoding.
The removeRequestParameter method was causing URLs to be encoded twice under certain conditions. This fix ensures proper handling of parameters to avoid redundant encoding.
MultiValueMap<String, String> encodedQueryParams = UriUtils.encodeQueryParams(queryParams); | ||
|
||
// remove from uri | ||
URI newUri = UriComponentsBuilder.fromUri(request.uri()) | ||
.replaceQueryParams(unmodifiableMultiValueMap(queryParams)) | ||
.build() | ||
.replaceQueryParams(unmodifiableMultiValueMap(encodedQueryParams)) | ||
.build(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.
This change only re-encodes request parameters, and does not affect other segments such as the request path.
@@ -407,7 +412,7 @@ public static Function<ServerRequest, ServerRequest> stripPrefix(int parts) { | |||
|
|||
URI prefixedUri = UriComponentsBuilder.fromUri(request.uri()) | |||
.replacePath(newPath.toString()) | |||
.build() | |||
.build(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.
The stripped path is already encoded, so no additional encoding will be applied.
Furthermore, other parts such as request parameters are not affected.
URI prefixedUri = UriComponentsBuilder.fromUri(request.uri()) | ||
.replacePath(uri.getRawPath()) | ||
.build(true) | ||
.toUri(); |
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.
The modified path is already encoded, so no additional encoding will be applied.
Furthermore, other parts, such as request parameters, are not affected.
Motivation
There were issues with the
setPath()
andstripPrefix()
methods where already encoded URIs were being double-encoded.Also, the
removeRequestParameter()
method was also double-encoding not only request parameters but also paths and other components.Key Changes
setPath()
andstripPrefix()
methods have been fixed to prevent double encoding.removeRequestParameter()
has been updated to ensure that only request parameters are encoded.Reference
related with #3131