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

Signup verifies a Turnstile token on the server before it makes an account, through a verifier injected on createApp #1669

Closed opened this
Closed without merging

Signup now checks a Turnstile token on the server before it hashes a password or makes an account. It only does so when a secret is configured; with no secret, signup behaves as before. Verifier: src/turnstile.ts posts the secret and token (and the client address, when known) to Cloudflare's siteverify.

Notes

stopped closed without shipping deploy e0945d5

opened this

Signup now checks a Turnstile token on the server before it hashes a password or makes an account. It only does so when a secret is configured; with no secret, signup behaves as before.

  • Verifier: src/turnstile.ts posts the secret and token (and the client address, when known) to Cloudflare's siteverify. It answers yes only on success: true. Anything else counts as no: empty or oversized token, non-200 reply, timeout (5 seconds), network error.
  • Injection: createApp takes verifyHuman. src/main.ts builds it from FORGE_TURNSTILE_SECRET; the secret never goes in the repository. Tests pass a fake, so nothing touches the network.
  • Refusal: signUp in src/actions/users.ts returns a new error, human_check_failed, before createUser runs.
    • The web form reads cf-turnstile-response, the field Turnstile's widget adds, and shows "We could not tell you are a person. Try again."
    • POST /api/v1/users reads the same key from its JSON body and returns 422 with the error code.
  • Tests: test/turnstile.test.ts is added to GATE in scripts/gate.ts in the same commit. It covers:
    • off: signup works;
    • on with a good token: account made;
    • on with no, empty or bad token: refused, and the user table has zero rows;
    • the verifier's request body, and its no on success: false, a 500, an empty token and a network error.
  • Checks run: bun x tsc --noEmit reported nothing. bun test test/turnstile.test.ts test/check-list.test.ts test/accounts.test.ts gave 33 pass, 0 fail.

Left out:

  • Widget: the signup page has no Turnstile widget, because the issue is server side only. With a secret set, web signup is refused until a later change adds it.
  • Terminal signup: it has no token to send, so it is refused too once a secret is set.
  • First account: it is not exempt from the check.

To try it, set FORGE_TURNSTILE_SECRET. Cloudflare's documented test secrets let you exercise it without a real widget.

Closes #1665

commented

Parked by the crew: the check failed ("home is the feed > On you can be cleared in one move: a box each, select all, by kind and by repository, one form") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs