Skip to content

feat(api): end personal access tokens on a password set and ask a session for a recent sign-in - #3570

Merged
fforootd merged 29 commits into
mainfrom
claude/adoring-rubin-5t2iz9
Dec 2, 2026
Merged

fforootd merged 29 commits into
mainfrom
claude/adoring-rubin-5t2iz9

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

ADR 095 recorded a risk nothing was built against: a hijacked Console session creates a personal access token (PAT), the owner changes their password, and the PAT keeps working for up to 90 days. This builds the two mitigations the ADR recommended, before PATs are switched on anywhere.

A person's PATs end when their password is set.

  • SetPasswordUserAction ends the person's unexpired PATs in the transaction that stores the password. Every password set for an existing user goes through that action, so the self-service change and the reset through a login flow inherit it when they are built.
  • Nothing triggers it on a default deployment yet. setUserPassword is the only path that replaces a password, it takes a project secret only, and the platform project mints none by default (ADR 053 §9). Until the change or the reset exists, a PAT's owner ends it with revokeMyPersonalAccessToken. The integration test proves the rule through the service.
  • The delete runs only for the platform project's people; a password set in any other project runs no statement. Creating a user with a password ends nothing (no PAT exists yet), nor does the rehash at sign-in.
  • One auth.token.revoked event records it, with reason password_set, type personal_access_token and count, the number of unexpired tokens that ended. Ending none records nothing.
  • New statement DeletePersonalAccessTokensByUserID in Postgres, Spanner and SQLite, with a parity test.
  • This breaks a CI job that uses one of the person's PATs. The changeset, the guide and the setUserPassword description say so.
  • No credential from before the password set creates a PAT (added after review). Creating one is refused when the session the credential stands in, a Console session or the one an access token was issued in, last proved a credential before the person's current password was set. Without it the token the set ended was replaced a moment later from the same cookie or access token. The person signs in again and both paths work. Sessions and OAuth grants are not ended.

A Console session creates a PAT only within 15 minutes of a sign-in.

  • The check reads the newest verification time among the session's credential factors (password, passkey, identity provider). Later it answers 403 tkn.pat_sign_in_required, with reason sign_in_too_old and max_age_seconds in the details. It is no 401, because the session is still good. The password refusal above uses the same code with reason password_set_after_sign_in.
  • An access token that carries personal_access_token.create is not held to the window.
  • Found on the way, fixed in the first commit: a sign-in attempt against an existing session copied the session's factors and stamped each as verified now. Such an attempt is complete with what it inherits, so it could be handed off and exchanged with nothing proven, and the session then looked freshly signed in. An inherited factor now keeps its time, in all three dialects.

ADR 095 (§3, §5, §6, risks), the docs guide, the events catalog, internal/service/AGENTS.md, the CLI's SKILL.md and the pending changesets are updated. ADR 095 gains §9: what a password set ends, the sign-in window, whether the OAuth path is held to it, and whether a PAT may set a password are fixed defaults now and open points for the policy work (ADR 066).

Validation

Run in a cloud container, Go 1.27.4, Node 24, PostgreSQL 16, and run again on the tree that has main merged in:

  • go test -count=1 -tags sqlite_integration ./internal/api/integration_test/ ./internal/api/integration_test/helpers/ ./internal/bootstrap/platform/ ./internal/storage/dialect/sqlite/ ./internal/storage/stmttest/ (the test:sqlite list): pass
  • go test -count=1 -tags postgres_integration on the test:postgres list (./cmd/cloud-launcher/ ./internal/api/integration_test/ … ./internal/storage/stmttest/) against a local PostgreSQL 16: pass
  • go test ./... -count=1 in apps/api: pass, once the console was built for the three cmd/server mux tests
  • turbo run lint --filter=@zitadel/server (format, vet, check-generate, OpenAPI lint, Go lint): pass
  • pnpm run check-openapi-rules, node scripts/check-adrs-index.mjs, node scripts/check-changesets-status.mjs: pass (the changeset length warning was there before)
  • Each new behaviour test fails without its change: checked by switching the password hook and the sign-in check off, by reverting the SQLite factor-time fix, and by removing the check that the session is the caller's own.
  • Spanner: green in CI, not run locally. The on-demand spanner workflow passed on this branch at 8aae053 (https://github.com/zitadel/nextgen/actions/runs/46934876242) and again at the merged head bfcee57 (https://github.com/zitadel/nextgen/actions/runs/46947671737): ./internal/api/integration_test/, ./internal/storage/dialect/spanner/, its migration/ package and ./internal/storage/stmttest/, with the new migration 000069_tokens_user_index.sql, the forced-index delete, the inherited factor time and every new token test.
  • Not run: the end-to-end, console and docs builds. setUserPassword was exercised through UserService.SetPassword, as the other integration tests do, not over HTTP.

Release notes / changeset

  • Changeset: .changeset/cli-login-and-pats.md (edited, pending): zitadel personal-access-token create is refused after a password set until zitadel login. @zitadel/cli.
  • Changeset: .changeset/personal-access-tokens.md (edited, still pending from the stack): a password set ends the person's personal access tokens and breaks jobs that use them; a session needs a sign-in within 15 minutes to create one. @zitadel/server, @zitadel/api.

Notes

Decisions taken, each with the alternative:

  • Window: 15 minutes, one constant. 10 was the alternative; 15 leaves time to sign in and reach the page. It can become a policy setting with the lifetime.
  • "Recent" is the newest credential factor's verification, not the session's or its token's age. Both of those are renewed by an exchange without a proof.
  • Fix the factor timestamp in storage rather than add an authenticated_at column to sessions: no migration, and the stored time now means what its name says. It touches the sign-in path in three dialects, so it is its own commit and can be its own pull request.
  • End only unexpired PATs, and count those. Deleting expired rows too would make the count say more ended than stopped working. Expired rows stay for the purge, as the ADR has it.
  • One auth.token.revoked with a count, following the session-delete precedent, rather than a field on auth.factor.password.set or one event per token. auth.token.revoked's payload schema changes from empty to three optional fields.
  • 403, not 401, for the sign-in refusal: SDKs clear the session cookie on a 401.
  • The delete is held to the platform project (changed after review; it first ran in every project). The user service is told which project's people hold PATs and hands that to every password set it applies. On Spanner the delete forces a new index, idx_tokens_user, as redeemAuthRequestCodeStmt does for its table.
  • One refusal code with a reason, not a second code, for a sign-in that predates the password: the caller's remedy is the same.
  • A five-second skew between a sign-in and its password still counts as "made with it": a registration writes both in one transaction and Postgres stamps them by different clocks. An integration test covers that case.
  • The sign-in check runs inside the create transaction. That closes the race with a password set on SQLite and Spanner. On Postgres it only narrows it; closing it needs a row lock on the person that the password write waits for, which is a new statement in three dialects and is not built.
  • Accounts with no password (passkey only, identity provider): no event ends their PATs today, because no operation removes a passkey or an identity link. Decided in the ADR for when those exist: removing a passkey or a link ends PATs, whether or not it is the last; adding one does not.

Still open, recorded in the ADR: telling the owner when a PAT is created; a Console page for PATs; signing out leaves PATs working by design; within the 15 minutes after a sign-in a session someone else also holds can still create one.

Not traced end to end: that every flow definition reaches the OAuth consent step only after a credential check. The token path relies on it.

https://claude.ai/code/session_0137eGmSjovZrRx7AfqMkuW2


Generated by Claude Code

claude added 18 commits December 2, 2026 07:05
…platform

ADR 095 is the record ADR 094 §5 waits for before a PAT is admitted. A PAT
belongs to a person homed in the platform project and acts as them, capped
by its scopes, on the operations a person's token reaches. It expires within
90 days, is created only from a Console session, and is listed and revoked
by its owner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
The user decided that the CLI, the API and MCP matter more than the Console
for creating a PAT. So a person's OAuth token may create one with a scope the
consent step never preselects, holding no scope that token lacks; a PAT still
never creates one, and the creating client is recorded. Scope choice on
consent is on main (#3543), which the first draft missed.

A PAT is now an opaque 256-bit secret stored as its SHA-256, with its record
id and a checksum in the token, so it depends on no key and a copy of the
table holds nothing usable. The 90-day limit is to become a policy later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
Creating a PAT is a marked call with a scope of its own, so ADR 094 §5's
rule fits it: the scope is the gate, and the MCP endpoint asks where the
client can answer once it asks about marked calls at all.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit c757ba5)
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit bef352c)
PATs are off until personal_access_tokens.enabled switches them on, since
they do open a bearer path a server without OAuth did not have, and §7 no
longer says otherwise. The create scope is never granted without the
consent step, and the MCP endpoint asks before a PAT is created where the
client can. A person holds at most 50 live PATs. The risks now name the
audience a PAT leaves and the Console session that outlives recovery,
with the options and a recommendation for the latter.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 93677b0)
A person homed in the platform project creates a PAT with
createMyPersonalAccessToken (POST /users/me/personal_access_tokens), lists
and revokes their own with listMyPersonalAccessTokens and
revokeMyPersonalAccessToken, from a Console session, an access token issued
for them, or (to list and revoke) a PAT (ADR 095).

A PAT reads zpat_<id>_<secret><checksum>: a 256-bit random secret whose
SHA-256 the tokens record keeps, found by the record id and compared in
constant time; a wrong checksum is refused before any read. The API and the
MCP endpoint take it on the operations an access token issued for a person
reaches, through the same gate: its owner is the principal, its scopes a
ceiling on the owner's grants at each call, and a refusal names the scope.
It expires within 90 days and stops while its owner is not active.

Creating one with an access token needs personal_access_token.create, which
consent never preselects; the PAT holds no scope that token lacks and records
its client. A PAT never creates one. Events of a PAT's calls name the owner
as a human actor, the PAT as token_id and pat_shared as delegation_type.

tokens gains name, secret_hash and client_id in the three dialects. The MCP
tool list budget is raised by the three tools' 3,700 bytes until the change
that makes room in it lands.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 442a041)
…client

A first-party client is asked no consent, so it would be granted
personal_access_token.create unasked, and with it a credential that
outlives its grant. The scope is now granted only on the consent step,
whoever the client is.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit edec824)
…ault

PATs were served wherever the platform project is, outside oauth.enabled,
so a server that took no person's bearer before would take a PAT after.
personal_access_tokens.enabled (NEXTGEN_PERSONAL_ACCESS_TOKENS_ENABLED) now
switches them on, off by default as oauth.enabled is. Off, the three
operations answer not_implemented and a zpat_ bearer is refused as an
unknown one.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 55f1699)
…pired

A credential that is only ever added to is one nobody reviews. Creating a
51st live PAT is refused with tkn.pat_invalid until the person revokes one.
Expired rows stay until a purge, which is a follow-up, and are not counted.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 234fa22)
A PAT leaves the audience of the token that created it: a token issued for
the MCP endpoint creates one through the endpoint, and the PAT then
answers on the API directly, where the endpoint's questions do not reach.
createMyPersonalAccessToken is now marked x-zitadel-asks: the endpoint asks
the person where the client can ask them, and sends the call where it
cannot, its own scope, ticked on purpose, being the gate (ADR 094 §5). The
tool says so, at 84 bytes, which the list budget's raise now counts.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 3b94cf2)
The endpoint now asks before createMyPersonalAccessToken where the client
can ask, so the agent's client in the integration test answers as its
person would, and the test holds that the person was asked.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 6cc66fb)
A project secret's scopes cover the three operations on a person's own
PATs, so the MCP endpoint listed them as tools that could only be refused.
No secret is anyone's person: Covers now passes them over for a secret.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 4d64c49)
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 6108cd1)
A PAT is persisted only with its secret's hash, and the Postgres dialect's
own token test still created one without it, which the Postgres lane
refused.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 5c38672)
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf

(the ADR part of commit 36bd497ba2, whose renames of CLI files belong to the CLI change)
…not call yet

The CLI's coverage test holds that every operation the API client offers is
called by a command or explained. The three personal access token operations
are a person's own, and the CLI holds a project secret until it can sign a
person in, so they are explained here. The CLI's sign-in and its token
commands, which call them, are their own change on top of this one and take
the explanation out again.

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

A sign-in attempt against an existing session copies the session's
verified factors, and CreateAuthAttempt stamped each of them as verified
at the attempt's creation. Such an attempt is complete with what it
inherits, so whoever held the session could hand it off and exchange it:
the session's factors then read as verified now, with nothing proven.

A factor that comes with a verification time keeps it, in all three
dialects; one without is stamped as before. Session.AuthenticatedAt reads
the newest verification among a session's credential factors, which is
what "a recent sign-in" can now rest on (ADR 095 §5).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSjovZrRx7AfqMkuW2
…ssion for a recent sign-in

The two mitigations ADR 095 recommended for a hijacked Console session
that mints a personal access token and keeps it after the owner
recovers the account.

A password set ends the person's unexpired tokens in the transaction
that stores the password. SetPasswordUserAction does it for every set
but a user's creation, so the self-service change and the reset will
inherit it; setUserPassword is the only caller that replaces a password
today. One auth.token.revoked records it, with reason, type and the
count of tokens that ended.

A Console session creates a token only within 15 minutes of the newest
verification of a credential factor in that session; later the request
answers 403 tkn.pat_sign_in_required. An access token with the create
scope is not held to the window.

ADR 095 §3, §5, §6 and its risks, the guide, the events catalog and the
pending changeset say so, including that a password set breaks a CI job
that uses one of the person's tokens.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSjovZrRx7AfqMkuW2
@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 7:11pm UTC

Request Review

…-api

main chose tool sets by URL (#3555): the catalog keeps this branch's asksWhereItCan beside main's tags, and the one budget on the tool list gives way to main's three checks.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main holds this branch's base, ADR 095, as one squash commit (#3548). Its tree is the base's final head merged with the main before it, which this branch already holds, so the squash is recorded as merged and nothing changes.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main gained a person's own reads (#3559), the client secret's rotation (#3561), the session type (#3551) and the CLI's client document (#3558). The personal access token migrations move behind the session type's (Postgres 64, Spanner 68, SQLite 51). A secret is refused on a person's own reads and on their personal access tokens alike, and the server's code is generated again from the merged spec. The tool-set tests expect the three token tools in the users set.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
The spec marks createMyPersonalAccessToken, listMyPersonalAccessTokens and revokeMyPersonalAccessToken x-zitadel-self, as it marks a person's own reads: the CLI, which holds a project secret, refuses them with its own reason, and the docs show a token issued for the person in their samples. The API passes a secret over on them before it is looked at, as on a person's own read, so the request is answered as one that sent no bearer. They stay a class of their own in the contract tests, since they name no project.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main gained a person's own sessions (#3560). The server's code is generated again from the merged spec, the tool-set tests expect both changes' tools in the users set, and ADR 092's measured figures count the three token tools: 91 on a plain URL, and 52 tools, 68,271 bytes, on the list a default consent yields.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Base automatically changed from claude/personal-access-tokens-api to main December 2, 2026 16:35
…rubin-5t2iz9

The base branch took main in. One conflict, in ADR 095's risk section:
the base still listed the options as not built; this branch's text, which
records the two that are, is kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSjovZrRx7AfqMkuW2
…ing-rubin-5t2iz9

The squash (348f144) has the tree of the branch head this one already
holds (377ba57), so the merge takes nothing from it and only records main
as an ancestor.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSjovZrRx7AfqMkuW2
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: bfcee57

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

This PR includes changesets to release 27 packages
Name Type
@zitadel/cli Minor
@zitadel/server Minor
@zitadel/api Minor
@zitadel/testing 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/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

…and say when it applies

From a review of this branch.

The delete of a person's personal access tokens ran on every password
set for an existing user in every project. Only the platform project's
people hold any, and on Spanner the tokens table has no named index on a
token's user to hold the delete to that person's rows. The user service
is now told which project's people hold tokens, hands that to every
password set it applies, and no other project runs the statement.

ADR 095 and the guide now say what the rule does not do yet: nothing
triggers it on a default deployment, where setUserPassword takes a
project secret only and the platform project has none; and a password
set ends the tokens, not the sessions and grants that can create new
ones.

Service-level tests cover each branch of the sign-in check, the session
of another person and an unavailable store among them, and a revoke
event that cannot be recorded.

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

A password set ended the person's tokens, and the same session or access
token created a new one a moment later. Creating one is now refused when
the session the credential stands in, a Console session or the one an
access token was issued in, last proved a credential before the person's
current password was set. The refusal is tkn.pat_sign_in_required, which
now carries a reason: sign_in_too_old with the window, or
password_set_after_sign_in.

A sign-in may read five seconds earlier than its password: a
registration writes both in one transaction, stamped by different
clocks. The check runs in the transaction that stores the token, which
closes the race with a password set on SQLite and Spanner and narrows it
on Postgres.

On Spanner the delete of a person's tokens forces a new index on a
token's user, so it does not lock the project's other tokens.

ADR 095 gains §9: what a password set ends, the sign-in window, whether
the OAuth path is held to it, and whether a token may set a password are
defaults now and open points for the policy work.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSjovZrRx7AfqMkuW2
main gained the session gates, the cover check on writes to a user and
the CLI's sign-in and personal-access-token commands. One conflict, in
the bundled OpenAPI document, resolved by regenerating it.

With the merge: the test harness names the project whose people hold
personal access tokens through its own platformProjectID, so a harness
without a platform project names none; and the CLI's skill and pending
changeset say that after a password set `personal-access-token create`
is refused until the person signs in again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSjovZrRx7AfqMkuW2
@fforootd
fforootd marked this pull request as ready for review December 2, 2026 19:25
Copilot AI balanced review requested due to automatic review settings December 2, 2026 19:25
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
@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-02T19:40:01.752834Z bfcee57 Draft marked ready
ℹ️ 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.

Merged via the queue into main with commit 43c7ab3 Dec 2, 2026
20 checks passed
@fforootd
fforootd deleted the claude/adoring-rubin-5t2iz9 branch December 2, 2026 19:30

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

A critical PostgreSQL race allows PAT creation to bypass password-recovery revocation, requiring a conflicting user-row lock and a coordinated regression test.

1 open issue
1 file not reviewed
  • apps/api/internal/service/mocks/service.mock.go: Generated file
What changed in this PR

Strengthens personal access token (PAT) recovery protections, building on the PAT API and ADR 095.

Changes:

  • Revokes unexpired PATs when their owner's password is set and records a grouped audit event.
  • Requires recent Console sign-in for PAT creation and checks sign-in against the current password.
  • Preserves inherited verification timestamps and updates tests, API contracts, generated clients, and guidance.
File Description
packages/​go/​api/​oas_validators_gen.go Generated revocation payload validation.
packages/​go/​api/​oas_schemas_gen.go Generated payload and error types.
packages/​go/​api/​oas_json_gen.go Generated payload and error serialization.
packages/​go/​api/​oas_client_gen.go Updated generated operation documentation.
docs/​design/​api/​events-catalog.md Documents grouped PAT revocation events.
docs/​adrs/​README.md Summarizes updated PAT decisions.
docs/​adrs/​095-personal-access-tokens.md Records recovery rules and remaining limitations.
apps/​docs/​content/​docs/​guides/​personal-access-tokens.mdx Explains sign-in requirements and automation impact.
apps/​cli/​skills/​zitadel-cli/​SKILL.md Documents CLI recovery steps.
apps/​api/​internal/​storage/​stmttest/​token_test.go Tests targeted PAT deletion across dialects.
apps/​api/​internal/​storage/​stmttest/​auth_attempt_test.go Tests inherited verification timestamps.
apps/​api/​internal/​storage/​dialect/​sqlite/​token.go Implements SQLite PAT deletion.
apps/​api/​internal/​storage/​dialect/​sqlite/​auth_attempt.go Preserves inherited factor timestamps.
apps/​api/​internal/​storage/​dialect/​spanner/​token.go Implements indexed Spanner PAT deletion.
apps/​api/​internal/​storage/​dialect/​spanner/​migration/​sql/​000069_tokens_user_index.sql Adds the token-owner index.
apps/​api/​internal/​storage/​dialect/​spanner/​auth_attempt.go Preserves inherited factor timestamps.
apps/​api/​internal/​storage/​dialect/​postgres/​token.go Implements PostgreSQL PAT deletion.
apps/​api/​internal/​storage/​dialect/​postgres/​auth_attempt.go Preserves inherited factor timestamps.
apps/​api/​internal/​storage/​dialect/​authattempt/​checks.go Includes verification time in storage input.
apps/​api/​internal/​service/​user.go Connects password setting to PAT revocation.
apps/​api/​internal/​service/​statement.go Defines the PAT deletion statement contract.
apps/​api/​internal/​service/​personal_access_token.go Enforces sign-in checks and emits revocation events.
apps/​api/​internal/​service/​personal_access_token_test.go Tests sign-in refusals and storage failures.
apps/​api/​internal/​service/​mocks/​service.mock.go Regenerates token deletion mocks.
apps/​api/​internal/​service/​event_payload_emit_test.go Tests password-triggered revocation events.
apps/​api/​internal/​service/​AGENTS.md Documents credential-replacement requirements.
apps/​api/​internal/​domain/​session.go Derives the latest credential verification time.
apps/​api/​internal/​domain/​personal_access_token.go Defines sign-in limits, checks, and errors.
apps/​api/​internal/​domain/​personal_access_token_test.go Tests sign-in boundaries and refusal details.
apps/​api/​internal/​domain/​event_payload.go Adds revocation reason, type, and count.
apps/​api/​internal/​api/​personal_access_token.go Passes the caller's session to creation checks.
apps/​api/​internal/​api/​integration_test/​personal_access_token_test.go Covers revocation and sign-in restrictions.
apps/​api/​internal/​api/​integration_test/​helpers/​user.go Configures platform PAT revocation in tests.
apps/​api/​internal/​api/​generated/​oas_validators_gen.go Generated revocation payload validation.
apps/​api/​internal/​api/​generated/​oas_unimplemented_gen.go Updated generated operation documentation.
apps/​api/​internal/​api/​generated/​oas_server_gen.go Updated generated handler documentation.
apps/​api/​internal/​api/​generated/​oas_schemas_gen.go Generated payload and error types.
apps/​api/​internal/​api/​generated/​oas_json_gen.go Generated payload and error serialization.
apps/​api/​internal/​api/​generated/​oas_handlers_gen.go Updated generated request-handler documentation.
apps/​api/​internal/​api/​error_handler.go Maps sign-in refusal to HTTP 403.
apps/​api/​cmd/​server/​server.go Configures platform-scoped PAT revocation.
apps/​api/​api/​openapi/​endpoints/​users/​me/​personal_access_tokens/​methods.yaml Documents creation restrictions and errors.
apps/​api/​api/​openapi/​endpoints/​users/​me/​personal_access_tokens/​createMyPersonalAccessToken-error-response.yaml Includes the sign-in-required error variant.
apps/​api/​api/​openapi/​endpoints/​users/​by_id/​password/​methods.yaml Documents password-setting revocation effects.
apps/​api/​api/​openapi/​endpoints/​events/​webhooks/​auth-token-revoked.yaml Describes grouped revocation webhook events.
apps/​api/​api/​openapi/​endpoints/​events/​types/​auth-token-revoked-event.yaml References the new revocation payload.
apps/​api/​api/​openapi/​endpoints/​events/​payloads/​auth-token-revoked-payload.yaml Defines optional revocation details.
apps/​api/​api/​openapi/​components/​schemas/​errors/​tkn-pat_sign_in_required.yaml Generated sign-in-required error schema.
apps/​api/​api/​openapi/​components/​examples/​errors/​tkn-pat_sign_in_required.yaml Generated sign-in-required error example.
apps/​api/​api/​openapi/​bundled/​openapi.json Regenerates the bundled API contract.
apps/​api/​api/​cmd/​gen_event_schemas/​main.go Updates revocation schema generation.
.changeset/​personal-access-tokens.md Announces recovery protections and automation impact.
.changeset/​cli-login-and-pats.md Announces the CLI sign-in recovery requirement.

Review effort: Balanced

// leave no gap. Postgres reads committed data without a lock on the
// user, so there a set that commits between this read and the commit
// below still lets the token through.
if err := s.signedIn(ctx, tx.Statements(), input); err != nil {
@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
Brings in #3570 (a password set ends personal access tokens). The consent
Spanner migrations sit behind its 000069 as 000070 and 000071.

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

This branch was successfully deployed

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