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

Signup resists bots and floods: a human check and rate limits #891

Closed opened this in answer to
Closed without merging

Signup now needs a Turnstile token checked on the server, and signup, sign-in and an edge's first sight are rate limited per source and for the whole forge. tsc --noEmit is clean and the new test/signup-guard.test.ts passes (6 tests).

Notes

stopped closed without shipping deploy 5432a10

opened this

Signup now needs a Turnstile token checked on the server, and signup, sign-in and an edge's first sight are rate limited per source and for the whole forge.

tsc --noEmit is clean and the new test/signup-guard.test.ts passes (6 tests). test/api-errors.test.ts passes too (the user-creation route it exercises was changed). I did not get a full bun test run to finish: it timed out in this environment. Run bun scripts/test-shards.ts --gate (what forge.json runs as check) to confirm the rest of the suite.

What changed

  • Human check: src/core/humancheck.ts verifies a Turnstile token server-side before an account is made. It applies at /signup and at POST /api/v1/users, where the token is the humanToken field. A missing, oversized or rejected token, or an unreachable verifier, refuses the signup.
  • Rate limits: src/http/doors.ts keeps one limiter per door, checking the forge-wide window first and then the per-source one.
    • Keys and message: Limits are keyed on the socket client (peer.ts), never on a header. Over the limit gives a 429 with Retry-After and "Too many attempts. Try again in N seconds."
    • Defaults (knocks per minute): signup 20 per source and 300 forge-wide, sign-in 60 and 200, edge first sight 20 and 300. A separate per-account guess limit allows 20 per account and 200 forge-wide.
    • Overrides: Tests override them through doorLimits.
  • Configuration: FORGE_TURNSTILE_SITE_KEY and FORGE_TURNSTILE_SECRET turn the check on. Setting only one of them fails the boot. With neither set, no human check is asked for. The README covers this.
  • Tests: The new tests cover a signup without a valid token being refused, rapid signups and sign-ins from one source being throttled, a forged forwarding header not changing the key, and the widget appearing on the page.

Left out

  • The human check is signup-only. Sign-in is rate limited but has no challenge.
  • No CAPTCHA fallback other than Turnstile.
  • Limiter state is in memory, so it resets on restart.

Try it Set the two Turnstile variables and open /signup. Without them, hit /signup more than 20 times a minute from one address to see the 429.

Closes #661

commented

Parked by the crew: the check failed ("an app gets its own domain > (unnamed)") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs