Repository navigation
Trust forwarded client addresses from configured proxy networks - #33
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On the Hugging Face Docker Space
huggingface/paperswithcode-mcpthe direct peer is HF's ingress proxy, not loopback._client_address()ignoresX-Forwarded-Forfrom non-loopback peers, so every external client shares one rate-limit identity: 60 requests and 10 semantic searches per minute, with concurrency 4.What
PWC_MCP_TRUSTED_PROXY_CIDRS(comma-separated CIDRs, empty by default). Invalid entries fail at startup.X-Forwarded-Forhop 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.X-PwC-MCP-Client.space/README.md:short_descriptionis now 52 characters (the limit is 60).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