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

ResourceHttpRequestHandler with PathPatternParser cannot resolve resources with a jsessionid URL #27913

Closed
bennypi opened this issue Dec 22, 2021 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@bennypi
Copy link

bennypi commented Dec 22, 2021

A simple showcase of this error can be found here: https://github.com/bennypi/thymeleaf-and-springboot

Expected behaviour

The expected behaviour can be seen when changing the spring boot version to 2.5.6. With this version, the linked css
can be retrieved and the form POST is working.

Current behaviour

Starting with spring boot version 2.6.0 and still present in 2.6.1, requests with the jsessionid parameter are not processed correctly but lead to errors on the server. A call to a CSS-file with the jsessionid parameter leads to a 404, the form POST request with the jsessionid parameter also leads to a 404. The page starts working again when the page is refreshed in the browser because the browser then sends a cookie with in the request which in turn removes the jsessionid parameter in the links in the HTML.

I am not completely sure if this indeed a bug in spring boot or if thymeleaf must make changes so that it is compatible with spring boot 2.6.0 and newer, but I don't see anything in the release notes that could be a reason for this changed behaviour.

@ztomic
Copy link

ztomic commented Dec 22, 2021

This is due to path matching strategy change to pattern based instead of ant. I've had same issue.

Workaround is to configure ant_path_matcher as matching strategy.

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

https://gitter.im/spring-projects/spring-boot?at=61ae129e8f98cb0811aa9c04

@bennypi
Copy link
Author

bennypi commented Dec 22, 2021

Thanks for the reply, I will test this workaround.

Nonetheless, I am still not sure what to think of this: AFAICT thymeleaf uses spring for URL rewriting. And spring rewrites the URLs into a format that spring can no longer process. How is this supposed to work with the new path matching strategy?

@philwebb
Copy link
Member

I think this might be a Spring Framework issue. Thymeleaf is calling HttpServletResponse.encodeURL(url) which adds ;jsessionid=....

Spring Framework has a ResourceHttpRequestHandler class that attempts to resolve resources. This line reads HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE which contains the jsessionid causing the resource to not be found.

I'm not sure if the value of PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE is wrong, or if the ResourceHttpRequestHandler should cleanup the path.

@philwebb philwebb changed the title Jan 11, 2022
@philwebb philwebb transferred this issue from spring-projects/spring-boot Jan 11, 2022
@philwebb
Copy link
Member

Transferring to the Framework team. Run the sample and do curl 'http://localhost:8080/css/main.css;jsessionid=27DE19AF0DE98353ECE4958BD868C6C5' to replicate the problem. It should return the css, instead it 404s

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 11, 2022
@poutsma poutsma added this to the Triage Queue milestone Jan 11, 2022
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jan 17, 2022
@rstoyanchev rstoyanchev self-assigned this Feb 14, 2022
@rstoyanchev
Copy link
Contributor

In most places we use PathPattern to pattern matching to the input RequestPath. The matching uses PathSegment#valueToMatch() which returns a decoded path, also cleaned from path parameters. For static resources, however, we use the full path based on PathContainer#value(), which is the original, raw path. We might need to expose an additional PathContainer#valueToMatch() that returns the path cleaned from path parameters.

@rstoyanchev rstoyanchev modified the milestones: Triage Queue, 5.3.16 Feb 14, 2022
@rstoyanchev rstoyanchev added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

7 participants