Skip to content

fix(api): hold a person's token to its scopes on an expand that reads another resource - #3547

Merged
fforootd merged 18 commits into
mainfrom
claude/grant-principal-expand-scope
Dec 2, 2026
Merged

fforootd merged 18 commits into
mainfrom
claude/grant-principal-expand-scope

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

  • The gap: an expand reads a resource beside the operation's own. The API declares seven; three checked no scope of a token issued for a person:

    Operation Expand What it read without the scope Scope it now asks
    queryGrants, getGrant principal each grantee's schema, attributes and metadata, on a token with grant.read alone user.read
    listSchemas in_use whether any user of the project is on a revision user.read
    listFlowDefinitions user_schema the user schema, on a token with flow_definition.read alone schema.read

    getUser refuses the first token for lack of user.read. ADR 092 §8 already said a token needs the scope where a session's grants waive it on an expanded read; the schema expand's description already promised user.read of a token.

  • The fix: every expand names the scope of what it reads in one table, expandScopes. requireExpandCeiling refuses the expand to a person's token without that scope, with 403 auth.scope_insufficient naming the scope, before anything is read. The three expands above call it, and so does an invitation's inviter, which fix(api): take a person's token on the operations a Console session may call, and guard invitations with the grant scopes #3538 had checked inline.

  • The guard: TestEveryExpandNamesTheScopeItReads holds the table to the spec's <resource>-expand enums, and each scope to one a person's token can carry. A new expand fails it until it names its scope; an expand the table does not know is refused to such a token.

  • Who is unaffected: a Console session and a project secret have no ceiling here. The check of what the caller may read (the principal's home project, the whole project for in_use) still runs after it.

  • The other four expands (teams and lifecycle_owner_team on users, release on deployments, inviter on invitations) already held a person's token to the scope; they are in the table and their code is unchanged, apart from inviter using the shared check.

  • Docs: the grant and flow definition expand descriptions, ADR 092 §8, the OpenAPI AGENTS.md and the pending changeset say it.

Validation

  • go test ./internal/api/ ./internal/mcp/ ./internal/service/ passes, with two new tests: TestEveryExpandNamesTheScopeItReads and TestRequireExpandCeiling.
  • go test -tags sqlite_integration ./internal/api/integration_test/ passes, with a new TestAccessTokenExpandsWithinItsScopes against the real API with real tokens: each of the four calls answers 403 auth.scope_insufficient naming the scope without it, and 200 with it. All four cases fail with the handler changes stashed (the first call answers 200).
  • turbo run generate for @zitadel/server and @zitadel/api, pnpm run check-openapi-rules, the toolchain's gofmt, go vet with and without the integration tag, scripts/go-lint.mjs and scripts/check-pr-title.mjs pass.
  • Not run: the Postgres and Spanner lanes. Nothing here 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: a person's token on the management API is unreleased.

Notes

  • For MCP clients: an agent whose token lacks the scope reads which one to ask the person for.
  • Not changed: without expand, a grant list still shows each grantee's user_id, identifier and display to a token with grant.read, and a project's member list does to one with project.read. That is what those lists are for.

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

claude added 13 commits December 2, 2026 00:41
…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
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
…ations' into claude/search-token-scopes

# Conflicts:
#	apps/api/internal/api/integration_test/access_token_test.go
search names one scope, the project's, and checked no other. A token issued
for a person with project.read alone found users by name or identifier,
teams, schemas, flow definitions and identity providers, whatever the token
was consented to. Each type search is to find now asks of such a token the
read scope that type's own list names, and a token without it is refused
with auth.scope_insufficient, naming the scope, before anything is read. A
session and a project secret have no such ceiling and search as before.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
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
…-scopes

Takes the base's merge of main, so this PR's diff against its base is
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
…-scopes

Takes the base's fix for an invitation replace; the changeset keeps both
branches' sentences. ADR 092 §8 also says that the tool list shows search
to a token with project.read alone, and that a call for a type the token
does not cover is refused with the scope it lacks.

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

An expand reads a resource beside the operation's own. Three of the seven
the API declares checked no scope of a token issued for a person: a grant's
principal (a user's schema, attributes and metadata, on a token with
grant.read alone), a schema's in_use and a flow definition's user_schema.
getUser refuses the first token for lack of user.read.

Every expand now names the scope of what it reads in one table, and the
three ask it of such a token, as an invitation's inviter already did. A test
holds the table to the spec's expand enums, so a new expand names its scope.
A Console session and a project secret have no ceiling and are unaffected.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@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 5:58am 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-02T05:17:24.353155Z 69b34bc 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: a93db7e

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

Picks up #3537, which landed on main first.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
#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
Base automatically changed from claude/search-token-scopes to main December 2, 2026 05:51
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
…cope

Picks up what landed on main in between: #3541, #3539, #3543 and #3542.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
#3546 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
fforootd enabled auto-merge December 2, 2026 05:55
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit bea794f Dec 2, 2026
17 of 18 checks passed
@fforootd
fforootd deleted the claude/grant-principal-expand-scope branch December 2, 2026 06:05
@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 #3546 and #3547, which landed after #3542.

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

This branch was successfully deployed

1 active deployment
Preview — a93db7ee 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.

2 participants