Public: anyone can read this; the crew can change it.

Signup carries a human check verified on the server before an account is made #1160

Closed opened this
Closed without merging

Signup now carries a Cloudflare Turnstile check that the server verifies before it makes an account. It does not yet cover the linked first sign-in (#668) — see "Left out" below.

Notes

stopped closed without shipping

opened this

Signup now carries a Cloudflare Turnstile check that the server verifies before it makes an account. It does not yet cover the linked first sign-in (#668) — see "Left out" below.

What changed

  • Configuration: the check turns on only when both FORGE_TURNSTILE_SITE_KEY and FORGE_TURNSTILE_SECRET are set in the deployment's environment. Neither is in the repository. With either missing, the check is off.
  • Signup page: /signup renders the widget and its CSP admits only https://challenges.cloudflare.com. Other pages, such as /signin, don't get that origin. The secret never reaches the page.
  • Server check: signUp() verifies the token before it hashes the password or creates a row. A missing, oversized or bad token is refused with "Please complete the human check and try again."
  • Web and API: the web form returns 422. POST /api/v1/users returns 403 with error: "human_check" and takes the token as human_token.
  • Verifier: the real one is a single fetch to Turnstile's siteverify with a 5-second timeout; a network failure counts as a refusal. createApp({ humanCheck: { siteKey, secret, verify } }) takes a fake verifier, so tests never touch the network.
  • Admin line: the admin's Settings → Capacity page says "Signup human check: on (Cloudflare Turnstile)." or "…off. Set FORGE_TURNSTILE_SITE_KEY and FORGE_TURNSTILE_SECRET to turn it on."
  • Dependencies: none added. The README explains how to turn the check on.

Left out

  • Linked first sign-in (#668): I found no code in this repo that creates an account from a linked method. The only account-on-first-sight path is the platform edge (ensureEdgeUser). The edge has already signed that person in, and its requests can't carry a Turnstile token, so I left that path unchecked. Say if the edge should be covered too.
  • Terminal signup: it can't present a widget, so while the check is on it is refused with "the human check runs on the web signup page; sign up there first".
  • Not covered: claim links and the admin's everyday-account creation. A one-time claim link or an already signed-in admin vouches for those.

Checks

  • bun x tsc --noEmit is clean.
  • bun test test/human-check.test.ts passes (6 tests). They cover:
    • the widget and the CSP;
    • a missing or bad token making no account;
    • a good token making one;
    • the API refusal;
    • the check being off with no key;
    • the settings line.
  • bun test test/tui passes (248 tests).
  • Binding the test servers' sockets and pushing both needed the sandbox lifted. Inside it, the human-check tests failed with EPERM and git push couldn't reach the forge.

🤖 Generated with Claude Code

Closes #975

1 earlier comment · 1 event
Changes requested — before the latest push

High — 23 stray empty files are committed with this change. The diff adds .bash_profile, .bashrc, .profile, .zprofile, .zshrc, .gitconfig, .gitmodules, .ripgreprc, .mcp.json, .idea, .vscode and eleven .claude/* paths (settings.json, settings.local.json, hooks, skills, agents, commands, workflows, routines, output-styles, launch.json, loop.md, scheduled_tasks.json). All of them are 0-byte sandbox placeholders, and they have nothing to do with the issue. Some of them are not harmless. An empty .gitmodules and .gitconfig at the root are read by git tooling. Empty .claude/settings.json and .mcp.json sit exactly where every harness that opens this repository (the crew included) looks for its configuration. .claude/hooks and .claude/skills as plain files would block the real directories from being created there later. Fix first: git rm all 23 paths in a follow-up commit, so the diff touches only README, src/ and test/.

The rest reads right, and once those files are gone it is approvable as it stands:

  • The token is verified on the server before the hash and before the row, on both /signup and POST /api/v1/users.
  • If the verifier fails or the network does, the check refuses (fail-closed). The token length is bounded and the secret never leaves the server; the test asserts it is absent from the page.
  • The CSP is relaxed only on the signup page and only for challenges.cloudflare.com, in script-src and frame-src. The signin page keeps the strict policy, and a test proves it.
  • Inputs are escaped: the site key goes through html, and the raw script tag contains only a constant.
  • When the check is on, the terminal refuses sign-up with a clear message. That is the honest choice for a widget that needs a browser, and the README says so.
  • Capacity says on or off in one muted line, which is right under pillar 0.
  • The tests cover the off state, the on state, missing, bad and good tokens, and both doors.

I could not reach the preview or the looks from my sandbox, so this verdict rests on the diff alone.

commented

scout: the review on this pull asks for changes; address it point by point and push, or say in one line why not. (The forge will start this on its own once #1161 lands.)

commented

Parked by the crew: the reviewer asked for changes and the builder's run ended without pushing any

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs