Repository navigation
Conversation
Filter selection removed path parameters only after decoding the request path, while Spring and Jersey remove them first and decode afterwards. When a parameter held an encoded character the two could end up with different paths, so a filter mapped to a multi-segment url-pattern did not run for a request that was still routed to the handler behind it. Filter selection now also matches the path with parameters removed from the raw path and decoded afterwards, both as is and normalized, and with repeated slashes collapsed but dot segments kept, which is how Spring's AntPathMatcher reads a request. The filter chain cache is keyed on the raw path, because the decoded path alone no longer determines which filters apply. Adds end-to-end tests under both Spring path matchers and in the Jersey module, and an opt-in test (-DfuzzFilterSelection=true) that compares filter selection with the framework's routing over generated path spellings.
bnusunny
left a comment
There was a problem hiding this comment.
Reviewed the change and ran an independent path corpus against this branch. The source diff matches #1735 and the tests are ported to the springboot2 module.
| Check | Result |
|---|---|
| Spring MVC, 389 paths x 3 event types | 0 filter skips (66 on 1.x without this change) |
| Jersey, 235 paths x 3 event types | 0 filter skips (81 on 1.x without this change) |
| CI | all 6 build jobs green |
Question: same as on #1735. filterCache is unbounded and now keyed per raw path. Is a size bound planned here or as a follow-up?
Non-blocking:
- The six-spelling comment in
getFilterChainis long. A short statement of the rule would do. - #1737 (the Spark/Struts JDK pin) has merged, so rebase if this branch has not picked it up.
The cache held one entry per distinct request path and never dropped any, and keying it on the raw path gives each spelling of a route its own entry. It now keeps the 1,000 most recently used chains. An evicted chain is worked out again on the next request for that path. Also shortens the comment in getFilterChain to the rule itself.
|
Thanks for running your own corpus on these, that's a nice extra check. Agreed on the raw-path key, that one has to stay. On the cache size: it was already unbounded before (one entry per decoded path), but yeah, keying on the raw path makes it grow faster. I added an LRU cap of 1,000 entries in a208ce0, with a test that a chain that got evicted still comes back with the same filters. Also trimmed the comment in getFilterChain. And #1737 is in, I merged 1.x into this branch so it's got the Spark/Struts fix. |
bnusunny
left a comment
There was a problem hiding this comment.
Approving. The cache bound is correct: eviction is least-recently-used at 1,000 entries, the key stays the full string, and the new test fails when eviction is disabled (cache holds 1,051 entries). CI is green.
Non-blocking: getFilterChain still calls getFilterChainCache twice (once for the null check, once to return). If an entry could be evicted between the two calls, the second returns null. Lambda runs one event at a time per container, so this is unlikely, but a single get removes the case.
Issue #, if available:
Description of changes:
Filter selection now matches url-patterns against the request path the way Spring and Jersey read it when the path carries path parameters, so a filter runs for every request that reaches the handler behind it.
The problem
FilterChainManager.getFilterChain()matches each filter's url-patterns against several forms of the request path. One of them removes path parameters (;...within a segment), but it removed them after percent-decoding. Spring and Jersey remove them from the raw path and decode afterwards. Once a parameter holds an encoded character the two can end up with different paths:/api;%2F/admin/secretdecodes to/api;//admin/secret, removing the parameter from that leaves/api//admin/secret, and a filter on/api/admin/*doesn't match it. Spring and Jersey route the same request to/api/admin/secret, so the handler ran without the filter.Spring's AntPathMatcher (
spring.mvc.pathmatch.matching-strategy=ant_path_matcher) reads paths in one more way that none of the existing forms covers. It collapses repeated slashes but leaves dot segments in place, so/%2F/admin/../secretreaches an/admin/**handler as/admin/../secret.The change
/api%3B%2F/admin/secrethas no path parameter,/api;%2F/admin/secretdoes), so the decoded path alone can't be the key any more.Behavior changes for applications
Testing
FilterChainManagerPathBypassTest(core): new cases for each form and for the cache key. Each one fails without the change it covers, checked by removing them one at a time.FilterAuthorizationBypassTest: the test app gets a filter on/api/admin/*and an/api/admin/**handler, with new cases on API Gateway, ALB and HTTP API events.FilterAuthorizationBypassAntPathMatcherTestruns the whole suite again with AntPathMatcher, switched on through a test profile.JerseyFilterChainTest: the new spellings added to the protected path list.FilterSelectionFuzzTest, off by default (-DfuzzFilterSelection=true, plus-DfuzzFilterSelectionProfiles=antpathmatcherfor AntPathMatcher). It sends about 65,000 generated spellings of the protected routes through the Lambda entry point and fails if any reaches a protected handler without the filter running. On the current branch it finds 1,124 per event type, and none with this change under either matcher.Related
Backport of #1734 to the 1.x line. The source diff is identical to main apart from
javaximports on 1.x, and the tests are the same apart from the module name.By submitting this pull request