fix: resolve x-forwarded-* hop-aware, right-to-left - #229
Conversation
`X-Forwarded-*` were resolved leftmost-first, so under a recommended `trustProxy: "loopback"` an attacker sending `X-Forwarded-For: 9.9.9.9` got `request.ip === "9.9.9.9"`, defeating IP rate-limits, allowlists, geo checks and audit logs. The same class of issue let forwarded proto and host be poisoned (cache keys, password-reset links). Resolve the forwarded chain hop-aware, walking right-to-left from the immediate peer and skipping addresses in the trusted set; the first untrusted address is the client (Express / nginx / ALB semantics). If every hop is trusted, the leftmost entry is the client; if the peer is untrusted the headers are ignored entirely. The same hop model gates forwarded proto/host: only the trusted proxy's entry is honored. Applied at all three call sites (universal plugin, Node adapter, AWS adapter — starting from the gateway-verified `sourceIp`). Replaces `firstForwardedValue` with `forwardedList` / `resolveClientIP` / `trustedHops` / `forwardedHopValue`. Rewrites the tests that enshrined the old leftmost behavior and documents the hop model. (F7 / D1) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
X-Forwarded-* hop-aware, right-to-left
X-Forwarded-* hop-aware, right-to-leftx-forwarded-* hop-aware, right-to-left
The
X-Forwarded-*headers were resolved leftmost-first, so under the recommendedtrustProxy: "loopback"an attacker sendingX-Forwarded-For: 9.9.9.9gotrequest.ip === "9.9.9.9". Because real proxies append to the header, the leftmost value is fully client-controlled — this defeats IP rate-limits, allowlists, geo checks and audit logs (F7). The same class of issue let forwarded proto and host be poisoned (cache keys, password-reset links).New hop-aware model (D1)
Resolve the forwarded chain hop-aware, right-to-left from the immediate peer, skipping addresses in the trusted set — the first untrusted address is the client. This matches Express (
trust proxy), nginx ($proxy_add_x_forwarded_for) and AWS ALB.request.url.Changes
firstForwardedValuewithforwardedList/resolveClientIP/trustedHops/forwardedHopValueinsrc/_trust-proxy.ts._node/request.ts+_node/url.ts), and AWS adapter (_aws/utils.ts, starting from the gateway-verifiedsourceIpas the nearest hop).trustProxydocs to state the hop model explicitly (Docs-T1).Verification
pnpm vitest run --exclude '**/{deno,bun}*.test.ts' test/— 860 passed, 32 skippedpnpm lintandpnpm typecheckclean🤖 Generated with Claude Code