Skip to content

fix(kubernetes-ingress-nginx): preserve original auth URI - #13754

Open
fredrikblau wants to merge 3 commits into
traefik:masterfrom
fredrikblau:fix/13682-preserve-auth-uri
Open

fredrikblau wants to merge 3 commits into
traefik:masterfrom
fredrikblau:fix/13682-preserve-auth-uri

Conversation

@fredrikblau

Copy link
Copy Markdown

Fixes #13682

What changed

  • Preserve the original request URI in X-Forwarded-Uri before rewrite-target rewrites the request.
  • Keep the preserved URI when constructing the ingress-nginx forward-auth request.
  • Add regression coverage for rewritten paths with query strings and forward-auth headers.

Validation

  • go test ./pkg/middlewares/ingressnginx/rewritetarget ./pkg/middlewares/ingressnginx/snippet
  • go test ./pkg/provider/kubernetes/ingress-nginx

@nmengin

nmengin commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Hey @fredrikblau,

Thanks for this contribution!
We've set this to "review" and will take a look at the code.
We'll update you once the review is done.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The change is small, well-targeted and covered by tests; the fix correctly preserves the pre-rewrite URI for forward-auth. One point worth confirming is the new propagation of X-Forwarded-Uri to upstream backends, and the ingress-nginx docs (docs/content/reference/routing-configuration/kubernetes/ingress-nginx.md) that describe the old behavior may now be stale.

Note

This review was performed by an AI agent. Learn more.


How this review was conducted

I traced the X-Forwarded-Uri flow across the rewrite-target and snippet forward-auth middlewares, confirmed middleware execution order in the ingress-nginx translator, verified the entrypoint forwardedheaders strips the header for untrusted sources, and validated the new test assertions against JoinPath's RawPath behavior.

2 files read beyond the diff

  • pkg/provider/kubernetes/ingress-nginx/translator.go — lines 460–559 of 634
  • pkg/middlewares/forwardedheaders/forwarded_header.go — lines 1–190 of 321

18 turns

// Keep the client URI available to downstream middleware, such as the
// ingress-nginx forward-auth adapter, before rewriting the request path.
if req.Header.Get(xForwardedURI) == "" {
req.Header.Set(xForwardedURI, req.URL.RequestURI())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 QUESTION:

Setting X-Forwarded-Uri on req.Header means the original URI is now forwarded to the upstream backend for every rewrite-target request, not only to the forward-auth subrequest. Previously the snippet adapter set it only on the auth forwardReq. Is exposing the pre-rewrite URI to backends intended? (It is consistent with how X-Forwarded-Prefix is handled just above, so this may be deliberate.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. The original URI is needed only by the forward-auth subrequest; exposing it to the upstream backend was not intentional.

I updated the PR to keep the URI in request context and apply X-Forwarded-Uri only while constructing the auth request. The upstream now receives the rewritten request without the new header. I also updated the ingress-nginx documentation and added regression coverage for both behaviors.

The branch has been rebased onto the current master. Focused middleware and provider tests pass.

@fredrikblau
fredrikblau force-pushed the fix/13682-preserve-auth-uri branch from 57aa702 to 22a5c53 Compare August 24, 2026 18:17
@fredrikblau

Copy link
Copy Markdown
Author

Updated the branch with current master; the ingress-nginx docs already describe the preserved auth URI and rewritten upstream path. Targeted rewritetarget and snippet tests pass with go test -p 1 -vet=off.

@fredrikblau

Copy link
Copy Markdown
Author

@traefik-code-review-oss Thanks for the careful review and your patience. The branch is updated with current master, and the auth/upstream URI behavior is covered by the targeted tests.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kubernetesIngressNGINX: preserve original request URI for auth-url when used with rewrite-target

4 participants