fix(ip): resolve client IP from a trusted proxy hop, not X-Forwarded-For[0]#7
Open
dddabtc wants to merge 1 commit into
Open
fix(ip): resolve client IP from a trusted proxy hop, not X-Forwarded-For[0]#7dddabtc wants to merge 1 commit into
dddabtc wants to merge 1 commit into
Conversation
…For[0]
Both /api/anon and /api/auth/callback derived the client IP as
xff.split(',')[0] — the left-most X-Forwarded-For entry, which is the most
client-controllable. A caller could prepend any value to rotate their apparent
IP and bypass per-IP limits: the anonymous free-prompt cap (drain the daily
free-subsidy budget) and the per-IP account-creation cap (defeat the anti-bot
limit).
Add a shared clientIp() that reads the entry inserted by the outermost trusted
proxy (XFF_TRUSTED_PROXY_COUNT from the right, default 1) instead of the
attacker-controllable left-most one, and use it in both routes.
leyten
added a commit
that referenced
this pull request
Jul 21, 2026
…itors (P1-#4 #7) (#47) GradedReputation passed as trust (rejects proven cheaters at announce); auditors from SWARM_AUDITOR_PUBKEYS; swarmSpotCheckSweep probabilistically checks ready rings; reputation persisted to data/ so a cheater cant rejoin by waiting for a deploy. reputation-gate-test 9/9; all suites green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
/api/anonand/api/auth/callbackboth compute the client IP as:X-Forwarded-Foris a client-settable header and the left-most entry is the one a caller can forge. The IP is used for per-IP caps:hashIpis bound into the anon token; rotating the header mints fresh free quota and can drain the daily free-subsidy budget),recordNewAccountForIp), an anti-bot control.So an attacker rotates
X-Forwarded-Forto bypass both.Fix
Add a shared
lib/client-ip.tsthat returns the entry inserted by the outermost trusted proxy — theXFF_TRUSTED_PROXY_COUNT-th from the right (default1, i.e. a single CDN/load balancer) — rather than the attacker-controllable left-most value. Both routes use it.Operators set
XFF_TRUSTED_PROXY_COUNTto their real proxy hop count. (If the app is exposed with no proxy at all,X-Forwarded-Forcan't be trusted regardless — a proxy must set it.)