Skip to content

fix(tokens): only a plain api key may delegate an assertion scope - #119

Merged
khaliqgant merged 2 commits into
mainfrom
fix/assertion-scope-credential
Oct 31, 2026
Merged

khaliqgant merged 2 commits into
mainfrom
fix/assertion-scope-credential

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #114, addressing review thread #114 (comment).

Delegating an assertion scope (through POST /v1/api-keys or POST /v1/tokens/workspace) now requires the caller to be a plain API key that holds the exact literal. Bearer tokens and workspace tokens do not qualify, because their scopes can be assigned within an org. Broker keys are provisioned out of band (bootstrap file or operator insert), so the assertion tests now seed them directly.

Verification

  • packages/server npm test: 694/694 pass.
  • tsc --noEmit (after turbo build): clean.
  • Reverting the credential check fails the new bearer-delegation test.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff


Agent Relay sessions

  • claude session a685ac1e · opened via gh pr create · last active 2026-10-31

Bearer tokens and workspace tokens no longer count as holding an assertion
scope for delegation, since their scopes are assignable within an org. Broker
keys are provisioned out of band; tests now seed them directly.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T04:46:55.964535Z 81dd7f8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

Broker-scope delegation now requires a plain API key with the exact requested scope. API-key and workspace-token creation routes pass caller type and scopes to the check. Tests cover bearer-token rejection and plain API-key delegation.

Changes: Broker scope delegation

Layer / File(s) Summary
Broker-scope eligibility rule
packages/server/src/lib/broker-scopes.ts
The check now rejects broker-scope delegation unless the caller is a plain API key that holds the exact requested scope.
Route integration and test coverage
packages/server/src/routes/api-keys.ts, packages/server/src/routes/tokens.ts, packages/server/src/__tests__/test-helpers.ts, packages/server/src/__tests__/tokens-route.test.ts
Both routes pass caller scopes and plain API-key status to the check. Tests seed plain API keys directly and cover rejection for bearer JWTs and successful delegation by a plain API key.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: kjgbot

Merge Risk: Minimal · up to 81dd7

No merge-blocking defect was found. Additional assertions would protect the delegation rules against regressions.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the keys at night,
Broker scopes must match just right.
A plain key may pass along,
A bearer token gets a no.
Tests hop through the guarded door,
Then curl up softly on the floor.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge; the previous test gap is addressed and no new issues were found.

Summary

Assertion scopes can now be delegated only by a plain API key holding the exact literal.

  • Only a plain API key can pass on a broker scope.

Reviews (2) · Last reviewed commit: "test(tokens): cover workspace-token dele..." · Reviewed by Greptile

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@khaliqgant
khaliqgant merged commit 6ccf423 into main Oct 31, 2026
6 checks passed
AgentRelayBot pushed a commit that referenced this pull request Oct 31, 2026
After merging main (#119: only a plain API key holding a broker literal
may delegate it), the issuer harness created its mint key through a
bearer token carrying the literal, which is now a scope_escalation (11
tests failed with 403). The operator is now a plain API key seeded out
of band, and a new test pins that a bearer token holding the mint
literal can delegate it neither onto an API key nor onto a workspace
token.

Server suite 710/710; typecheck clean.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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