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

HttpSessionRequestCache#getMatchingRequest passes decoded Request URL to UriComponentsBuilder #16656

Open
ClausMie opened this issue Feb 26, 2025 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: bug A general bug

Comments

@ClausMie
Copy link

Hi there!
Thanks for taking a look at this issue. Please let me know if you require more information.
Let's discuss!

Describe the bug

HttpSessionRequestCache#getMatchingRequest relies on org.springframework.web.util.UriComponentsBuilder#fromUriString(String) to be able to handle decoded % characters.

To Reproduce

The org.springframework.web.util.UriComponentsBuilder#fromUriString(String) cannot handle a % followed by characters that result in false %-encoding.

@Test
void unencodedPercent(){
  assertThatRuntimeException().isThrownBy(() -> UriComponentsBuilder.fromUriString("/30 % off"));
}

This leads to a org.springframework.web.util.InvalidUrlException: Bad path when such a request gets to HttpSessionRequestCache#getMatchingRequest.
An encoded request https://example.com/myapp/discounts/30%20%25%20off is returned decoded by UrlUtils#buildRequestUrl(HttpServletRequest.
The UriComponentsBuilder cannot handle this decoded %

Expected behavior
My request does not result in an InvalidUrlException.

@ClausMie ClausMie added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Feb 26, 2025
@mkleine
Copy link

mkleine commented Feb 28, 2025

In fact every request containing a properly encoded % sign followed by a non-hex character will cause an exception in line

|| !UriComponentsBuilder.fromUriString(UrlUtils.buildRequestUrl(request))
as the path of the URI to be checked is decoded as documented
* But the requestURI is not decoded, whereas the servletPath and pathInfo are

The decoded URI could be parsed using WHAT_WG parser type but that's not configurable at that line. @marcusdacoregio can you confirm this analysis? You introduced this line in 18e8836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants