Skip to content

fix(api): take a person's token on the operations a Console session may call, and guard invitations with the grant scopes - #3538

Merged
fforootd merged 7 commits into
mainfrom
claude/person-token-session-operations
Dec 2, 2026
Merged

fforootd merged 7 commits into
mainfrom
claude/person-token-session-operations

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

  • The bug: handleAccessToken decides whether a person's token may call an operation by userBoundSessionOperations. That list was kept for another purpose: which operations skip an anonymous building cookie. Six operations take both a session cookie and a bearer but were missing from it, so the Console could call them and a person's token could not:
    • createInvitation, listInvitations, getInvitation, cancelInvitation
    • getApplicationRevision
    • evaluatePolicy
  • The fix: they join the list, with no exception. The repository owner decided on 2026-12-02 that the credential and its scopes decide what a caller may do, whether it is a person who consented, a personal access token or a machine identity.
  • Invitations take the grant scopes. The invitation operations named project.write, the scope that renames a project. A client a project administrator had allowed to change a project could then have created an admin invitation, whose link anyone signed in redeems for 72 hours, while createGrant on the same token is refused without grant.create. An invitation ends in a grant and its gate asks what creating a grant asks, so:
    • createInvitation names grant.create;
    • listInvitations and getInvitation name grant.read;
    • cancelInvitation names grant.delete, so it leaves the list of removals on a write scope in scripts/openapi-casing-rules.test.mjs.
    • A project secret is unaffected: its project.write covers every scope.
    • This answers the permission catalog's open question on project invitations (owner's decision, 2026-12-02).
  • A replace asks what its parts ask. createInvitation with replaces_invitation_id deletes the original, and one that sends no metadata answers with the original's. Of a person's token it therefore needs grant.delete beside grant.create, and grant.read when it carries the metadata over. Otherwise a token with grant.create alone would cancel an invitation that cancelInvitation refuses it. Found by an independent review of this PR.
  • The inviter needs user.read: expand=inviter on the invitation list answers 403 auth.scope_insufficient to a token without user.read. An inviter is a user, and a token's scopes are a ceiling the person's grants do not lift, as on the other expands.
  • The guard: TestAPersonsTokenReachesWhatASessionReaches holds every operation the spec lets both a session cookie and a bearer call to the list.
  • Scopes: the scopes a person's token can use are unchanged (28), so the MCP endpoint's metadata doesn't move.
  • Authorization: each operation's gate is unchanged. The invitation operations still ask admin on the project (ADR 086), getApplicationRevision and evaluatePolicy ask viewer. A token's scopes cap the person's own grants.
  • MCP: a person's client is shown five of the six as tools. createInvitation becomes a tool with feat(api): offer an MCP client the operations that answer with a credential #3542.

Validation

  • TestAPersonsTokenReachesWhatASessionReaches fails on main naming the missing operations, and passes with the fix.
  • go test ./internal/api/ ./internal/mcp/ passes. That covers the gate contract with anonymous cookies, TestEveryOperationAPersonsTokenReachesNamesAScope, TestAPersonsTokenReadsTheProjectWithTheReadScope and TestPersonScopesAreScopesAPersonsTokenCanUse.
  • go test -tags sqlite_integration ./internal/api/integration_test/ passes, with a new TestAccessTokenWorksOnInvitationsWithTheGrantScopes:
    • project.write with project.read creates no invitation and lists none;
    • grant.create creates one, grant.read reads it, and only grant.delete cancels it;
    • a replace is refused on grant.create with grant.read, and without metadata on grant.create with grant.delete; the original is still there after both, and the replace passes with grant.delete and its own metadata (this part fails without the fix);
    • expand=inviter needs user.read as well.
  • turbo run generate for @zitadel/server and @zitadel/api: the bundled spec, the generated security and handler code and the Go client changed with the scopes.
  • pnpm run check-openapi-rules passes.
  • turbo run lint --filter=@zitadel/server --continue: 14 of 15 tasks pass. format fails on internal/flowengine/sso_test.go, which this PR doesn't touch: the container's gofmt is older than the toolchain, and the toolchain's own is clean.
  • node scripts/check-pr-title.mjs passes.
  • Not run: the Postgres and Spanner lanes. Nothing in this PR touches storage.

Release notes / changeset

  • Changeset: edits the pending .changeset/api-person-token.md (@zitadel/server, @zitadel/api, minor), as .changeset/README.md asks for a fix to a change that has not been released. It now says the invitation operations name the grant scopes, and that a project secret is unaffected.

Notes

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

…ay call

A person's token is meant to reach what a Console session of theirs reaches,
but handleAccessToken read userBoundSessionOperations, a list kept for
anonymous cookies, and five operations that take both a session cookie and a
bearer were missing from it: listInvitations, getInvitation,
cancelInvitation, getApplicationRevision and evaluatePolicy. They join it,
the two invitation reads join projectReads, and a test now holds the list to
the spec. createInvitation stays off it by a decision the test names: its
answer is a link that gives a role, and a person's token reaches no
operation that answers with a credential.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Copilot AI balanced review requested due to automatic review settings December 2, 2026 00:41
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Dec 2, 2026 4:40am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-12-02T00:53:48.448560Z c70583d 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.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: ad7f798

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@zitadel/server Minor
@zitadel/api Minor
@zitadel/cli Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/testing Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-sveltekit Minor
@zitadel/server-sdk-contract Patch
@zitadel/server-darwin-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-win32-x64 Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The follow-up adds a separate release note instead of updating the existing pending changeset, contrary to repository policy.

1 open issue
What changed in this PR

Extends person-token access to five management API operations already available to Console sessions, while keeping invitation creation excluded.

Changes:

  • Enables the five operations and uses project.read for invitation reads.
  • Adds a spec-based test guarding session/token operation parity.
  • Documents the exception and release impact.
File Description
docs/​adrs/​092-mcp-server.md Documents the invitation-creation exception.
apps/​api/​internal/​api/​security.go Expands token access and invitation read-scope mapping.
apps/​api/​internal/​api/​security_access_token_test.go Checks operation parity and explicit exceptions.
.changeset/​person-token-session-operations.md Adds a server release note.

Review effort: Balanced

The exception kept a person's token off createInvitation because its answer
is a link that gives a role. The credential and its scopes decide what a
caller may do, so the exception goes: a person's token reaches every
operation that takes both a session cookie and a bearer, and the test holds
the list to the spec without exceptions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…s token

A person's token on the management API has not been released, and its
pending changeset already says the token reaches the operations a Console
session may call (.changeset/README.md). It now also says project.read
reads a project's invitations.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
A review found that a token with only project.read read each inviter's user
ID and email through expand=inviter on the invitation list, now that the
list takes a person's token. An inviter is a user, and a token's scopes are a
ceiling the person's grants do not lift, so the expand asks for user.read as
the other expands ask for their scope. ADR 092 also counted three reads
under project.read where there are five.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
The invitation operations named project.write, the scope that renames a
project. Once a person's token reached them, a client a project
administrator had allowed to change a project could create an admin
invitation, whose link anyone signed in redeems, while createGrant on the
same token is refused without grant.create. An invitation ends in a grant and
its gate asks what creating a grant asks, so createInvitation names
grant.create, the two reads grant.read and cancelInvitation grant.delete. A
project secret is unaffected: its project.write covers every scope. This
answers the permission catalog's open question on project invitations.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@fforootd fforootd changed the title fix(api): take a person's token on the operations a Console session may call fix(api): take a person's token on the operations a Console session may call, and guard invitations with the grant scopes Dec 2, 2026
Picks up #3545, which the PR stacked on this branch (#3546) already
holds, so that PR's diff shows only its own change.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
createInvitation with replaces_invitation_id deletes the original, and one
that sends no metadata answers with the original's. A person's token issued
with grant.create alone could so cancel an invitation that cancelInvitation
refuses it, and read a name getInvitation refuses it. A replace now asks
grant.delete of such a token, and grant.read when it carries the metadata
over. A Console session and a project secret are unaffected.

The contract test's open note on invitation reads named the catalog's old
home for invitations; it now names the grant scopes.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Merged via the queue into main with commit 65597c7 Dec 2, 2026
18 checks passed
@fforootd
fforootd deleted the claude/person-token-session-operations branch December 2, 2026 05:33
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Dec 2, 2026
fforootd pushed a commit that referenced this pull request Dec 2, 2026
Picks up #3537, which landed on main first.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
#3538 landed on main as one commit. This branch already holds its changes
through the old base branch, so the merge takes nothing from it: it only
records main as an ancestor, so that the pull request shows its own change.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
The base branch had main merged in before it landed; this takes those
merges, so that main's squash of #3538 is an ancestor here too.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
Picks up what landed on main in between: #3538, #3541, #3539 and #3543.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U

This branch was successfully deployed

1 active deployment
Preview — ad7f7982 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants