Skip to content

[#2969] - Filters use the path pattern matched by the chain resolver - #2971

Open
lprimak wants to merge 1 commit into
apache:mainfrom
lprimak:path-matcher-fails-closed
Open

lprimak wants to merge 1 commit into
apache:mainfrom
lprimak:path-matcher-fails-closed

Conversation

@lprimak

@lprimak lprimak commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2969. Supersedes #2970.

A custom PatternMatcher set on PathMatchingFilterChainResolver was only used by the resolver. The filters in the chain matched the path again with their own AntPathMatcher, so non-Ant patterns (for example regular expressions) did not work.

The resolver now stores the pattern it matched as a request attribute, and PathMatchingFilter uses that pattern's config directly instead of matching again. This works regardless of when filters are added or which matcher they have.

Also:

  • The Guice SimpleFilterChainResolver does the same, and now looks up the chain by its configured pattern after a trailing-slash match.
  • Removed a redundant null/empty check in PathMatchingFilter.preHandle.

Behavior note: a filter that overrides pathsMatch is no longer consulted for requests whose chain was selected by the resolver.


Following this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a GitHub issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a GitHub issue. Your pull request should address just this issue, without pulling in other changes.

  • Format the pull request title like [#XXX] - Fixes bug in SessionManager,
    where you replace #XXX with the appropriate GitHub issue. Best practice
    is to use the GitHub issue title in the pull request title and in the first line of the commit message.

  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.

  • add fixes #XXX if merging the PR should close a related issue.

  • Run mvn verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.

  • Committers: Make sure a milestone is set on the PR

  • Committers: Use "Squash and Merge" to combine all commits into one when merging a PR when appropriate.

  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004

A custom PatternMatcher set on PathMatchingFilterChainResolver was not
used by the filters in the chain, which matched the path again with
their own AntPathMatcher. Non-Ant patterns did not work as a result.

The resolver now records the matched pattern as a request attribute
and PathMatchingFilter uses that pattern's config directly. Applies to
the Guice SimpleFilterChainResolver as well, which now looks up the
chain by its configured pattern after a trailing-slash match.
@github-actions github-actions Bot added java Pull requests that update Java code tests labels Nov 24, 2026
@lprimak lprimak added this to the 3.1.0 milestone Nov 24, 2026
@lprimak

lprimak commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@4n86rakam1 can you please review?
Thanks

@4n86rakam1

Copy link
Copy Markdown

@lprimak
Thanks, this looks right. On embedded Tomcat 11 with a RegExPatternMatcher, main lets /secure/report through without credentials (200) and this PR returns 401. The same holds for a filter added after setPathMatcher().

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

Labels

java Pull requests that update Java code tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PathMatchingFilterChainResolver.setPathMatcher() does not reach PathMatchingFilters

3 participants