Skip to content

ARSN-682: Resolve the client IP from the trusted end of X-Forwarded-For - #2763

Draft
fredmnl wants to merge 3 commits into
development/8.4from
bugfix/ARSN-682/resolve-client-ip-from-trusted-end-of-xff
Draft

fredmnl wants to merge 3 commits into
development/8.4from
bugfix/ARSN-682/resolve-client-ip-from-trusted-end-of-xff

Conversation

@fredmnl

@fredmnl fredmnl commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

The X-Forwarded-For header is a list of IPs where each proxy will append their client to the right of the list thereby constructing a chain of IP. The rightmost entries are written by the trusted proxies where as leftmost entries can be legit or forged by the client. Currently, arsenal uses the leftmost entry and is susceptible to being fooled by a bad actor forging that one IP address. Instead, we choose to walk right-to-left by successively removing all IPs that belong to trusted proxies that are known to be in the chain and belong to us. We use trustedProxyCIDRs for this.

Edge cases: if every entry is trusted, we keep the leftmost one; if an entry is not a valid IP we keep the last trusted hop to its right (the direct peer if none).

Examples

The client is 1.2.3.4, the attacker connects from 1.2.3.4 and poses as 9.9.9.9, the LB is 10.0.0.1 and the s3-frontend is 127.0.0.1, so cloudserver's peer is always 127.0.0.1. trustedProxyCIDRs contains 127.0.0.1 and, except in case 5, 10.0.0.1.

Case X-Forwarded-For received by cloudserver Before After
1. Client → s3-frontend 1.2.3.4 1.2.3.4 1.2.3.4
2. Client → LB → s3-frontend 1.2.3.4, 10.0.0.1 1.2.3.4 1.2.3.4
3. Attacker → s3-frontend 9.9.9.9, 1.2.3.4 9.9.9.9 1.2.3.4
4. Attacker → LB → s3-frontend 9.9.9.9, 1.2.3.4, 10.0.0.1 9.9.9.9 1.2.3.4
5. Client → LB not in trustedProxyCIDRs → s3-frontend 1.2.3.4, 10.0.0.1 1.2.3.4 10.0.0.1

Behaviour change

Assuming every proxy in front of cloudserver and Vault appends to X-Forwarded-For, each of them must now be listed in trustedProxyCIDRs. An unlisted proxy is taken for the client: every request it forwards gets the proxy's address. Before, the left-most entry gave the right address for an honest client but could be forged; now it can't be forged, but we need to know every proxy. How we document and roll this out is for product to decide.

Open for discussion

  • Proxies that write ip:port. An entry with a port is not a valid IP, so a trusted proxy writing ip:port makes us fall back to that proxy's address (often the local frontend, 127.0.0.1) for every request. We could strip ports in Arsenal; left out for now to keep the change simple.
  • Resolving the client address in the S3C frontend nginx instead. The nginx realip module (real_ip_header X-Forwarded-For, real_ip_recursive on) does the same walk and accepts ip:port. The frontend already uses realip for its PROXY protocol listeners, and only one real_ip_header applies per server block, so this would mean splitting the server block in two and makes the nginx configuration convoluted.

The left-most X-Forwarded-For entry is written by the client, so a client
behind a trusted proxy could choose the address used for aws:SourceIp.
Walk the entries from the right, skip the trusted proxies, and use the
first untrusted one.
Cover a single entry, several trusted proxies, empty entries, a repeated
header, an IPv6 client and an IPv4-mapped trusted proxy.
@bert-e

bert-e commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Hello fredmnl,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval ⭐
/bypass_build_status Bypass the build and test status ⭐
/bypass_commit_size Bypass the check on the size of the changeset TBA ⭐
/bypass_incompatible_branch Bypass the check on the source branch prefix ⭐
/bypass_jira_check Bypass the Jira issue check ⭐
/bypass_peer_approval Bypass the pull request peers' approval ⭐
/bypass_leader_approval Bypass the pull request leaders' approval ⭐
/bypass_source_branch_lineage Bypass the cross-branch contamination check ⭐
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request.
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e

bert-e commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Incorrect fix version

The Fix Version/s in issue ARSN-682 contains:

  • 8.4.29

  • 8.5.22

  • 8.6.6

  • 8.7.2

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 8.4.29

  • 8.5.22

  • 8.6.7

  • 8.7.4

Please check the Fix Version/s of ARSN-682, or the target
branch of this pull request.

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.75%. Comparing base (d5e2bf8) to head (42f0ad9).

Additional details and impacted files
@@                 Coverage Diff                 @@
##           development/8.4    #2763      +/-   ##
===================================================
+ Coverage            74.72%   74.75%   +0.02%     
===================================================
  Files                  229      229              
  Lines                18583    18595      +12     
  Branches              3822     3824       +2     
===================================================
+ Hits                 13886    13900      +14     
+ Misses                4692     4690       -2     
  Partials                 5        5              

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

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.

2 participants