Skip to content

build(deploy): mark the sign-in widget's /api/v1 flow writes for BotID, and check them in production - #2625

Closed
fforootd wants to merge 1 commit into
mainfrom
claude/botid-console-signup-7ef0d8
Closed

fforootd wants to merge 1 commit into
mainfrom
claude/botid-console-signup-7ef0d8

Conversation

@fforootd

@fforootd fforootd commented Nov 2, 2026

Copy link
Copy Markdown
Member

Context

  • Refs ADR 084 §5 and §9 step 2 (BotID on the cloud's sign-in and sign-up).

Summary

  • Fixes sign-in and sign-up on every cloud preview. Since feat!: call the API under /api/v1 #2359 the sign-in widget calls /cloud/zitadel/api/v1/flow…, but BotID's client still protected /cloud/zitadel/flow…. The client never marked the widget's flow writes, so the functions' checkBotId() read each one as a bot and answered 403 auth.bot_suspected. A preview showed "This browser could not be verified" before the form loaded.
  • FLOW_WRITES and SIGN_IN_PREFIX now live in @zitadel/cloud-functions/contract. The paths are built with apiBaseUrl(), the same function the widget's API client uses, so they can't drift from what the widget sends. The add-on's bot-check.ts and index.ts and the functions' sign-in.ts read them from there. sign-in.spec.ts checks that every path BotID's client marks is one the functions check.
  • Turns BotID on in production. The production add-on now starts BotID's client and sends the widget through /cloud/zitadel, as previews do. Local builds keep the hop without the client, since only a Vercel deployment serves the challenge.
  • ADR 084 §9 and the cloud runbook's console row now say so.

Validation

  • moon run cloud-console:typecheck cloud-console:lint cloud-console:test cloud-functions:typecheck cloud-functions:lint cloud-functions:test: all pass (18 and 69 tests).
  • VERCEL_ENV=production CONSOLE_BASE_PATH=/console/ CONSOLE_ADDON=../cloud-console vite build in apps/console: the production bundle includes BotID's client and the /cloud/zitadel base.
  • Real browser on this PR's preview (cloud-git-claude-botid-console-signup-7ef0d8-zitadel.vercel.app): the challenge …/a-4-a/c.js loads (200). On /console/signup, POST /cloud/zitadel/api/v1/flow returns 201, and submitting the email step (…/flow/{id}/submit) returns 200 and shows the password step. /console/login starts its flow with 201. On main's preview, the same page got 403 auth.bot_suspected with no challenge request.
  • Production's check already refuses a script: curl -X POST https://preview.zitadel.com/cloud/zitadel/flow -d '{}' returns 403 auth.bot_suspected. A preview can't show this with vercel curl, because its protection bypass gets through.

Release notes / changeset

  • No changeset required — no shipped behavior changed. The add-on and the functions belong to the hosted cloud only.

Notes

  • A bad verdict is still a hard 403 until the server reads ADR 019's risk signal (ADR 084 §5). That means a false positive blocks a real person in production. Only basic checks are on.
  • This covers the console's path only. POST /api/v1/flow straight to the server has no BotID check, so a script can skip the console. The signed risk signal of ADR 019 is what would close that.
  • A deployment's own hash URL (cloud-<hash>-zitadel.vercel.app) is not an origin of the console's project, so its flow submit answers 403 "not an origin of this project". Test on the branch alias instead.

🤖 Generated with Claude Code

…D, and check them in production

Since the widget calls the API under /api/v1 (#2359), BotID's client
protected /cloud/zitadel/flow while the widget sent
/cloud/zitadel/api/v1/flow. The functions' check read the unmarked write
as a bot, so every sign-in and sign-up on a preview answered 403
auth.bot_suspected. The protected paths now come from the contract,
built with the base URL the widget's API client uses.

Production's add-on now starts BotID's client and sends the widget
through the functions too (root ADR 084 §5, §9 step 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 22:02
@vercel

vercel Bot commented Nov 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 Nov 2, 2026 10:02pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-11-02T22:04:53.721870Z 801333e 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 Nov 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ No Changeset found

Latest commit: 801333e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

// never marks is refused for every person.
it.each(FLOW_WRITES)("checks $method $path, which BotID's client marks", ({ method, path }) => {
expect(path.startsWith(`${SIGN_IN_PREFIX}/`)).toBe(true);
const sent = path.slice(SIGN_IN_PREFIX.length).replace("*", "flw_1");

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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🔵 Needs a closer look

This change introduces production BotID enforcement in critical authentication flows, where false positives could block real users, so a human-reviewed rollout plan with monitoring and failure-mode handling is needed before merging.

No open issues 🎉

What changed in this PR

This pull request aligns the hosted cloud console’s sign-in/sign-up widget routing with BotID-protected /api/v1 flow writes (preventing false auth.bot_suspected 403s), centralizes the relevant path contract to avoid drift, and enables the same BotID-backed routing behavior in production (not only previews), with corresponding ADR/runbook updates.

Changes:

  • Centralizes SIGN_IN_PREFIX and FLOW_WRITES in @zitadel/cloud-functions/contract using apiBaseUrl() to keep BotID marking in sync with the widget client.
  • Updates cloud-functions sign-in forwarding and adds tests to ensure BotID-marked paths match isFlowWrite() checks.
  • Updates the cloud console add-on to start the BotID client in production and route widget traffic consistently via /cloud/zitadel, plus documentation updates.

Review notes (nit):

  • apps/cloud-functions/src/contract.ts: Header comment claims everything is beneath /cloud/api/, but this contract also defines /cloud/zitadel paths (SIGN_IN_PREFIX / FLOW_WRITES), making the comment misleading.
File Summary
docs/​runbooks/​cloud.md Updates the cloud runbook to reflect BotID-enabled routing behavior beyond previews.
docs/​adrs/​084-hosted-cloud-business-systems.md Updates ADR 084 wording/rollout notes to reflect production behavior for the sign-in hop and BotID.
apps/​cloud-functions/​src/​sign-in.ts Switches to importing SIGN_IN_PREFIX from the shared contract while keeping forwarding/flow-write logic.
apps/​cloud-functions/​src/​sign-in.spec.ts Adds a contract-based test asserting BotID-marked paths are recognized by isFlowWrite().
apps/​cloud-functions/​src/​contract.ts Introduces shared SIGN_IN_PREFIX and FLOW_WRITES derived via apiBaseUrl() for drift-resistant config.
apps/​cloud-console/​src/​index.ts Uses shared SIGN_IN_PREFIX, enables BotID client startup in production, and routes widget traffic consistently through /cloud/zitadel.
apps/​cloud-console/​src/​bot-check.ts Replaces hardcoded BotID-protect paths with shared FLOW_WRITES from the contract.

Review effort: Balanced

This branch was successfully deployed

1 active deployment
Preview — 801333e4 Deployed Nov 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

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants