Skip to content

router: stop duplicating X-Forwarded-For - #484

Merged
volcano-sh-bot merged 2 commits into
volcano-sh:mainfrom
altf4-games:fix/router-xff-duplicate
Oct 23, 2026
Merged

volcano-sh-bot merged 2 commits into
volcano-sh:mainfrom
altf4-games:fix/router-xff-duplicate

Conversation

@altf4-games

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

The router sent a duplicated X-Forwarded-For header to the sandbox. configureProxyDirector set the header itself, and then httputil.ReverseProxy appended the peer address again, so each hop showed up twice (for example "127.0.0.1, 127.0.0.1").
The Director no longer sets the header, and the unused forwardedClientIP helper is removed. Any X-Forwarded-For the client sent is still forwarded, and the real peer is appended once.

Which issue(s) this PR fixes:
Fixes #480

Special notes for your reviewer:

c.ClientIP() is no longer used for this header.
I added TestForwardToSandbox_XForwardedFor with four cases: no prior header, one entry, several entries, and repeated header lines. It fails without the change. I also built the router from main and from this branch and ran both against a stub workload manager and an echo backend. go test -race ./pkg/router/... and the repo lint under Go 1.26.8 pass.

Not tested: a real cluster or an ingress in front of the router.
AI use: I used Claude to help find the bug and draft the fix and the test. I reviewed and ran all of it and can explain each line.

Does this PR introduce a user-facing change?:

Fix duplicated entries in the X-Forwarded-For header the router sends to sandboxes.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 13:25

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

Welcome @altf4-games! It looks like this is your first PR to volcano-sh/agentcube 🎉

@codecov-commenter

codecov-commenter commented Oct 20, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.45%. Comparing base (5903457) to head (f521ae9).
⚠️ Report is 22 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #484      +/-   ##
==========================================
+ Coverage   59.98%   60.45%   +0.46%     
==========================================
  Files          36       35       -1     
  Lines        3589     3616      +27     
==========================================
+ Hits         2153     2186      +33     
+ Misses       1216     1211       -5     
+ Partials      220      219       -1     
Flag Coverage Δ
unittests 60.45% <100.00%> (+0.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@zhzhuang-zju

Copy link
Copy Markdown
Contributor

Hi @altf4-games, thanks for your PR. It has been labeled do-not-merge/invalid-commit-message. Please remove the phrase Fixes #480 from your commit message.

commit 0baf96b818e670237e461de694a1dce3661b3147 (HEAD -> pr484)
Author: Pradyum Mistry <39883432+altf4-games@users.noreply.github.com>
Date:   Tue Oct 20 18:33:42 2026 +0530

    router: stop duplicating X-Forwarded-For
    
    Fixes #480
    
    Signed-off-by: Pradyum Mistry <39883432+altf4-games@users.noreply.github.com>

Signed-off-by: Pradyum Mistry <39883432+altf4-games@users.noreply.github.com>
@altf4-games

Copy link
Copy Markdown
Contributor Author

@zhzhuang-zju thanks for pointing that out. I’ve removed it from the commit message.

@zhzhuang-zju

Copy link
Copy Markdown
Contributor

I reviewed your fix, and it makes sense to me.

The custom proxy director first began appending c.ClientIP() to X-Forwarded-For in response to this review comment: #51 (comment). The intention was to preserve the source address.

However, in Director mode, httputil.ReverseProxy already appends the request's RemoteAddr to X-Forwarded-For. So, manually adding c.ClientIP() would result in duplicate entries.

Ask @acsoto to take another look

Comment thread pkg/router/handlers.go
if c.Request.TLS != nil {
req.Header.Set("X-Forwarded-Proto", "https")
}
req.Header.Set("X-Forwarded-For", forwardedClientIP(req, c.ClientIP()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is dropping the X-Real-IP fallback intentional? When an upstream proxy sends only that header, the sandbox's X-Forwarded-For now contains only the proxy address.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@acsoto not intentional, fixed in f521ae9 with tests.

Signed-off-by: Pradyum Mistry <39883432+altf4-games@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:42

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@acsoto

acsoto commented Oct 23, 2026

Copy link
Copy Markdown
Member

/lgtm
/approve

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acsoto

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot
volcano-sh-bot merged commit 86aa227 into volcano-sh:main Oct 23, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

router: duplicate entries in X-Forwarded-For sent to sandbox

6 participants