Repository navigation
fix(server): merge X-Forwarded-For lines and stop at unparseable hops - #415
Conversation
Behind TRUSTED_PROXIES, clientIP read only the first X-Forwarded-For line and skipped hops it couldn't parse, so a forged line or an ip:port hop could pick the rate-limit key and audit actor. Merge every line, parse ip:port hops, treat an unparseable hop as the boundary, and canonicalize addresses. Also document the signature-audience limit and the edge-with-exec bundle risk.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
No actionable comments were generated in the recent review.
|
|
@greptileai Review exact head |
[Medium impact] The PR appears safe to merge; no actionable regression was found.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
An empty field line joined to an empty string and skipped the chain, so a client-sent X-Real-IP was used instead of the direct peer.
biggest-littlest
left a comment
There was a problem hiding this comment.
Reviewed the X-Forwarded-For fix and docs on 504572a. CI is green and the Codex finding is addressed.
ALARGECOMPANY
left a comment
There was a problem hiding this comment.
Reviewed the X-Forwarded-For fix and docs on 504572a. CI is green and the Codex finding is addressed.
This is pre-GA hardening from the claude-security scan. It has one code fix and two notes in the docs.
X-Forwarded-For (scan F5). Behind
TRUSTED_PROXIES,clientIPusedHeader.Get, which only returns the firstX-Forwarded-Forline, and it skipped any hop it couldn't parse. HAProxy withoption forwardforappends its own line, and some proxies write hops asip:port. Behind either, the hop that came back was one the client wrote. That value keys the auth and enrollment rate limiter and becomes the audit actor, so a caller could dodge the throttle, trip the controller's bucket, or forge the actor.It now merges every line in order, parses
ip:portand[v6]:port, and stops at the first hop that won't parse, falling back to the direct peer. Returned addresses are canonicalized, so IPv4-mapped IPv6 and IPv4 share a bucket. X-Real-IP is still a fallback, but only when the chain yields nothing.Signature audience (F3). The authentication and security-model pages now say that a signature doesn't name the agent it's for, so a captured request can replay on another agent that trusts the same key within the skew window. Use TLS and give each agent its own controller key. The protocol fix is planned for v1.1, together with Drydock.
Exec bundle (F9).
examples/README.mdanddocker-compose.edge-with-exec.ymlnow warn that exec can reach the sockguard container itself. Sockguard is fixing the scoping on its side.sockguard-with-exec.yamlis a synced copy, so it's untouched.TestClientIPForwardedHeaderParsingadds 12 cases. clientIP and the new helper are at 100% coverage.go test -race ./internal/server/..., the release contract and the full pre-push gate pass locally.Changelog
clientIPnow mergesX-Forwarded-Forlines in order and walks the chain from right to left when the direct peer is trusted.IP:portforms, including bracketed IPv6. Returned addresses are canonicalized.X-Real-IPis used only when the XFF chain is absent or contains only trusted proxies.X-Real-IPfallback.Concerns