Repository navigation
feat(server): wildcard and callable Host matching, and a loopback-only policy warning - #2015
Merged
Merged
Conversation
… in the Host policy Proxied and multi-tenant sellers had to list every Host value exactly or turn DNS-rebinding protection off. The SDK's Host check now matches entries itself, case-insensitively, instead of delegating to MCP's literal matcher: - `*.agents.example.com` matches exactly one extra label (the TLS wildcard rule) and `**.agents.example.com` one or more. Neither matches the apex. Only a whole leftmost label may be a wildcard, and it must sit under a registrable domain (the bundled Public Suffix List, both sections) or a dev name; `*.com`, `*.co.uk` or `tenant-*.example.com` raise ValueError when the server is built. - Request Hosts with userinfo, paths, whitespace, empty labels, a non-numeric or out-of-range port, unbracketed IPv6 or raw non-ASCII are refused before matching. One trailing dot is stripped from entries and request Hosts alike, so `example.com.:8080` still matches an `example.com.` entry as it did under MCP's matcher. Entries must be ASCII (punycode for IDNs). - `host_validator(hostname) -> bool` on serve, ServeConfig, create_mcp_server, create_a2a_server and build_asgi_app is consulted when no allowed_hosts entry matches. It receives the normalized hostname without the port. It must be synchronous (an async validator raises TypeError at configuration), only a `True` result admits, and an exception or awaitable rejects. `adcp.server.HostValidator` names the type. Exact entries and `:*` port patterns keep their meaning. Entries the parser cannot structure keep matching their literal value. Refs #2010 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a possibly public listener With DNS-rebinding protection on, a server reachable on a public interface whose allowed_hosts holds only loopback or dev names answers 421 to MCP, A2A and agent-card discovery for every real hostname, and nothing said so. The SDK now logs a WARNING, once per policy per process, when protection is on, no host_validator is set, and every entry is localhost, *.localhost, a loopback or unspecified IP, or a reserved .test/.example/.invalid name. serve() judges first against the address it binds (quiet on a loopback IP and for stdio), so its decision covers the factories it calls. create_mcp_server uses its host; create_a2a_server and build_asgi_app do not know the listener and warn for a loopback-only policy. A bind address given as a hostname is never second-guessed. serve() also warns that host_validator is ignored when protection is disabled. Refs #2010 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the Origin check applies The HTTP Host and Origin policy section now covers leftmost-label wildcards and their public-suffix rule, ASCII-only entries, trailing-dot handling, host_validator (synchronous, True-only), the loopback-only warning and who emits it, and states that the Origin check applies to protocol POSTs and operational endpoints, not to GET/HEAD discovery reads. Closes #2010 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.
Closes #2010
What changed
Host matching for DNS-rebinding protection is now done by the SDK (
HostMatcherinsrc/adcp/server/http_policy.py) instead of MCP's literal_validate_host. Matching is case-insensitive. Origin matching is unchanged. Nothing waits on modelcontextprotocol/python-sdk#2141.Wildcards in
allowed_hosts*.agents.example.commatches exactly one extra label, the TLS wildcard rule.**.agents.example.commatches one or more labels.agents.example.comseparately.tenant-*.x,a.*.xand a bare*raiseValueErrorwhen the server is built.*.com,*.co.uk,**.github.ioand*.fly.devraise;*.example.co.uk,*.acme.github.ioand*.localhostare accepted.faßtofass, which is a different domain.host_validator(hostname) -> bool, onserve,ServeConfig,create_mcp_server,create_a2a_serverandbuild_asgi_app:async defvalidator, or a callable object with an async__call__, raisesTypeErrorat configuration.result is Trueadmits the Host. An awaitable result is closed and rejected, and an exception rejects.adcp.server.HostValidatornames the type.Request Host parsing rejects userinfo, path, query and fragment characters,
%, backslash, whitespace, non-ASCII, empty labels, ports that are empty, non-numeric or out of range, and unbracketed IPv6. One trailing dot is stripped from entries and request Hosts alike, soexample.com.:8080still matches anexample.com.entry as it did under MCP. Entries the parser cannot structure keep matching their literal value.Startup warning (
fix:commit). The SDK logs a WARNING, once per policy per process, when all of these hold:host_validatoris set,serve()judges first, with the address it binds. It stays quiet for a loopback IP or stdio, and its decision covers the factories it calls.create_mcp_serveruses itshost.create_a2a_serverandbuild_asgi_appdon't know where the app will be served, so they warn whenever the policy is loopback-only. A bind address given as a hostname never warns.servealso warns thathost_validatoris ignored when protection is off.Docs:
handler-authoring.md#http-host-and-origin-policycovers all of the above. It also states that the Origin check applies to protocol POSTs and operational endpoints, not to GET/HEAD discovery reads.Security review
An independent review found one high and four low issues; all are fixed here, each with tests:
serve().Design calls to review
*= one label and**= one or more, rather than*matching any depth.create_a2a_server,build_asgi_app) means warn. With default settings, test suites that build these apps get one warning per policy per process.host:abcfor ahost:*entry.Tests
tests/test_host_policy_wildcards.pycovers wildcard edge cases (apex, deeper subdomains, ports, uppercase, trailing dots, IDN/punycode, userinfo, smuggling characters, public suffixes), validator semantics, all four transports end to end, and the warning paths.mypy src/adcpis clean.🤖 Generated with Claude Code