Skip to content

fix(lambda): match filter url-patterns against more path forms 1.x - #1736

Open
ckawl wants to merge 3 commits into
aws:1.xfrom
ckawl:fix/filter-path-parameters-1.x
Open

ckawl wants to merge 3 commits into
aws:1.xfrom
ckawl:fix/filter-path-parameters-1.x

Conversation

@ckawl

@ckawl ckawl commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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/secret decodes 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/../secret reaches an /admin/** handler as /admin/../secret.

The change

  • Two new forms remove path parameters from the raw path and decode afterwards, one left as is and one normalized.
  • A third new form is that path with repeated slashes collapsed and dot segments kept, which is how AntPathMatcher sees it.
  • The existing forms are unchanged, so any filter selected today is still selected.
  • The filter chain cache is keyed on the canonical path plus the raw path, length-prefixed. Two raw paths can decode to the same string but need different filters (/api%3B%2F/admin/secret has no path parameter, /api;%2F/admin/secret does), so the decoded path alone can't be the key any more.

Behavior changes for applications

  • A filter mapped to a path prefix now also runs for some unusual spellings that end up routed elsewhere or nowhere, so a few requests that used to return 404 may now get the filter's response instead. This is the same direction fix(lambda): filter path canonicalization #1628 took.
  • The filter chain cache holds one entry per raw path rather than per decoded path.

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.
  • New FilterAuthorizationBypassAntPathMatcherTest runs the whole suite again with AntPathMatcher, switched on through a test profile.
  • JerseyFilterChainTest: the new spellings added to the protected path list.
  • New FilterSelectionFuzzTest, off by default (-DfuzzFilterSelection=true, plus -DfuzzFilterSelectionProfiles=antpathmatcher for 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 javax imports on 1.x, and the tests are the same apart from the module name.

By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

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 bnusunny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getFilterChain is 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.
@ckawl

ckawl commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

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 bnusunny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants