Fix httpexchanges filter missing Security-rejected requests#50765
Open
VedPatel2811 wants to merge 1 commit into
Open
Fix httpexchanges filter missing Security-rejected requests#50765VedPatel2811 wants to merge 1 commit into
VedPatel2811 wants to merge 1 commit into
Conversation
Add HttpExchangesStartingFilter that runs at HIGHEST_PRECEDENCE + 1 to record exchanges before Spring Security can short-circuit the filter chain. HttpExchangesFilter coordinates with it via request attributes to avoid double-recording. Fixes spring-projectsgh-6545 Signed-off-by: Ved Patel <veds28112004@gmail.com>
762f299 to
b0026a2
Compare
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.
Problem
The /actuator/httpexchanges endpoint (formerly /trace) does not record
requests that are rejected by Spring Security, because HttpExchangesFilter
runs at LOWEST_PRECEDENCE - 10, after Spring Security's FilterChainProxy
has already short-circuited the request.
Solution
Add a new HttpExchangesStartingFilter that runs at HIGHEST_PRECEDENCE + 1
(before Spring Security). It starts recording the exchange and stores the
HttpExchange.Started instance as a request attribute. HttpExchangesFilter
is updated to reuse that attribute when present, and signals back via a
second attribute to prevent double-recording. If HttpExchangesFilter is
never reached (e.g. 401 from Security), the starting filter's finally
block records the exchange instead.
Testing
including filterRecordsWhenChainTerminatesEarly which directly
simulates the Security short-circuit scenario
both filters (twoFiltersCombinedRecordExchangeOnce,
filterReusesStartedExchangeFromStartingFilter,
filterSetsFinishedAttributeAfterRecording)
are registered as beans by autoconfiguration
Fixes gh-6545