Repository navigation
fix: derive client IPs from trusted proxy hops only - #1399
devflora-princess wants to merge 3 commits into
Conversation
|
@devflora-princess Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Thanks for the contribution! We reviewed this PR while merging the open queue and couldn't merge it yet. Here's what needs fixing:
This branch also has merge conflicts with |
|
@greatest0fallt1me — thanks for the review. Addressed both points (and the conflicts):
The branch is based on current |
|
@greatest0fallt1me Thanks — the review points are addressed, and I fixed one regression the branch had introduced:
Verified locally on the updated head with Node 20:
Please re-review. |
c63e2b0 to
163eacf
Compare
Overview
This PR replaces the boolean
TRUST_PROXY_HEADERSbehavior ingetClientIpwith a trusted hop count, so the client IP is selected from the right side ofX-Forwarded-For(matching Expresstrust proxysemantics) instead of the client-controlled leftmost entry. This closes the spoofing vector that let callers bypass the admin IP allowlist and per-IP rate limits.Related Issue
Changes
🔒 Trusted-hop client IP resolution
[MODIFY]
src/lib/clientIp.tsgetClientIpnow accepts a trusted hop count and selects the entry that many positions from the right ofX-Forwarded-For, falling back to the socket address when trust is disabled or the header is missing/short.[MODIFY]
src/config/env.ts[MODIFY]
src/lib/__tests__/clientIp.test.ts[MODIFY]
src/__tests__/ipAllowlist.test.tsVerification Results
X-Forwarded-For: 1.1.1.1, 2.2.2.2yields2.2.2.2clientIp.test.tsipAllowlist.test.tsclientIp.test.tssrc/lib/__tests__/clientIp.test.tsis updatedCloses #1268