Skip to content

Trust forwarded client addresses from configured proxy networks - #33

Merged
NielsRogge merged 1 commit into
mainfrom
claude/mcp-trusted-proxy
Oct 18, 2026
Merged

NielsRogge merged 1 commit into
mainfrom
claude/mcp-trusted-proxy

Conversation

@NielsRogge

Copy link
Copy Markdown
Collaborator

Why

On the Hugging Face Docker Space huggingface/paperswithcode-mcp the direct peer is HF's ingress proxy, not loopback. _client_address() ignores X-Forwarded-For from non-loopback peers, so every external client shares one rate-limit identity: 60 requests and 10 semantic searches per minute, with concurrency 4.

What

  • New opt-in PWC_MCP_TRUSTED_PROXY_CIDRS (comma-separated CIDRs, empty by default). Invalid entries fail at startup.
  • When the direct peer is inside a configured network, the identity is the right-most X-Forwarded-For hop outside those networks. Repeated XFF headers are joined in order. Hops further left are client-supplied and ignored. A missing, fully trusted, or malformed chain falls back to the proxy peer.
  • Proxied peers never get X-PwC-MCP-Client.
  • Loopback handling is unchanged, so the VPS behaves the same.
  • space/README.md: short_description is now 52 characters (the limit is 60).
  • README and SPEC document the setting.

Not deployed

The Space keeps running the old image. I couldn't confirm which peer range and XFF chain the Space ingress uses, so don't set the variable until it's measured; see the PR conversation.

Tests

uv run --project mcp_server pytest mcp_server/tests: 83 passed. The new tests cover right-most selection, trusted intermediate hops, IPv6, repeated headers, fallbacks, ignoring the identity header, env parsing and validation, and separate per-client buckets through the full app.

🤖 Generated with Claude Code

Behind the Hugging Face Spaces ingress the direct peer is never loopback, so
every external client shared one rate-limit identity. PWC_MCP_TRUSTED_PROXY_CIDRS
(empty by default) lists the proxy's networks; a request from such a peer is
limited by the right-most X-Forwarded-For hop outside them, and can never name
its identity with X-PwC-MCP-Client. Loopback handling is unchanged.

Also shorten the Space short_description to the 60-character limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NielsRogge
NielsRogge merged commit c8a789e into main Oct 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant