Skip to content

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

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

ckawl wants to merge 2 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.
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.

1 participant