Skip to content

bug(auth): MCP leg accepts conflicting Authorization and alias tokens that the A2A leg rejects as ambiguous #1305

Closed

Description

@bokelley

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 as reason=ambiguous_header at :1728-1730).
  • MCP checks Authorization first 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 the Authorization principal. 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:

  1. On MCP, reject with 401 (ambiguous_header, as on A2A) when an alias carries a token that differs from the one in Authorization. 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.
  2. Add a BearerTokenAuth(on_conflicting_credentials="reject" | "warn") setting that applies to both legs. "warn" logs token fingerprints, never the values.

Activity

  1. added
    bugSomething isn't working
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Oct 2, 2026
  2. bokelley commented on Oct 2, 2026

    @bokelley
    ContributorAuthor

    Triage

    Classification: Bug
    Bucket(s): middleware (no matching repo label — gap noted)
    Status: ready-for-human

    What the experts said:

    • security-reviewer: Not an exploitable bypass; MCP authenticates the Authorization token 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.
    • ad-tech-protocol-expert: Neither RFC 6750 nor the MCP/A2A specs define server policy for two coexisting accepted carriers — this is an implementation gap. Option A applied symmetrically to both legs is correct; "reject if different, allow if identical" is consistent with the confused-deputy defense principle. Flagged as security-sensitive because it touches the auth trust boundary on both legs and changes middleware guarantees.
    • code-reviewer: Option A is ~15–20 lines, purely inside _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):

    • In _extract_bearer (MCP, auth.py:572): after resolving the canonical bearer, walk self._alias_header_names; if any alias header is non-empty, compare its parsed token to the canonical; if they differ, log reason=ambiguous_header at INFO and return None (→ 401); if identical, log at DEBUG and return the canonical token.
    • In _resolve_credential (A2A, auth.py:1571): add an identical-duplicate fast path before the len(accepted) > 1 reject — 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.
    • Update tests/test_auth_middleware.py:910 to 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 in test_serve_auth_both.py.
    • Document the MCP behavior change in CHANGELOG as a security fix (behavior change: MCP will now reject with 401 on ambiguous_header when Authorization and an alias carry different tokens).

    Do not implement Option B (on_conflicting_credentials enum) — 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 execute on this issue.

    Triaged by Claude Code. Session: https://claude.ai/code/session_01J6UKX1sbPnChud27HmQW7Q


    Generated by Claude Code

  3. added and removed
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions