Skip to content

http: invalidate cached token scopes when auth token changes#2204

Open
davidahmann wants to merge 1 commit intogithub:mainfrom
davidahmann:codex/issue-2203-token-scope-invalidation
Open

http: invalidate cached token scopes when auth token changes#2204
davidahmann wants to merge 1 commit intogithub:mainfrom
davidahmann:codex/issue-2203-token-scope-invalidation

Conversation

@davidahmann
Copy link

Problem

If scope context populated for one token is reused after a token change, tool filtering can reflect stale permissions.

Why now

Token rotation/swap during long-lived request flows is common; scope filtering must stay bound to the active token to avoid quiet governance drift.

What changed

  • Added token-bound scope context helpers:
    • WithTokenScopesForToken
    • GetTokenScopesForToken
  • Updated middleware/filtering to reuse scopes only when bound token matches active token:
    • pkg/http/middleware/pat_scope.go
    • pkg/http/middleware/scope_challenge.go
    • pkg/http/handler.go (PATScopeFilter)
  • Added regression tests:
    • pkg/context/token_test.go
    • token swap refetch case in pkg/http/middleware/pat_scope_test.go

Validation

  • go test ./pkg/context ./pkg/http/middleware ./pkg/http

Refs #2203

@davidahmann davidahmann requested a review from a team as a code owner March 12, 2026 17:16
@davidahmann
Copy link
Author

This PR prevents stale scope-filter decisions when auth tokens change by requiring cached scope context to match the active token before reuse.

The fix is intentionally small: add token-bound scope helpers, switch PAT/scope-challenge/filter paths to token-bound reads, and add regression tests for token-swap behavior.

Validation:

  • go test ./pkg/context ./pkg/http/middleware ./pkg/http (pass)

Inspired by research context: CAISI publishes independent, reproducible AI agent governance research: https://caisi.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant