Skip to content

fix: redirect port leaking across multiple listeners#9349

Open
Aias00 wants to merge 2 commits into
envoyproxy:mainfrom
Aias00:worktree-fix-redirect-port-leak
Open

fix: redirect port leaking across multiple listeners#9349
Aias00 wants to merge 2 commits into
envoyproxy:mainfrom
Aias00:worktree-fix-redirect-port-leak

Conversation

@Aias00

@Aias00 Aias00 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Problem Description

When a HTTPRoute with a redirect filter (without an explicit port) is attached to multiple Gateway listeners with different ports, the redirect port derived from the first listener is incorrectly reused by subsequent listeners.

Root Cause

In internal/gatewayapi/route.go:1282-1296, the code directly modifies routeRoute.Redirect.Port without first deep copying the routeRoute object. When processing subsequent listeners, the check routeRoute.Redirect.Port == nil fails because the first listener already set it, causing all listeners to reuse the first listener's port.

Fix

Add a DeepCopy() of routeRoute at the beginning of the listener processing loop to ensure each listener works with an independent copy and derives the correct redirect port independently.

Test Case

Added httproute-redirect-port-multi-listener test case:

  • Gateway with two listeners on ports 8080 and 9090
  • HTTPRoute with redirect filter (no explicit port) attached to both listeners
  • Verifies each listener gets the correct redirect port (8080 and 9090 respectively)

Related Issue

Fixes #9348

Copilot AI review requested due to automatic review settings June 25, 2026 04:56
@Aias00 Aias00 requested a review from a team as a code owner June 25, 2026 04:56
@netlify

netlify Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 64604dd
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6a4ce94c1ab179000897959b
😎 Deploy Preview https://deploy-preview-9349--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 206c4249b7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// This is important when a route has multiple parent refs (listeners)
// with different ports, as the redirect port needs to be derived
// independently for each listener.
routeRoute := routeRoute.DeepCopy()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add a release-note fragment for this bug fix

Because this changes user-visible redirect behavior when one HTTPRoute attaches to multiple listeners with different ports, it should be included in the compiled release notes. The repository’s release-notes/current/README.md says bug fixes need a new fragment under release-notes/current/bug_fixes/, but this commit only updates the translator and testdata, so users upgrading would not see this fix documented.

Useful? React with 👍 / 👎.

Copilot AI 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.

Pull request overview

Fixes a translation bug where an HTTPRoute redirect filter with no explicit port could “leak” the derived redirect port from the first processed Gateway listener to subsequent listeners with different ports. The change ensures redirect port derivation is isolated per listener, and adds a regression test case covering the multi-listener scenario.

Changes:

  • Deep-copies per-route IR before deriving a default redirect port so listener-specific derived state doesn’t persist across listeners.
  • Adds new translator golden testdata for an HTTPRoute attached to two listeners (8080 and 9090) with a redirect filter missing port.
  • Validates generated xDS IR contains listener-appropriate redirect ports (8080 and 9090 respectively).

Review Findings

Required fixes

  • Add a release-notes fragment for this user-visible bug fix (commented at internal/gatewayapi/route.go:1281-1283).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/gatewayapi/route.go Deep-copies IR route objects before deriving redirect port so derived state doesn’t leak across listeners.
internal/gatewayapi/testdata/httproute-redirect-port-multi-listener.in.yaml New regression input: one Gateway with two listeners and an HTTPRoute redirect filter without an explicit port.
internal/gatewayapi/testdata/httproute-redirect-port-multi-listener.out.yaml Expected output verifying each listener gets the correct derived redirect port in xDS IR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1281 to +1283
// Deep copy the route first to avoid modifying the original and
// affecting other listeners that may be attached to the same route.
// This is important when a route has multiple parent refs (listeners)
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.36%. Comparing base (30d456e) to head (64604dd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9349      +/-   ##
==========================================
+ Coverage   75.35%   75.36%   +0.01%     
==========================================
  Files         252      252              
  Lines       41475    41476       +1     
==========================================
+ Hits        31254    31259       +5     
+ Misses       8108     8106       -2     
+ Partials     2113     2111       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Aias00

Aias00 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

/retest

When a HTTPRoute with redirect filter is attached to multiple listeners with different ports, the redirect port derived from one listener could be reused by subsequent listeners because route translation mutated the shared route object.

Deep copy the route while processing each listener so redirect ports are derived independently per listener. Add golden coverage for multi-listener redirects, including scheme-derived well-known ports.

Signed-off-by: liuhy <liuhongyu@apache.org>
@Aias00 Aias00 force-pushed the worktree-fix-redirect-port-leak branch 2 times, most recently from a4b7671 to 0637a3e Compare July 7, 2026 10:56
Document the fix for redirect port leaking across multiple listeners.

Signed-off-by: liuhy <liuhongyu@apache.org>
@Aias00 Aias00 force-pushed the worktree-fix-redirect-port-leak branch from 0637a3e to 64604dd Compare July 7, 2026 11:55
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.

Bug: Redirect port leaks across multiple listeners when HTTPRoute has no explicit redirect port

2 participants