clientIP() trusts the leftmost X-Forwarded-For entry #74

Open
opened 2026-10-14 08:53:41 +00:00 by sharang · 0 comments
Owner

Found by mobile-support while working on #73.

Problem

  • clientIP() (internal/server/helpers.go) returns the leftmost X-Forwarded-For entry.
  • orca-proxy (crates/orca-proxy/src/forward.rs) appends the peer it saw and documents the rightmost entry as the authoritative one.
  • So today the caller chooses every source_ip the registry records in its audit, licence and usage rows, by sending its own X-Forwarded-For.
  • A side effect: the column is INET, so a non-IP leftmost value likely makes the insert fail.

Fix

  • Take the rightmost entry, i.e. the one orca-proxy appended.
  • More generally, the entry that sits a configured number of trusted hops from the right.
  • Accept it only when net.ParseIP succeeds; otherwise fall back to RemoteAddr.
  • Add tests for a spoofed leftmost entry and a junk entry.

Related: #73 (source_ip relayed by products), orca-platform #88.

🤖 Generated with Claude Code

Found by mobile-support while working on #73. ## Problem - `clientIP()` (internal/server/helpers.go) returns the **leftmost** `X-Forwarded-For` entry. - orca-proxy (`crates/orca-proxy/src/forward.rs`) *appends* the peer it saw and documents the **rightmost** entry as the authoritative one. - So today the caller chooses every `source_ip` the registry records in its audit, licence and usage rows, by sending its own `X-Forwarded-For`. - A side effect: the column is `INET`, so a non-IP leftmost value likely makes the insert fail. ## Fix - Take the rightmost entry, i.e. the one orca-proxy appended. - More generally, the entry that sits a configured number of trusted hops from the right. - Accept it only when `net.ParseIP` succeeds; otherwise fall back to `RemoteAddr`. - Add tests for a spoofed leftmost entry and a junk entry. Related: #73 (`source_ip` relayed by products), orca-platform #88. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: platform/tenant-registry#74