Skip to content

BearerTokenAuthMiddleware does not construct AuthInfo — ctx.auth_info.kind unusable for bearer flows #576

Closed

Description

@bokelley

What

BearerTokenAuthMiddleware (`src/adcp/server/auth.py`) authenticates requests, sets the framework-private `current_principal` ContextVar with the validated principal id, and short-circuits on auth failure. What it does not do: construct an `AuthInfo` object and thread it into the request context.

Net effect for bearer adopters reading `RequestContext`:

  • `ctx.auth_info` is `None` (or default-stub) — adopters can't read `auth_info.kind`, `auth_info.key_id`, `auth_info.credential`, etc.
  • Adopters who want to branch on "is this a bearer or signed-request flow?" have no typed read.
  • After #574, `ctx.auth_principal` is correctly populated for bearer flows — but the surrounding typed auth surface (`auth_info.*`) is still unusable.

Why it matters

The triage security-reviewer flagged this as a structural gap during the issue #571 review. PR #574 addressed the immediate `auth_principal is None` papercut; this issue tracks the deeper fix so it doesn't only live in PR-body prose.

For adopters writing transport-agnostic handlers, `ctx.auth_info` is meant to be the typed identity surface. Today bearer adopters either (a) read `ctx.auth_principal` (post-#574) and ignore everything else, or (b) reach into framework-private contextvars to reconstruct what they need.

Possible direction

Have `BearerTokenAuthMiddleware` construct an `AuthInfo` after `validate_token` succeeds, populate `AuthInfo.kind = "bearer"` (or similar), `AuthInfo.principal = principal.caller_identity`, and thread it into the request context alongside the ContextVar. Then `_build_request_context` already does the right thing for both flows, and adopters can read `ctx.auth_info.kind` to discriminate.

Open questions:

  • What goes into `AuthInfo.credential` for a bearer flow? Per CLAUDE.md, the typed credential classes (`ApiKeyCredential`, `OAuthCredential`, `HttpSigCredential`) are for upstream propagation. Bearer adopters typically don't propagate the inbound bearer token outward — what's the right shape?
  • `AuthInfo.kind` enum: does "bearer" exist today, or do we extend it?
  • Backward compatibility: any consumer that assumes `auth_info` is `None` for bearer flows will break. Worth auditing before shipping.

Surfaced by

PR #574 (closes #571). Security-reviewer notes captured in the issue #571 triage comment.

Activity

  1. added
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on May 4, 2026
  2. added a commit that references this issue on May 4, 2026
    10927fe
  3. added 2 commits that reference this issue on May 4, 2026
    c2ab696
    078d0aa
  4. bokelley commented on May 4, 2026

    @bokelley
    ContributorAuthor

    Triage

    Classification: Bug
    Bucket: adcp.server.auth middleware + adcp.decisioning.handler
    Severity: Medium — ctx.auth_info always None for bearer flows; any handler calling ctx.auth_info.kind raises AttributeError

    Root cause: auth_context_factory correctly populated caller_identity / tenant_id on ToolContext but never set metadata["adcp.auth_info"]. PlatformHandler._extract_auth_info reads that key — so it always returned None for bearer requests even though the principal was present.

    Fix:

    1. auth_context_factory now constructs AuthInfo(kind="bearer", principal=..., credential=None) and stores it at metadata["adcp.auth_info"] when authenticated
    2. _build_ctx pops the key after extraction (mirrors the existing adcp.buyer_agent pop) so the AuthInfo object never reaches the context-echo/idempotency path

    Pre-PR review: Security reviewer and code reviewer both approved. No ship-blockers.

    Draft PR: #579


    Generated by Claude Code

  5. added
    bugSomething isn't working
    and removed
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on May 4, 2026
  6. added 2 commits that reference this issue on May 4, 2026
    cf04cf3
    901aa53
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