Repository navigation
fix(traefik): make prefix path rules segment-aware - #4042
Open
Tyagiquamar wants to merge 1 commit into
Open
Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
Traefik's PathPrefix is a plain string prefix, so a Prefix redirect on `/office/zz` also matched `/office/zzabc`. Badger decides whether a request belongs to a redirect with matchesPath, which is segment-aware, so it passed the request through; the router had already sent it to the noop service, which answered 418. Emit Path() plus PathPrefix(`<path>/`) for prefix matches so the router and the auth gate agree.
Tyagiquamar
requested review from
miloschwartz and
oschwartz10612
as code owners
November 2, 2026 10:48
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.
Summary
A redirect with the Prefix match type made sibling paths return 418 for logged-in users. With a Prefix redirect on
/office/zz, a request to/office/zzabcanswered418 I'm a teapotinstead of being proxied, while the same path was correctly treated as "not matched" for anonymous users.Fixes #4039.
Root cause
The router rule and the auth gate disagreed about what "prefix" means.
appendPathMatchemittedPathPrefix(/office/zz). Traefik'sPathPrefixis a plain string prefix, so the redirect router matched/office/zzabc.findRedirectasksmatchesPath, which is segment-aware:/office/zzabcis not under/office/zz, so it found no redirect and let the request continue.noop@internal, and its comment says a request reaching it is a bug in the middleware chain.noopanswers 418, which is what the user saw.Anonymous requests got 401 instead because badger requires auth before this point, so they never reached the noop service.
Fix
For a Prefix path without a trailing slash, emit
Path(<path>) || PathPrefix(<path>/)instead of a barePathPrefix. A trailing slash keeps the plainPathPrefix, which already matches exactly the same requests asmatchesPath. The comment inrule.tsnow states why the two matchers are paired.This applies to resource routers as well as redirect routers. They use the same helper, and a resource with a Prefix path had the same mismatch: its router matched
/productsforsalewhile the auth gate treated it as a different path.Testing
npx tsx server/lib/traefik/rule.test.ts- all matchesPath, priority and rule quoting tests pass, including three new cases: prefix without a trailing slash emits the paired matcher, a prefix without a leading slash is normalised, and a prefix ending in a slash stays a singlePathPrefix.npx tsx server/lib/traefik/pathEncoding.test.ts- 15 passed.middleware.test.tsandloadBalancer.test.tscould not run in this checkout:node_modulesis not installed here and they import@server/*aliases, sotsxfails to resolve them. They do not touchappendPathMatch. I did not run the Traefik config snapshot suite (traefikConfig.test.tsis listed as known-failing inscripts/run-tests.mjs); CI will run it.No end-to-end Traefik test: that needs a running stack with an SSO session, which this change does not have access to.