Skip to content

Set all dispatch types for OncePerRequestFilter #39859

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

Closed
wants to merge 2 commits into from

Conversation

fisco-unimatic
Copy link

As I said in a Stack Overflow question that I posted yesterday, Spring SessionRepositoryFilter is not applied to forwarded requests.
When there's an error, then the request is forwarded to /error, with a dispatch type of ERROR, but SessionRepositoryFilter is only applied to requests with dispatch type REQUEST. That means that a new session ID is created by tomcat, and the client uses this on subsequent requests, which are then rejected as unauthorized by the session repository.
AbstractFilterRegistrationBean#determineDispatcherTypes sets all dispatch types for filters that extend org.springframework.web.filter.OncePerRequestFilter in spring-web, but SessionRepositoryFilter extends org.springframework.session.web.http.OncePerRequestFilter in spring-session-core.
This change sets all dispatch types for filters extending either OncePerRequestFilter class.

We already do this for OncePerRequestFilter from spring-web, but there is a OncePerRequestFilter class in spring-session-core  as well.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 8, 2024
@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label Mar 8, 2024
@quaff
Copy link
Contributor

quaff commented Mar 11, 2024

It's very risky to change the behavior of org.springframework.web.filter.OncePerRequestFilter.

@wilkinsona
Copy link
Member

It's very risky to change the behavior of org.springframework.web.filter.OncePerRequestFilter.

Unless I have missed something, this PR doesn't do that. Instead, it's treating org.springframework.session.web.http.OncePerRequestFilter in the same way as we already treat org.springframework.web.filter.OncePerRequestFilter.

That said, I'm still not sure that this is something that we should do. I would prefer that it's fixed in Spring Session by it using org.springframework.web.filter.OncePerRequestFilter instead of org.springframework.session.web.http.OncePerRequestFilter, although we may still need to do something in the meantime. I've raised this with the Spring Session team and we're waiting to hear back from them.

@wilkinsona
Copy link
Member

wilkinsona commented Mar 11, 2024

Chatting with @marcusdacoregio, I was reminded that we have spring.session.servlet.filter-dispatcher-types to control the session filter's dispatcher types. It defaults to async, error, and request so determineDispatcherTypes on the filter registration bean should not be involved.

Judging by the problem description above, it sounds like that may not be working as intended. @fisco-unimatic thanks for the proposal here, but I don't think it's the right way to fix the problem that you seem to be having. Can you please open an issue with a minimal sample that reproduces it so that we can investigate?

@wilkinsona wilkinsona closed this Mar 11, 2024
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Mar 11, 2024
@fisco-unimatic
Copy link
Author

ok - I'll try to put together an example and then raise an issue

@fisco-unimatic
Copy link
Author

In case any ends up here looking for a solution to a similar problem, it turns out that our application was excluding SessionAutoConfiguration. If I remove that exclusion, then it imports SessionRepositoryFilterConfiguration, which sets the dispatch types.

If for some reason you wanted to exclude SessionAutoConfiguration, you could instead make your session configuration class extend AbstractHttpSessionApplicationInitializer. That would also set the dispatch types for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants