Repository navigation
feat: accept /api/v1 paths in the SDK and dev-proxy gates - #2357
Conversation
ADR 077 moves the resource API under /api/v1, and until 1.0.0 the server answers both spellings. Every check that decides by path now accepts both, so apps keep signing in on any mix of versions once their packages call the prefix: - @zitadel/sdk-core: the project-secret gate (POST /sessions/exchange) and the shared-session handling of the session probe, sign-in and sign-out trim the prefix before they compare. All six server SDKs go through it. - The dev proxies zitadel setup writes for SPAs (Vite and Angular) move to zitadel:proxy:v3, whose bearer hook knows both exchange paths. A separate convenience edit migrates the v2 hook, matched formatter-insensitively in vite.config.*: zitadel doctor warns until zitadel doctor --fix applies it, since a v2 proxy keeps working until the packages call the prefix. - The credential-policy check now accepts only the exact guard (POST, one or both exchange paths, no overwrite), so a guard an `|| true` widens is flagged for manual review. - @zitadel/api exports API_PREFIX; the SDK proxy docs tell a hand-written SPA production proxy to accept both paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: ce3a561 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
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 |
Brings in #2358's server, so CI and this branch's Vercel preview run against a server that serves /api/v1. The PR's base is that branch, so its diff is unchanged. When #2357 and #2358 have merged, rebase with: git rebase --onto origin/main claude/api-v1-gates-and-server Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflicts with ADR 083's session cookies: - The Vite and Angular proxies' session-cookie edits take both migrations: main replaces the hooks from before ADR 083, and this branch finds the CLI's entry by either version of its bearer hook. main's new code calls this branch's cliEntry instead of the cliEntryStatements it renamed. - doctor's tests keep this branch's v2-proxy test beside main's two for the hooks from before ADR 083. - sdk-core's tests for the prefixed session probe, sign-in and sign-out use ADR 083's cookie names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cloud functions check BotID only in front of the sign-in widget's
POST /flow and /flow/{id}/submit, matched by exact path. Once the widget
calls the API under /api/v1 (ADR 077), those calls would pass unchecked.
The check reads both spellings, as the SDK and dev-proxy gates do.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ath-gates Stacks this PR on #2356 (ADR 077's amendment), so the stack's top tests the whole change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stacks this PR on #2358 instead of the merge branch of #2357 and #2358, and brings in main through them. Conflicts: - ADR 077, its README row and the design docs keep this PR's "Implemented" and "shipped" wording, with #2356's new section 5 text and main's other edits to the resource map. - The console's Vite config is main's, restructured for the cloud's add-on, with this PR's proxy for /api/v1; the test base moved to vitest.config.ts, which now names the origin. The console's specs that main added or changed call /api/v1, as the rest do. - sdk-core's revokeSession (ADR 083, main) asks for the CSRF token and revokes under the prefix; its tests and the six server SDKs' tests take main's cookie names and this PR's prefixed URLs. - The scaffold guidance, sdk-next's docs, the CLI's SKILL.md, the console README and src/api/zitadel.ts take main's text with this PR's /api/v1 paths. The CLI's local-server tests and console-real's response match take main's cases on the prefixed paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code main added since this PR was written still called the root paths: - The hosted cloud's functions read /users/me and /users/me/teams from the server; they now read them under the prefix. The sign-in widget the console's cloud add-on points at them calls /cloud/zitadel/api/v1/..., which they forward unchanged, and #2357's bot check reads both spellings. - Tests main added mock the server at the root: the CLI's policy, rollback, env add, preview list, setup deploy and issuer-origin tests, the console's releases and deployments specs, and the server SDKs' CSRF read before a sign-out revoke. They mock the prefix now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🔵 Needs a closer look
The change reworks security-critical credential-forwarding logic—the project-secret guard parser and AST-based v2→v3 proxy migration gate—which calls for human security sign-off rather than automated approval.
No open issues 🎉
What changed in this PR
This PR is the second step (after the docs-only #2356) in the ADR 077 rollout that moves Zitadel's resource API under an /api/v1 prefix. It makes every path-based gate accept both the current path and the /api/v1-prefixed spelling, so that when later PRs (#2358/#2359) switch clients to the prefix, nothing silently breaks. Nothing here calls /api/v1 yet; this only widens the gates and migrates scaffolded dev proxies.
Changes:
@zitadel/apiexports a newAPI_PREFIX(/api/v1);@zitadel/sdk-core'srequiresProjectSecret/proxySessionCookiesand cloud-functions'isFlowWritestrip the prefix before comparing paths, accepting both spellings while rejecting doubled/other/look-alike prefixes.- The CLI's scaffolded SPA dev proxies (Vite + Angular) move from
zitadel:proxy:v2tov3, attaching the project secret to bothPOST /sessions/exchangeandPOST /api/v1/sessions/exchange;zitadel doctor/--fixdetect and migrate a v2 proxy, and the credential-policy check now parses the guard structurally. - Docs (
proxy.mdx) and a changeset (@zitadel/api/@zitadel/cli/@zitadel/sdk-coreminor) describe the dual-path behavior.
| File | Description |
|---|---|
| packages/api/src/runtime/base-url.ts | Adds the public API_PREFIX constant. |
| packages/sdk-core/src/middleware.ts | Adds operationPath prefix-stripping used by the secret and session-cookie gates. |
| packages/sdk-core/src/middleware.spec.ts | Tests both spellings plus doubled/other/look-alike prefixes. |
| apps/cloud-functions/src/sign-in.ts | isFlowWrite strips a local API_PREFIX before matching flow writes. |
| apps/cloud-functions/src/sign-in.spec.ts | Covers prefixed flow writes and rejected non-matching prefixes. |
| apps/cli/.../proxy-credential-policy.ts | v3/v2 markers, dual-path check, structural isExchangeOnlyCondition guard parser. |
| apps/cli/.../vite-support.ts | cliEntryOf version detection + viteApiPrefixEdit/Verdict v2→v3 migration op. |
| apps/cli/.../angular/templates.ts | Parameterized bearer hook; proxyConfApiPrefixEdit/Verdict. |
| apps/cli/.../angular/index.ts | Wires the new proxy.conf.cjs convenience edit. |
| apps/cli/.../{vue,svelte,solid,react,qwik}/index.ts | Each adds viteApiPrefixOp to routeOps. |
| apps/cli/tests/.../{vite-support,angular/index,doctor/checks}.test.ts | Tests for migration, verdicts, formatter resilience, doctor warn/fix. |
| apps/docs/content/docs/sdks/proxy.mdx | Documents dual-path proxy behavior and the doctor migration. |
| .changeset/api-v1-path-gates.md | Minor changeset for the three published packages. |
Note: the credential-guard parsing and AST-based proxy migration are security-sensitive (they decide when a project secret is forwarded), so I've flagged them for human sign-off despite finding no defects.
Review effort: Balanced
…d's checks The CLI's doctor verdicts on an SPA dev proxy and the cloud functions' bot check each spelled /api/v1 out again, beside @zitadel/api's API_PREFIX. Both now derive it: the CLI names the prefixed exchange path once (PREFIXED_EXCHANGE_PATH) and its verdicts and messages use it; the cloud functions import API_PREFIX, with @zitadel/api as a dependency, its build ahead of theirs in moon and turbo, and their tests reading its source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2357's shared API prefix for the CLI's and cloud's checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2358's spec checks and #2357's shared prefix. The cloud functions' sign-in forwarder and directory both import API_PREFIX from @zitadel/api now, so the constant this branch had added to zitadel.ts goes; base-url.spec.ts keeps this branch's imports beside the new test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The specs import @zitadel/api's dist/, as Next does: the source condition the previous commit set reaches only Vite's client resolution, not the SSR mode a node-environment test runs in. Locally a dist/ was there; in CI, where nothing had built it, three suites failed with "Cannot find package '@zitadel/api/runtime/base-url'". The test task now waits for api:build in moon and @zitadel/api#build in turbo, as sdk-core's and the test kit's do, and the ineffective condition goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2357's build edge for the cloud functions' tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2357's build edge for the cloud functions' tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2357's build edge for the cloud functions' tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Context
/api/v1yet.Summary
Several places decide by the exact path
/sessions/exchangeor/sessions/me. Once an app's packages call/api/v1/…, each of them would silently stop working: the project secret would no longer reach the session exchange, and the shared-session handling would no longer recognise the probe, sign-in or sign-out. Until 1.0.0 the server answers both spellings, so every such check now accepts both.@zitadel/sdk-core.requiresProjectSecretandproxySessionCookies(probe, sign-in, sign-out) trim the API prefix before they compare. A doubled prefix (/api/v1/api/v1/…), another prefix (/api/v2/…) and look-alikes (/api/v1x/…) do not match. All six server SDKs go through these functions, so they need no change of their own.@zitadel/apiexportsAPI_PREFIX.zitadel setupwrites for SPAs (Vite and Angular) move tozitadel:proxy:v3: the bearer hook attaches the project secret toPOST /sessions/exchangeandPOST /api/v1/sessions/exchange.convenienceedit: invite.config.*it finds the CLI's own v2 hook through the existing formatter-insensitive fingerprint, so a Prettier- or Biome-formatted config still migrates; inproxy.conf.cjsit replaces the exact managed hook. Only the hook statement and the entry's marker change.zitadel doctorwarns about a v2 proxy (it keeps working until the packages call the prefix) andzitadel doctor --fixmigrates it. A CLI entry whose hook was changed by hand, and a hand-written proxy that attaches the secret but never names/api/v1/sessions/exchange, read asunknown.POST /flowandPOST /flow/{id}/submit(ADR 084), by exact path. The check now reads both spellings, so it keeps covering the widget once it calls/cloud/zitadel/api/v1/…(feat!: call the API under /api/v1 #2359). A doubled or other prefix is no flow write; the server answers neither.assertNoUnreviewedProjectSecretProxy) now accepts only the exact guard: the POST check, one or both exchange paths, and the no-overwrite check, in any order. The old substring tests acceptedpathname === "/sessions/exchange" || true; such a guard is now flagged for manual review.POST /api/v1/sessions/exchangebefore its app upgrades.Validation
main(see Notes) and stacking on docs: amend and accept ADR 077 on the /api/v1 prefix #2356, at 21b537f:moon run sdk-core:typecheck sdk-core:lint sdk-core:test cli:typecheck cli:lint cli:test sdk-next:test sdk-nuxt:test sdk-qwik-router:test sdk-solid-start:test sdk-sveltekit:test sdk-tanstack-start:test: pass, exceptcli:test's two suites that run the generated proxies against a remote https server, whose setup hook timed out under the load; alone they pass (120 tests).moon run cloud-functions:typecheck cloud-functions:test cloud-functions:lint: pass.moon run sdk-core:test: 378 passed, including the new rows for both spellings.moon run sdk-core:lint sdk-core:typecheck api:lint api:typecheck cli:lint cli:typecheck docs:lint: pass.vitest run tests/unit/lib/orca/patchers/rule/vite-support.test.ts tests/unit/lib/orca/patchers/rule/angular/index.test.ts tests/unit/commands/doctor/checks.test.ts(inapps/cli): 204 passed. They include the generated proxies run by Vite against a remote https server, attaching the secret to/__nextgen/api/v1/sessions/exchangeand to nothing else, and a doctor run that warns on a v2proxy.conf.cjsuntil--fixmigrates it.moon run cli:teston this branch alone: 4319 passed.moon run sdk-next:test sdk-nuxt:test sdk-sveltekit:test sdk-solid-start:test sdk-qwik-router:test sdk-tanstack-start:teston this branch alone: pass (248, 228, 129, 130, 129, 151).Release notes / changeset
.changeset/api-v1-path-gates.md—@zitadel/api,@zitadel/cli,@zitadel/sdk-coreminor: the SDK proxies and the scaffolded SPA dev proxies recognise the session calls under/api/v1;zitadel doctorwarns about an older dev proxy anddoctor --fixupdates it; a hand-written SPA production proxy should accept both paths.Notes
@zitadel/api'sAPI_PREFIX: the CLI names the prefixed exchange once (PREFIXED_EXCHANGE_PATH) for its guard, its doctor verdicts and their messages, and the cloud functions importAPI_PREFIX, with@zitadel/apias a dependency built ahead of theirs in moon and turbo and their tests reading its source. Checked:moon run cloud-functions:lint cloud-functions:typecheck cloud-functions:test cloud-functions:build cli:typecheck cli:lintand the three patcher and doctor test files (232 tests).mainis merged in once, to resolve conflicts with ADR 083's session cookies (main's build(deploy): create preview databases as postgres so the cleanup can drop them #2484 and before). The Vite and Angular session-cookie edits take both migrations:mainreplaces the hooks from before ADR 083, and this PR finds the CLI's entry by either version of its bearer hook. doctor's tests keep this PR's v2-proxy test besidemain's two, and sdk-core's tests for the prefixed probe, sign-in and sign-out use ADR 083's cookie names.apps/cli/skills/zitadel-cli/SKILL.mddescribes no dev-proxy wiring or doctor warnings, so nothing there changes; the doctor's own message saysdoctor --fixapplies the edit.🤖 Generated with Claude Code