Skip to content

feat: accept /api/v1 paths in the SDK and dev-proxy gates - #2357

Merged
fforootd merged 6 commits into
claude/api-v1-merge-impact-506209from
claude/api-v1-path-gates
Nov 1, 2026
Merged

fforootd merged 6 commits into
claude/api-v1-merge-impact-506209from
claude/api-v1-path-gates

Conversation

@fforootd

@fforootd fforootd commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

Several places decide by the exact path /sessions/exchange or /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. requiresProjectSecret and proxySessionCookies (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/api exports API_PREFIX.
  • The dev proxies zitadel setup writes for SPAs (Vite and Angular) move to zitadel:proxy:v3: the bearer hook attaches the project secret to POST /sessions/exchange and POST /api/v1/sessions/exchange.
    • A v2 proxy is migrated by a separate convenience edit: in vite.config.* it finds the CLI's own v2 hook through the existing formatter-insensitive fingerprint, so a Prettier- or Biome-formatted config still migrates; in proxy.conf.cjs it replaces the exact managed hook. Only the hook statement and the entry's marker change.
    • zitadel doctor warns about a v2 proxy (it keeps working until the packages call the prefix) and zitadel doctor --fix migrates 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 as unknown.
    • v2 stays recognised everywhere it was: the session-cookie edit and verdict, the origin-forwarding migration, the pre-v2 legacy migration.
  • The hosted cloud's functions check BotID only in front of the sign-in widget's two flow writes, POST /flow and POST /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.
  • The credential-policy check (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 accepted pathname === "/sessions/exchange" || true; such a guard is now flagged for manual review.
  • Docs. The SDK proxy page says the proxies know both paths, and tells an SPA's hand-written production proxy to accept POST /api/v1/sessions/exchange before its app upgrades.

Validation

  • After merging 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, except cli: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.
    • The whole stack, self-hosted and on its preview: see feat!: call the API under /api/v1 #2359's Validation.
  • From before the merge:
  • 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 (in apps/cli): 204 passed. They include the generated proxies run by Vite against a remote https server, attaching the secret to /__nextgen/api/v1/sessions/exchange and to nothing else, and a doctor run that warns on a v2 proxy.conf.cjs until --fix migrates it.
  • moon run cli:test on 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:test on this branch alone: pass (248, 228, 129, 130, 129, 151).

Release notes / changeset

  • Changeset: .changeset/api-v1-path-gates.md — @zitadel/api, @zitadel/cli, @zitadel/sdk-core minor: the SDK proxies and the scaffolded SPA dev proxies recognise the session calls under /api/v1; zitadel doctor warns about an older dev proxy and doctor --fix updates it; a hand-written SPA production proxy should accept both paths.

Notes

  • After a review (2026-11-01), the prefix has one TypeScript home, @zitadel/api's API_PREFIX: the CLI names the prefixed exchange once (PREFIXED_EXCHANGE_PATH) for its guard, its doctor verdicts and their messages, and the cloud functions import API_PREFIX, with @zitadel/api as 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:lint and the three patcher and doctor test files (232 tests).
  • main is 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: main replaces 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 beside main's two, and sdk-core's tests for the prefixed probe, sign-in and sign-out use ADR 083's cookie names.
  • The plan put a new test title into the six server SDKs' shared test lists. The SDKs pass the path after their proxy prefix to sdk-core unchanged, so the property lives in sdk-core and is tested there, at the lowest layer that proves it.
  • apps/cli/skills/zitadel-cli/SKILL.md describes no dev-proxy wiring or doctor warnings, so nothing there changes; the doctor's own message says doctor --fix applies the edit.
  • The follow-up feat!: call the API under /api/v1 #2359 turns the v2 warning into a doctor failure, since from then a v2 proxy breaks sign-in.

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Oct 26, 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 Nov 1, 2026 2:52am UTC

Request Review

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: ce3a561

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

This PR includes changesets to release 24 packages
Name Type
@zitadel/api Minor
@zitadel/cli Minor
@zitadel/sdk-core Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/testing Minor
@zitadel/server Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-darwin-arm64 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

fforootd added a commit that referenced this pull request Oct 26, 2026
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>
fforootd and others added 2 commits October 31, 2026 15:19
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>
fforootd added a commit that referenced this pull request Oct 31, 2026
Stacks this PR on #2357 (the path checks that accept both spellings),
itself on #2356, so the stack's top tests the whole change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd changed the base branch from main to claude/api-v1-merge-impact-506209 October 31, 2026 22:28
fforootd added a commit that referenced this pull request Oct 31, 2026
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>
fforootd added a commit that referenced this pull request Oct 31, 2026
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>
@fforootd
fforootd added this pull request to stack #2564 October 31, 2026 22:42
@fforootd
fforootd marked this pull request as ready for review October 31, 2026 23:55
Copilot AI balanced review requested due to automatic review settings October 31, 2026 23:55
@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
🔒 Security Review ✅ Completed 2026-10-31T23:57:52.369145Z 21b537f 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.

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.

🔵 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/api exports a new API_PREFIX (/api/v1); @zitadel/sdk-core's requiresProjectSecret/proxySessionCookies and cloud-functions' isFlowWrite strip 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:v2 to v3, attaching the project secret to both POST /sessions/exchange and POST /api/v1/sessions/exchange; zitadel doctor/--fix detect 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-core minor) 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>
fforootd added a commit that referenced this pull request Nov 1, 2026
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>
fforootd added a commit that referenced this pull request Nov 1, 2026
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>
fforootd added a commit that referenced this pull request Nov 1, 2026
Brings in #2357's build edge for the cloud functions' tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fforootd added a commit that referenced this pull request Nov 1, 2026
Brings in #2357's build edge for the cloud functions' tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fforootd added a commit that referenced this pull request Nov 1, 2026
Brings in #2357's build edge for the cloud functions' tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 79d8dd0 Nov 1, 2026
23 of 25 checks passed
@fforootd
fforootd deleted the claude/api-v1-path-gates branch November 1, 2026 03:36
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Nov 1, 2026

This branch was successfully deployed

1 active deployment
Preview — ce3a5611 Deployed Nov 1, 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

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants