Skip to content

fix(middleware): refuse agent tokens minted by another tenant - #5

Merged
TheGreatAxios merged 2 commits into
cl-9312-agent-token-export-resolvedworkflowrunscope-andfrom
cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken
Sep 27, 2026
Merged

TheGreatAxios merged 2 commits into
cl-9312-agent-token-export-resolvedworkflowrunscope-andfrom
cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • requireAgentToken and createAgentTokenVerifier share one tenant check: a token whose tenant differs from c.get("tenant").id gets the same bare 401, so consuming routes no longer carry their own check.
  • The tenant is read before the header, so mounted without the hub's tenant middleware every request fails: the middleware with a 500, and createAgentTokenVerifier returns a rejected promise rather than throwing synchronously (both tested).
  • mountAgentTokens reads the tenant from TenantEnv; the resolveTenantId option is removed (breaking for hosts that pass it).
  • README drops the per-route tenant check.
  • Stacked on feat(types): type agent-token contexts against the hub's TenantEnv #4.

Verification

  • bun run typecheck, bun run build: pass
  • DB suite against local Postgres (DATABASE_URL=... bun test --timeout 60000 ./src): 8 pass, 0 fail, including cross-tenant and untenanted cases

Closes CL-9188

@TheGreatAxios TheGreatAxios left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review: diff matches the linked ticket(s); independent review passes addressed (fixed or waived as noted in the description); typecheck, build and the Postgres-backed suite pass on this branch.

@TheGreatAxios
TheGreatAxios force-pushed the cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken branch from 6367d2d to b88617e Compare September 25, 2026 18:09
@TheGreatAxios
TheGreatAxios force-pushed the cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken branch 2 times, most recently from ecd71b3 to 52e6881 Compare September 25, 2026 23:49
@TheGreatAxios TheGreatAxios changed the title Refuse agent tokens minted by another tenant in requireAgentToken Refuse agent tokens minted by another tenant Sep 25, 2026
@TheGreatAxios
TheGreatAxios force-pushed the cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken branch from 52e6881 to 865941a Compare September 25, 2026 23:53
@TheGreatAxios TheGreatAxios changed the title Refuse agent tokens minted by another tenant fix(middleware)!: refuse agent tokens minted by another tenant Sep 26, 2026
@TheGreatAxios
TheGreatAxios force-pushed the cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken branch from 865941a to 356c044 Compare September 26, 2026 01:27
Leaving the tenant comparison to each consuming route made forgetting it
a cross-tenant hole.
@TheGreatAxios
TheGreatAxios force-pushed the cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken branch from 356c044 to 4ecb538 Compare September 26, 2026 01:37
@TheGreatAxios TheGreatAxios changed the title fix(middleware)!: refuse agent tokens minted by another tenant fix(middleware): refuse agent tokens minted by another tenant Sep 26, 2026
@TheGreatAxios
TheGreatAxios added this pull request to stack #12 September 26, 2026 01:58
createAgentTokenVerifier now refuses another tenant's token like
requireAgentToken does, and mountAgentTokens reads the tenant from
TenantEnv instead of a resolveTenantId option that could disagree.
@TheGreatAxios
TheGreatAxios force-pushed the cl-9188-agent-token-enforce-tenant-match-in-requireagenttoken branch from 4ecb538 to b50eb06 Compare September 27, 2026 01:00
@TheGreatAxios
TheGreatAxios removed this pull request from stack #12 September 27, 2026 01:42
@TheGreatAxios
TheGreatAxios added this pull request to stack #17 September 27, 2026 01:43
@TheGreatAxios
TheGreatAxios merged commit e89ef10 into main Sep 27, 2026
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