feat(security): expand inbound passthrough denylist to block protocol-level headers#4726
Open
bogdanmariusc10 wants to merge 2 commits into
Conversation
Closes #4450 - Add _INBOUND_PASSTHROUGH_DENYLIST with 10 protocol-level headers - Block content-type, content-length, host, transfer-encoding, and hop-by-hop headers - Enforce denylist in get_passthrough_headers() and compute_passthrough_headers_cached() - Add 13 comprehensive security tests for each denied header - Update existing tests to use X-Custom-Type instead of Content-Type - Log WARNING when blocking protocol-level headers Security rationale: - host: prevents vhost selection / cache-poisoning attacks - transfer-encoding: prevents request-smuggling attacks - content-type: prevents encoding-dispatch bypass (PR #4139) - content-length: httpx-managed; defence-in-depth - connection, keep-alive, proxy-connection, te, trailer, upgrade: hop-by-hop headers Note: authorization intentionally NOT in denylist (has gateway-auth-aware handling) Signed-off-by: Bogdan-Marius-Catanus <[email protected]>
Signed-off-by: Bogdan-Marius-Catanus <[email protected]>
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.
🔗 Related Issue
Closes #4450
📝 Summary
Expands the inbound passthrough header denylist from a single entry (
content-type) to 10 protocol-level headers that pose security risks when client-controlled. This prevents vhost selection attacks, cache poisoning, request smuggling, and encoding-dispatch bypasses.What changed:
_INBOUND_PASSTHROUGH_DENYLISTconstant with 10 security-critical headersget_passthrough_headers()andcompute_passthrough_headers_cached()X-Custom-Typeinstead ofContent-Type)Headers now blocked from inbound passthrough:
content-type— encoding-dispatch protection (PR fix(api): support multipart/form-data and form-urlencoded for REST tool invocations #4139)host— vhost selection / cache-poisoning protectiontransfer-encoding— request-smuggling protectioncontent-length— httpx-managed; defence-in-depthconnection,keep-alive,proxy-connection,te,trailer,upgrade— hop-by-hop headersNote:
authorizationis intentionally NOT in the denylist as it has existing gateway-auth-aware handling viaX-Upstream-Authorizationrename logic.🏷️ Type of Change
🧪 Verification
make lintmake testmake coverageTest coverage:
TestInboundPassthroughDenylistclassdefault_passthrough_headersand per-gatewaypassthrough_headersauthorizationis NOT blocked (existing special handling preserved)✅ Checklist
make black isort pre-commit)📓 Notes
Security rationale per header:
hosttransfer-encodingcontent-typecontent-lengthconnection,keep-alive,proxy-connection,te,trailer,upgradeDesign decisions:
_LOOPBACK_SKIP_HEADERSconstant (same file, line 552)mcp-session-id,x-forwarded-internally) as they only matter in loopback contextsauthorizationto preserve existing gateway-auth-aware handlingFiles modified:
mcpgateway/utils/passthrough_headers.py— added denylist constant and enforcement logictests/unit/mcpgateway/utils/test_passthrough_headers_security.py— added 13 new security teststests/unit/mcpgateway/utils/test_passthrough_headers.py— fixed 8 tests expectingContent-Typepassthroughtests/unit/mcpgateway/utils/test_passthrough_headers_fixed.py— fixed 4 tests expectingContent-Typepassthrough.secrets.baseline— updated baseline for new test content