Set Spring MVC context when RequestContextFilter is absent - #327
Open
Mishenevd wants to merge 2 commits into
Open
Set Spring MVC context when RequestContextFilter is absent#327Mishenevd wants to merge 2 commits into
Mishenevd wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The Spring MVC context was only created by wrapping RequestContextFilter#doFilterInternal. WebMvcAutoConfiguration does not register that filter when a RequestContextListener bean is present, so the context was never set: controllers logged "Received Spring Annotations, but no context set" on every request and input/IP/UA inspection did not run. Wrap FrameworkServlet#processRequest, which runs for every DispatcherServlet request regardless of the filter chain, and create the context when it is missing. A per-request marker set by the filter prevents double creation on the normal path.
Mishenevd
force-pushed
the
fix/spring-mvc-context-without-request-context-filter
branch
from
July 28, 2026 12:17
3d736db to
90eda45
Compare
New sample app (Spring Boot 4.0.7 / Spring 7, Jakarta) on HyperSQL that registers a RequestContextListener, which makes WebMvcAutoConfiguration skip the auto RequestContextFilter and forces Zen onto the FrameworkServlet#processRequest fallback. The e2e SQL-injection payload is blocked (500) with the fix and passes through (200) without it, guarding against regressions. Wired into the end2end matrix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Zen creates the Spring MVC context only by instrumenting
RequestContextFilter#doFilterInternal.WebMvcAutoConfiguration.requestContextFilter()is@ConditionalOnMissingBean({RequestContextListener.class, RequestContextFilter.class}), so when the application registers aRequestContextListenerbean the filter is never added to the chain. The context is then never set: controllers logReceived Spring Annotations, but no context seton every request, and input/IP/user-agent inspection does not run.Fix
Add
SpringMVCDispatcherWrapperwrappingFrameworkServlet#processRequest— the entry point of everyDispatcherServletrequest, independent of the filter chain — which creates the context when none exists. The filter sets a per-request marker the fallback checks, so the normal path is unchanged and the context is not created twice.Testing
Reproduced on Spring Boot 4.0.7 (Spring 7.0.8 / Tomcat 11.0.22) with a
RequestContextListenerbean: exact error on every request. Verified with the fix, forcing a single Tomcat worker thread, 3 sequential requests:RequestContextListenerpresent): 0 errors, 3 fresh contexts, correct per-request routes;