Skip to content

fix(server): merge X-Forwarded-For lines and stop at unparseable hops - #415

Merged
scttbnsn merged 2 commits into
dev/v1.0from
fix/pre-ga-hardening
Oct 29, 2026
Merged

scttbnsn merged 2 commits into
dev/v1.0from
fix/pre-ga-hardening

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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, clientIP used Header.Get, which only returns the first X-Forwarded-For line, and it skipped any hop it couldn't parse. HAProxy with option forwardfor appends its own line, and some proxies write hops as ip: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:port and [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.md and docker-compose.edge-with-exec.yml now warn that exec can reach the sockguard container itself. Sockguard is fixing the scoping on its side. sockguard-with-exec.yaml is a synced copy, so it's untouched.

TestClientIPForwardedHeaderParsing adds 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

  • 🔧 Changed: clientIP now merges X-Forwarded-For lines in order and walks the chain from right to left when the direct peer is trusted.
  • 🔧 Changed: Forwarded hops accept bare IPs and IP:port forms, including bracketed IPv6. Returned addresses are canonicalized.
  • 🐛 Fixed: An unparseable hop stops traversal and returns the direct peer. X-Real-IP is used only when the XFF chain is absent or contains only trusted proxies.
  • ✨ Added: Forwarded-header parsing tests cover multiple lines, ports, canonicalization, malformed hops, and X-Real-IP fallback.
  • 🔒 Security: Authentication and security-model docs explain that signatures do not identify the intended agent, so another agent trusting the same key can accept a captured request within the skew window.
  • 🔒 Security: The edge-with-exec example warns that exec can target the sockguard proxy and bypass its allowlist.

Concerns

  • The test table has nine cases, not the 12 reported in the PR objectives. Confirm the intended case count or update the report.
  • The reported race test, release contract, and pre-push results were not independently verified.

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.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 32cfb91 and 504572a.

Files selected for processing: 2
  • internal/server/coverage2_test.go
  • internal/server/middleware.go

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between ef2857b and 32cfb91.

Files ignored due to path filters: 1
  • CHANGELOG.md is excluded by !CHANGELOG.md
Files selected for processing: 6
  • docs/content/docs/current/authentication.mdx
  • docs/content/docs/current/security-model.mdx
  • examples/README.md
  • examples/docker-compose.edge-with-exec.yml
  • internal/server/coverage2_test.go
  • internal/server/middleware.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The server now merges all X-Forwarded-For field lines, parses and normalizes forwarded hops, and applies trusted-proxy traversal with defined fallback behavior. Tests cover multiple header lines, address formats, malformed hops, and X-Real-IP fallback. Documentation now describes cross-agent replay considerations for Ed25519 authentication and the container scope of the edge-with-exec rule.

Suggested labels: second-opinion

Priority: Normal

Change: Bug fix

Merge Risk: Minimal · previous review 32cfb

No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 2
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the second-opinion Summon Greptile for a second-opinion review label Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@greptileai Review exact head 32cfb91cc8ea204cce90bc229d9d6955e8c465d8. Review for correctness, security issues, and cross-file regressions.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable regression was found.

Summary

The PR hardens clientIP behind trusted proxies and documents two existing security limits.

  • Trusted proxy chains now produce one canonical client address.
  • Authentication docs explain how signed requests can replay between agents.
  • The edge-with-exec example warns that exec can reach the sockguard proxy.

Reviews (1) · Last reviewed commit: "fix(server): merge X-Forwarded-For lines..." · Reviewed by Greptile

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

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 biggest-littlest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the X-Forwarded-For fix and docs on 504572a. CI is green and the Codex finding is addressed.

@ALARGECOMPANY ALARGECOMPANY left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the X-Forwarded-For fix and docs on 504572a. CI is green and the Codex finding is addressed.

@scttbnsn
scttbnsn merged commit 40bf061 into dev/v1.0 Oct 29, 2026
63 of 66 checks passed
@scttbnsn
scttbnsn deleted the fix/pre-ga-hardening branch October 29, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

second-opinion Summon Greptile for a second-opinion review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants