Skip to content

fix: GetClientIP discards real IP on multi-hop X-Forwarded-For and leaves a port on the RemoteAddr fallback - #7101

Merged
bhupesh-devtron merged 1 commit into
mainfrom
fix/get-client-ip-xff-parsing
Dec 2, 2026
Merged

bhupesh-devtron merged 1 commit into
mainfrom
fix/get-client-ip-xff-parsing

Conversation

@bhupesh-devtron

@bhupesh-devtron bhupesh-devtron commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

GetClientIP previously returned the X-Forwarded-For header verbatim (unusable once more than one hop is present) and fell back to RemoteAddr including its port when no proxy header was set. It now takes the rightmost X-Forwarded-For entry (the nearest trusted proxy's own observed peer, not the client-claimed leftmost one - which a client-appending proxy like AWS ALB would let the client fake), falls back to X-Real-IP, then RemoteAddr, stripping the port from whichever entry is used via a shared stripPort helper (handles bracketed IPv6 too).

Description

Fixes https://github.com/devtron-labs/sprint-tasks/issues/3005

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit/api test cases.

Does this PR introduce a user-facing change?


@bito-code-review

Copy link
Copy Markdown

Bito Automatic Review Skipped - Draft PR

Bito didn't auto-review because this pull request is in draft status.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change draft PR review settings here, or contact your Bito workspace admin at shivam@devtron.ai.

@bhupesh-devtron
bhupesh-devtron marked this pull request as ready for review November 27, 2026 08:00
@github-actions

Copy link
Copy Markdown

Some linked issues are invalid. Please update the issue links:\nIssue # in is not found or invalid (HTTP }404).\n

@github-actions

Copy link
Copy Markdown

Some linked issues are invalid. Please update the issue links:\nIssue # in is not found or invalid (HTTP }404).\n

prakash100198
prakash100198 previously approved these changes Nov 27, 2026
@bhupesh-devtron
bhupesh-devtron changed the base branch from develop to main November 30, 2026 12:27
@bhupesh-devtron
bhupesh-devtron dismissed prakash100198’s stale review November 30, 2026 12:27

The base branch was changed.

@bhupesh-devtron
bhupesh-devtron changed the base branch from main to develop November 30, 2026 12:27
…aves a port on the RemoteAddr fallback

GetClientIP previously returned the X-Forwarded-For header verbatim
(unusable once more than one hop is present) and fell back to
RemoteAddr including its port when no proxy header was set. It now
takes the rightmost X-Forwarded-For entry (the nearest trusted proxy's
own observed peer, not the client-claimed leftmost one - which a
client-appending proxy like AWS ALB would let the client fake), falls
back to X-Real-IP, then RemoteAddr, stripping the port from whichever
entry is used via a shared stripPort helper (handles bracketed IPv6
too).

Ported from the equivalent devtron-enterprise fix (PR #3450).
@bhupesh-devtron
bhupesh-devtron force-pushed the fix/get-client-ip-xff-parsing branch from af85dfd to d5ef3ba Compare November 30, 2026 12:34
@bhupesh-devtron
bhupesh-devtron changed the base branch from develop to main November 30, 2026 12:34
@sonarqubecloud

Copy link
Copy Markdown

@bhupesh-devtron
bhupesh-devtron merged commit 9b07abc into main Dec 2, 2026
6 checks passed
@bhupesh-devtron
bhupesh-devtron deleted the fix/get-client-ip-xff-parsing branch December 2, 2026 09:42
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.

3 participants