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

RequestMappingHandlerMapping matches uri with percent encoded characters [SPR-12274] #16879

Closed
spring-projects-issues opened this issue Sep 30, 2014 · 2 comments
Assignees
Labels
in: core in: web status: declined

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 30, 2014

Michal opened SPR-12274 and commented

As described in provided question on stackoverflow. In spring mvc application i found out that org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping matches some requests to controllers instead of returning no match. Mentioned requests contain percent encoded characters in front of path part of uri.
Example requests:
http://www.example.pl/%06api/1.0/client/abc - is decoded to /^Fapi/1.0/client/abc but matches /api/1.0/client/abc
http://www.example.pl/%0bapi/1.0/client/abc - is decoded to /^Kapi/1.0/client/abc but matches /api/1.0/client/abc

Example logs for first request :
DEBUG RequestMappingHandlerMapping - Looking up handler method for path /^Fapi/1.0/client/abc
TRACE RequestMappingHandlerMapping - Found 1 matching mapping(s) for [/^Fapi/1.0/client/abc] : [{[/api/1.0/client/{clientId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}]

Not every percent encoded character applies here, for some of them behavior is correct and application returns http 404:
http://www.example.pl/%83api/1.0/client/abc - returns 404, is decoded to /�api/1.0/client/abc and does not match /api/1.0/client/abc

I am not having issues with encoding neither in application nor in tomcat container. In web.xml file in application i have CharacterEncodingFilter filter with UTF-8 encoding. Application runs on Tomcat 7 with http and ajp connectors configured with URIEncoding="UTF-8".
I guess that all percent encoded characters are decoded correctly and problem is somewhere in RequestMappingHandlerMapping matching mechanism.


Affects: 3.2.8

Reference URL: http://stackoverflow.com/questions/26110136/spring-mvc-uri-mapping-with-percent-encoded-characters

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 30, 2014

Rossen Stoyanchev commented

AntPathMatcher tokenizes the path and by default trims all segments. This behavior can be controlled. You'll need to configure the RequestMappingHandlerMapping with an AntPathMatcher with setTrimTokens(false).

Also note that in the 4.0 line (and higher) the MVC Java config and namespace have dedicated support for plugging in a custom PathMatcher. For 3.2.x follow the instructions in the reference for advanced MVC config changes.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 30, 2014

Michal commented

Thank you for your time. I have checked your solution and i confirm that setting trimTokens to false on AntPathMatcher solves described problem.

@spring-projects-issues spring-projects-issues added type: bug status: declined in: core in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core in: web status: declined
Projects
None yet
Development

No branches or pull requests

2 participants