Title: brand.json resolver: _canonicalize_url drops IPv6 brackets, and the jwks_origin_mismatch gate compares a canonical origin to a raw one · Issue #989 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: brand.json resolver: _canonicalize_url drops IPv6 brackets, and the jwks_origin_mismatch gate compares a canonical origin to a raw one · Issue #989 · adcontextprotocol/adcp-client-python
X Title: brand.json resolver: _canonicalize_url drops IPv6 brackets, and the jwks_origin_mismatch gate compares a canonical origin to a raw one · Issue #989 · adcontextprotocol/adcp-client-python
Description: Summary Two origin-normalization defects in the brand.json resolver, both from hand-rolled netloc string work: _canonicalize_url rebuilds the netloc from parts.hostname, which strips IPv6 brackets and never re-adds them. A bracketed IPv6...
Open Graph Description: Summary Two origin-normalization defects in the brand.json resolver, both from hand-rolled netloc string work: _canonicalize_url rebuilds the netloc from parts.hostname, which strips IPv6 brackets ...
X Description: Summary Two origin-normalization defects in the brand.json resolver, both from hand-rolled netloc string work: _canonicalize_url rebuilds the netloc from parts.hostname, which strips IPv6 brackets ...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/989
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"brand.json resolver: _canonicalize_url drops IPv6 brackets, and the jwks_origin_mismatch gate compares a canonical origin to a raw one","articleBody":"## Summary\n\nTwo origin-normalization defects in the `brand.json` resolver, both from hand-rolled netloc string work:\n\n1. `_canonicalize_url` rebuilds the netloc from `parts.hostname`, which strips IPv6 brackets and never re-adds them. A bracketed IPv6 `brand.json` URL is turned into a malformed URL, and the failure surfaces as an untyped `SSRFValidationError` escaping the resolver instead of a `BrandJsonResolverError`.\n2. The `jwks_origin_mismatch` gate compares a *canonicalized* brand origin against a *raw* agent origin, so cosmetic spelling differences in `agent.url` produce a spurious mismatch with an error message that blames a cross-origin trust pivot.\n\nBoth fail closed. Neither is a bypass — see \"Direction\" below, which matters because the second one sits on a security gate and reads worse than it is.\n\n## 1. `_canonicalize_url` de-brackets IPv6 authorities\n\n`src/adcp/signing/brand_jwks.py:714-721`:\n\n```python\nhost = parts.hostname or \"\" # :714 — strips [ ] from IPv6\n...\nnetloc = host if port is None else f\"{host}:{port}\" # :720 — never re-adds them\nreturn urlunsplit((scheme, netloc, parts.path, parts.query, \"\"))\n```\n\n```python\n>>> from adcp.signing.brand_jwks import _canonicalize_url\n>>> _canonicalize_url(\"https://[::1]/x\", allow_private=True)\n'https://::1/x'\n```\n\nThat string is then both the redirect-loop `seen` key (`:551-553`) and the URL handed to the transport builder at `:569` and to `client.get` at `:580`. The builder rejects it:\n\n```python\n>>> from adcp.signing.ip_pinned_transport import build_async_ip_pinned_transport\n>>> build_async_ip_pinned_transport(\"https://::1/x\", allow_private=True)\nadcp.signing.jwks.SSRFValidationError: URI has no host: 'https://::1/x'\n```\n\n`build_async_ip_pinned_transport` at `:569` is **outside** the `try` opened at `:577`, and the `except SSRFValidationError` at `:581` only wraps `client.get`. So the exception escapes `_fetch_brand_json` untyped — callers that handle `BrandJsonResolverError` see an `SSRFValidationError` instead. (httpx would have refused the same URL with `httpx.InvalidURL`, which is not an `httpx.HTTPError` and so is not caught by `:585` either.)\n\nMarginal in frequency — `brand.json` URLs are normally DNS names — but the diagnostic is wrong and the exception type is not part of the resolver's contract.\n\n**Same function, second gap.** Its docstring (`:685-701`) states it exists to close \"trivial aliasing attacks (case-mismatched host, default-port elision)\" against the `seen` set, and that a Python-only deployment would otherwise \"fail open where JS fails closed\". It does not strip the trailing FQDN-root dot and does not IDNA-encode, so it does not close those two aliases:\n\n```python\n>>> _canonicalize_url(\"https://Brand.Example./x\", allow_private=True)\n'https://brand.example./x' # distinct `seen` entry from .../x\n>>> _canonicalize_url(\"https://bücher.example/x\", allow_private=True)\n'https://bücher.example/x' # distinct from the xn-- spelling\n```\n\n`max_redirects` still bounds the chain, so this is not an unbounded loop — it means the depth cap, not the loop detector, is what stops it. Worth closing so the function meets its own stated contract, not because it is currently exploitable.\n\n## 2. The `jwks_origin_mismatch` gate compares canonical to raw\n\n`src/adcp/signing/brand_jwks.py:895-898`:\n\n```python\nbrand_parts = urlsplit(final_brand_url)\nagent_origin = f\"{agent_parts.scheme}://{agent_parts.netloc}\"\nbrand_origin = f\"{brand_parts.scheme}://{brand_parts.netloc}\"\nif agent_origin != brand_origin:\n raise BrandJsonResolverError(\"jwks_origin_mismatch\", ...)\n```\n\n`final_brand_url` is the output of `_canonicalize_url` (`:548`, `:641`, `:659` → `:673`): host lowercased, default port stripped, fragment stripped, userinfo rejected. `agent_url` is the raw `agents[].url` string from the document. So this is a byte comparison between a canonical value and an uncanonicalized one, and it uses raw `.netloc` — the one accessor in the module that keeps userinfo.\n\n```python\n>>> from adcp.signing.brand_jwks import _default_jwks_uri\n>>> BRAND = \"https://brand.example/.well-known/brand.json\" # already canonicalized\n\n>>> _default_jwks_uri(\"https://brand.example/agent\", BRAND)\n'https://brand.example/.well-known/jwks.json'\n\n>>> _default_jwks_uri(\"https://Brand.Example/agent\", BRAND)\nBrandJsonResolverError: jwks_origin_mismatch\n>>> _default_jwks_uri(\"https://brand.example:443/agent\", BRAND)\nBrandJsonResolverError: jwks_origin_mismatch\n>>> _default_jwks_uri(\"https://brand.example./agent\", BRAND)\nBrandJsonResolverError: jwks_origin_mismatch\n>>> _default_jwks_uri(\"https://user@brand.example/agent\", BRAND)\nBrandJsonResolverError: jwks_origin_mismatch\n```\n\nThe IDN pair diverges the same way: a `brand.json` fetched from `https://bücher.example/...` produces `brand_origin == \"https://bücher.example\"`, so an `agent.url` of `https://xn--bcher-kva.example/agent` mismatches despite naming the same host.\n\n### Direction: this fails closed, and cannot fail open\n\nStating this explicitly because the site is a security gate and the shape invites the opposite reading.\n\n- The brand side is always the output of `_canonicalize_url`: lowercase host, no userinfo, no default port, no fragment. The agent side is raw. A normalization divergence can therefore only make a raw string *unequal* to a canonical one. There is no input that makes two origins denoting **different** hosts compare equal, because equality here is byte equality against a value that is already in canonical form.\n- The return value at `:907` is built from `agent_origin`, but only on the equality branch — where `agent_origin` is byte-identical to `brand_origin`. So the derived `jwks_uri` is always rooted at the canonical brand origin. No trust pivot is reachable through this path.\n\nThe honest severity is therefore **interop / diagnostics, low**: a publisher who writes `agent.url: \"https://Brand.Example/agent\"` or includes an explicit `:443` in a `brand.json` served from `https://brand.example/` loses the default-`jwks_uri` path, and the error text tells them their agent is on a different origin from their brand.json — which it is not. The documented escape hatch (declare an explicit `jwks_uri`) works, so this is recoverable, just confusing.\n\n## Suggested direction\n\nBoth findings have the same fix shape: derive the origin through the package's designated host canonicalizer rather than string-concatenating a netloc.\n\n- `_canonicalize_url`: re-bracket the host when it is an IPv6 literal before reassembling the netloc, and route the host through `_idna_canonicalize.canonicalize_host` (which strips one trailing dot, lowercases, short-circuits IP literals, and A-label-encodes). Note `canonicalize_host` returns IPv6 literals unbracketed, so bracket re-addition is the caller's job either way.\n- `_default_jwks_uri`: build both origins the same way — `scheme.lower()` + `canonicalize_host(parts.hostname)` + non-default port — rather than comparing raw `.netloc` on one side and a canonical string on the other. Using `.hostname` rather than `.netloc` also drops the userinfo that only the agent side can currently carry.\n- Also move `build_async_ip_pinned_transport` at `:569` inside the `try` at `:577`, or wrap it, so an SSRF refusal on the transport-construction path surfaces as `BrandJsonResolverError(\"fetch_failed\", ...)` like the one on the request path already does.\n\n`canonicalize_host` raises on underscore hosts and over-long labels where these functions return them today; both sites are already fail-closed (they raise `BrandJsonResolverError` on bad input), so mapping the raise onto `invalid_url` is consistent with what is there.\n","author":{"url":"https://github.com/KonstantinMirin","@type":"Person","name":"KonstantinMirin"},"datePublished":"2026-07-29T09:59:14Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/989"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:768d4056-4942-e728-06cb-13643a505210 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0AA:3A4875:BC6F87:FC0814:6B00F698 |
| html-safe-nonce | 880530e882a641a696e52bddb01d41c860a5c1b41d4eb625bead4d4183c696a4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEFBOjNBNDg3NTpCQzZGODc6RkMwODE0OjZCMDBGNjk4IiwidmlzaXRvcl9pZCI6IjExOTc2NTAzNzM4NTk0MDc1MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4f40d177198aea308132e6ec7bf28f0ff89ab93e0d9187a6ffbf1b63d31c4c06 |
| hovercard-subject-tag | issue:5007929821 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/adcontextprotocol/adcp-client-python/989/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f3ec9bc6bdc8f9c167956a7989f1afc43c3525ae9a426782fb075d1cca2a746f/adcontextprotocol/adcp-client-python/issues/989 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f3ec9bc6bdc8f9c167956a7989f1afc43c3525ae9a426782fb075d1cca2a746f/adcontextprotocol/adcp-client-python/issues/989 |
| og:image:alt | Summary Two origin-normalization defects in the brand.json resolver, both from hand-rolled netloc string work: _canonicalize_url rebuilds the netloc from parts.hostname, which strips IPv6 brackets ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KonstantinMirin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/adcontextprotocol/adcp-client-python git https://github.com/adcontextprotocol/adcp-client-python.git |
| octolytics-dimension-user_id | 221690821 |
| octolytics-dimension-user_login | adcontextprotocol |
| octolytics-dimension-repository_id | 1090305973 |
| octolytics-dimension-repository_nwo | adcontextprotocol/adcp-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1090305973 |
| octolytics-dimension-repository_network_root_nwo | adcontextprotocol/adcp-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width