Skip to content

feat(mcp): opt-in DNS rebinding protection for localhost Host/Origin - #3022

Merged
howardjohn merged 3 commits into
agentgateway:mainfrom
piyushbag:feat/mcp-dns-rebinding-protection
Aug 14, 2026
Merged

howardjohn merged 3 commits into
agentgateway:mainfrom
piyushbag:feat/mcp-dns-rebinding-protection

Conversation

@piyushbag

Copy link
Copy Markdown
Contributor

Summary

  • Opt-in dnsRebindingProtection on MCP backends (default off), as requested in Support MCP DNS rebinding specification #1855.
  • When enabled, Host/Origin must be localhost, 127.0.0.1, or [::1] (optional port); otherwise the gateway returns 403.
  • Off by default so typical proxy deployments are unchanged.

Fixes #1855

Test plan

  • Unit tests for Host/Origin localhost parsing
  • E2E: protection off still allows Origin: http://evil.example
  • E2E: protection on rejects non-localhost Origin (403) and allows localhost Origin (200)
  • E2E: raw HTTP Host: evil.example returns 403
$ cargo test -p agentgateway --lib dns_rebinding -- --nocapture
test mcp::dns_rebinding::tests::rejects_non_localhost_origin_even_with_localhost_host ... ok
test mcp::dns_rebinding::tests::rejects_non_localhost_host ... ok
test mcp::dns_rebinding::tests::accepts_localhost_origin ... ok
test mcp::dns_rebinding::tests::accepts_localhost_hosts ... ok
test mcp::dns_rebinding::tests::reject_non_localhost_builds_403 ... ok
test mcp::tests::dns_rebinding_protection_rejects_non_localhost_host ... ok
test mcp::tests::dns_rebinding_protection_off_allows_non_localhost_origin ... ok
test mcp::tests::dns_rebinding_protection_rejects_non_localhost_origin ... ok
test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 1725 filtered out

Add dnsRebindingProtection on MCP backends (off by default). When enabled,
requests whose Host or Origin is not localhost/127.0.0.1/[::1] are rejected
with 403, matching the MCP localhost DNS-rebinding requirement without
breaking typical proxy deployments.

Signed-off-by: Piyush Jagadish Bag <[email protected]>
@piyushbag
piyushbag requested a review from a team as a code owner August 14, 2026 03:44
Keep dnsRebindingProtection off-by-default out of serialized MCP backends
and document the field in config.md so proxy-lint and snapshot tests pass.

Signed-off-by: Piyush Jagadish Bag <[email protected]>
Signed-off-by: John Howard <[email protected]>
@howardjohn
howardjohn force-pushed the feat/mcp-dns-rebinding-protection branch from 2ebb93d to 0083d57 Compare August 14, 2026 19:34
@howardjohn
howardjohn merged commit d3c0689 into agentgateway:main Aug 14, 2026
11 checks passed
gaogaoSpark pushed a commit to gaogaoSpark/agentgateway that referenced this pull request Aug 28, 2026
…gentgateway#3022)

## Summary
- Opt-in `dnsRebindingProtection` on MCP backends (default off), as
requested in agentgateway#1855.
- When enabled, Host/Origin must be `localhost`, `127.0.0.1`, or `[::1]`
(optional port); otherwise the gateway returns 403.
- Off by default so typical proxy deployments are unchanged.

Fixes agentgateway#1855

## Test plan
- [x] Unit tests for Host/Origin localhost parsing
- [x] E2E: protection off still allows `Origin: http://evil.example`
- [x] E2E: protection on rejects non-localhost Origin (403) and allows
localhost Origin (200)
- [x] E2E: raw HTTP `Host: evil.example` returns 403

```text
$ cargo test -p agentgateway --lib dns_rebinding -- --nocapture
test mcp::dns_rebinding::tests::rejects_non_localhost_origin_even_with_localhost_host ... ok
test mcp::dns_rebinding::tests::rejects_non_localhost_host ... ok
test mcp::dns_rebinding::tests::accepts_localhost_origin ... ok
test mcp::dns_rebinding::tests::accepts_localhost_hosts ... ok
test mcp::dns_rebinding::tests::reject_non_localhost_builds_403 ... ok
test mcp::tests::dns_rebinding_protection_rejects_non_localhost_host ... ok
test mcp::tests::dns_rebinding_protection_off_allows_non_localhost_origin ... ok
test mcp::tests::dns_rebinding_protection_rejects_non_localhost_origin ... ok
test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 1725 filtered out
```

---------

Signed-off-by: Piyush Jagadish Bag <[email protected]>
Signed-off-by: John Howard <[email protected]>
Co-authored-by: John Howard <[email protected]>
Signed-off-by: rayze <[email protected]>
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.

Support MCP DNS rebinding specification

2 participants