Repository navigation
Description
Summary
When one BearerTokenAuth config accepts both Authorization: Bearer and a legacy alias such as x-adcp-auth, the two legs handle a request carrying both headers in opposite ways:
- A2A collects every accepted carrier and rejects the request with 401 if there is more than one (
adcp/server/auth.py:1555-1573, logged asreason=ambiguous_headerat:1728-1730). - MCP checks
Authorizationfirst and returns as soon as it parses a token, so the alias is never read (auth.py:557-587). A request with two different tokens is authenticated as theAuthorizationprincipal. Nothing is logged, and the handler can't tell there was a second token.
So the same request is rejected on one leg and accepted on the other.
Reproduction (adcp 8.0.0)
import json
from starlette.testclient import TestClient
from adcp.server import ADCPHandler
from adcp.server.auth import BearerTokenAuth, Principal, auth_context_factory
from adcp.server.serve import _build_mcp_and_a2a_app # the builder serve(transport="both") uses
TOKENS = {"token-a": "buyer-a", "token-b": "buyer-b"}
seen = []
class Seller(ADCPHandler):
async def get_products(self, params, context=None):
seen.append(context.caller_identity)
return {"products": []}
app = _build_mcp_and_a2a_app(
Seller(), name="seller", port=3001, host="0.0.0.0", instructions=None,
test_controller=None, validation=None, stateless_http=True,
enable_dns_rebinding_protection=False, context_factory=auth_context_factory,
auth=BearerTokenAuth(
validate_token=lambda t: Principal(caller_identity=TOKENS[t]) if t in TOKENS else None,
legacy_header_aliases=["x-adcp-auth"], # both legs
),
)
HEADERS = {"content-type": "application/json", "accept": "application/json, text/event-stream",
"A2A-Version": "1.0", "authorization": "Bearer token-a", "x-adcp-auth": "token-b"}
PARAMS = {"buying_mode": "brief", "brief": "video"}
MCP_CALL = {"jsonrpc": "2.0", "id": 1, "method": "tools/call",
"params": {"name": "get_products", "arguments": PARAMS}}
A2A_CALL = {"jsonrpc": "2.0", "id": 1, "method": "SendMessage", "params": {"message": {
"messageId": "m1", "role": "ROLE_USER",
"parts": [{"data": {"skill": "get_products", "parameters": PARAMS}}]}}}
with TestClient(app) as client:
for leg, path, body in (("MCP", "/mcp", MCP_CALL), ("A2A", "/", A2A_CALL)):
seen.clear()
response = client.post(path, headers=HEADERS, content=json.dumps(body))
print(f"{leg}: HTTP {response.status_code}, "
f"authenticated as {seen[0] if seen else '(rejected)'!r}")Output:
MCP: HTTP 200, authenticated as 'buyer-a'
A2A: HTTP 401, authenticated as '(rejected)'
Why an adopter hits this
Two different tokens on one request usually mean one of three things: a proxy that injects or strips headers, a buyer partway through migrating credentials, or an attempt to slip a second credential past a layer that only checks one header. Embedded Sales Agent accepts x-adcp-auth on MCP for legacy buyers. It added DualCredentialAuditMiddleware (core/middleware/dual_credential_audit.py, 104 LOC) to log a SHA-256 fingerprint of each token when the two differ. Without that middleware, MCP gives no sign of the conflict at all.
#720 picked "Authorization wins" for MCP. It also suggested handing the divergence to an audit hook, but no hook was added. The A2A leg later went the stricter way.
Ask
Make the legs consistent. Either of these would work:
- On MCP, reject with 401 (
ambiguous_header, as on A2A) when an alias carries a token that differs from the one inAuthorization. Identical values could still be accepted, so a buyer that sends the same token in both headers during migration isn't broken. A2A rejects even identical duplicates today, which could be relaxed in the same way. - Add a
BearerTokenAuth(on_conflicting_credentials="reject" | "warn")setting that applies to both legs. "warn" logs token fingerprints, never the values.
Activity
bokelley commentedon Oct 2, 2026
Triage
Classification: Bug
Bucket(s): middleware (no matching repo label — gap noted)
Status: ready-for-human
What the experts said:
Authorizationtoken and never reads the alias, so no identity-swap is possible. Silent accept is a defense-in-depth gap (hinders incident response). Option A preferred. No CVE warranted; safe for normal release._extract_bearer; no shared code with the A2A path. One test needs updating:tests/test_auth_middleware.py:910(test_authorization_wins_when_both_headers_present) currently asserts 200 for differing tokens and will flip to 401. Bug-fix-level behavioral change; minor version bump appropriate.My take: Security reviewer says no Flag needed; protocol reviewer says human sign-off is warranted for a change that touches auth middleware guarantees on both transport legs. Per triage policy "when in doubt, Flag" — flagging for @bokelley to authorize. Both experts converge on Option A as the correct fix.
Implementation brief (pending authorization):
_extract_bearer(MCP,auth.py:572): after resolving the canonical bearer, walkself._alias_header_names; if any alias header is non-empty, compare its parsed token to the canonical; if they differ, logreason=ambiguous_headerat INFO and returnNone(→ 401); if identical, log at DEBUG and return the canonical token._resolve_credential(A2A,auth.py:1571): add an identical-duplicate fast path before thelen(accepted) > 1reject — if all accepted values decode to the same token, accept with a DEBUG log. This relaxes A2A to match Option A's identical-duplicate carve-out.tests/test_auth_middleware.py:910to expect 401 for differing tokens; add a companion test for identical-token pass-through on both legs; no A2A integration test covers this case today so add one intest_serve_auth_both.py.ambiguous_headerwhenAuthorizationand an alias carry different tokens).Do not implement Option B (
on_conflicting_credentialsenum) — the protocol reviewer recommends a fixed-safe default rather than a general policy dial that adopters will set to"warn"and ignore.To authorize implementation, comment
/triage executeon this issue.Triaged by Claude Code. Session: https://claude.ai/code/session_01J6UKX1sbPnChud27HmQW7Q
Generated by Claude Code
fix(auth)!: unify duplicate credential policy across transports (#1325)