Skip to content

Fix '+' character in query parameters is not encoded when rewrite query parameter in mvc #3798

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

Conversation

raccoonback
Copy link
Contributor

@raccoonback raccoonback commented May 16, 2025

Description

When a + character is included in an HTTP query parameter, it is currently interpreted as a space in cases where the BeforeFilterFunctions.rewriteRequestParameter() is applied. This may result in the parameter being misinterpreted on the server side compared to its original intent.

In this PR, we have applied precise encoding based on StandardCharsets.UTF_8 or replaced the use of UriUtils.encodeQueryParams() with a MvcUtils.encodeQueryParams() custom utility to ensure that the + character is correctly encoded as %2B.

Changes:

  • Replacing + with %2B after standard encoding
  • Added corresponding unit test

(The BeforeFilterFunctions.rewriteRequestParameter() method is only present in the main branch.)

For example.

[AS-IS]
"http://localhost/path?foo=A&bar=B%2B" -> "http://localhost/path?foo=A&bar=B " (The value of the 'bar' query parameter is encoded as a 'B '.)

[TO-BE]
"http://localhost/path?foo=A&bar=B%2B" -> "http://localhost/path?foo=A&bar=%2B"

…uery parameter

Signed-off-by: raccoonback <kosb15@naver.com>
@raccoonback
Copy link
Contributor Author

raccoonback commented May 23, 2025

@ryanjbaxter
Hello.
I've incorporated the same handling as in #3799 for the BeforeFilterFunctions.rewriteRequestParameter() filter, which currently exists only on the main branch.

Please take a look when you have a chance.
Thanks!

@ryanjbaxter ryanjbaxter added this to the 4.3.0 milestone May 23, 2025
@ryanjbaxter
Copy link
Contributor

Thanks for the ping. I actually made the change in BeforeFilterFunctions yesterday when merging #3799. The additional tests are useful though, thanks.

@ryanjbaxter ryanjbaxter merged commit 5b26387 into spring-cloud:main May 23, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this to Done in 2025.0.0 May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants