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

Signup is rate-limited per source and per forge, set on /admin/limits like sign-in #2294

Parked opened this
Closed without merging

Signup is now rate-limited per source and per forge, with both limits set on /admin/limits. I merged main into the branch to clear the conflict in src/tui/screens/signin.ts. What conflicted: main added SIGNUPCLOSEDMESSAGE and signupClosed to the sign-in screen's import from actions/users.ts.

Notes

stopped parked by the crew deploy 939193f

opened this

Signup is now rate-limited per source and per forge, with both limits set on /admin/limits. I merged main into the branch to clear the conflict in src/tui/screens/signin.ts.

  • What conflicted: main added SIGNUP_CLOSED_MESSAGE and signupClosed to the sign-in screen's import from actions/users.ts. This branch had added the rate-limit imports from http/signup-limit.ts. I kept both.
  • One test changed: after the merge, signup closed (#2166) › "switching back to open takes effect on the next request" got a 429 instead of a 201. That suite makes many signup attempts from one address, so it hit the default limit of 5 per source per minute. The test was wrong, not the code. I set signup.per_source to 1,000 and signup.per_forge to 100,000 in that suite's beforeAll in test/signup.test.ts. The dedicated limiter tests are unchanged.
  • What I ran: bun x tsc --noEmit is clean, and test/signup.test.ts plus test/signup-limit.test.ts pass (18 tests). I did not run the full bun test here. The first attempt ran past the 120-second command timeout and I stopped waiting for it, so the forge's check covers the rest.

To try it: lower signup.per_source on /admin/limits, then make that many sign-up attempts from one address within a minute. The next attempt is refused with a "Too many signups. Try again in N seconds." message.

Continues #2294

3 earlier comments
commented

Signup now goes through signupAllowed(ctx) with two windows, per source and per forge. The new test file and test/app-domains.test.ts pass, and so does test/capacity.test.ts once FORGE_CHECK_SHARDS is unset (see below). The type check is clean.

What changed

  • New module: src/http/signup-limit.ts holds the throttle. It has its own limiter per forge, and the window logic is the same as sign-in's.
  • Limits: signup.per_source (default 5 a minute) and signup.per_forge (default 60 a minute) are in src/settings/limits.ts, so they show on /admin/limits.
  • Source: the socket's peer address, taken from clientAddress, and an IPv6 address counts as its whole /64. clientAddress honours X-Forwarded-For only from a trusted proxy, and loopback counts as trusted when FORGE_TRUSTED_PROXIES is unset. That rule was already there and I did not change it.
  • Per-source key: the source plus the route, so another route from the same source has its own budget. That also means passkey signup's options step and its create step each get their own budget.
  • Doors covered: the signup form, POST /api/v1/users, both passkey signup routes, and the terminal signup screen. The passkey routes used to share sign-in's limiter and no longer do.
  • When throttled: the form re-renders with 429, a "Try again in N seconds" message and retry-after. The API and the passkey routes answer 429 with retry-after and a JSON rate_limited error. The terminal shows the message.
  • Test: test/signup-limit.test.ts is gated automatically, because the gate is every test file except the excluded ones. It covers:
    • the defaults;
    • the API throttled after 5 attempts with retry-after;
    • the form's 429 page;
    • a different route from the same source not throttled;
    • the per-forge window holding across sources.

Test results

  • bun test test/app-domains.test.ts test/capacity.test.ts: 24 pass, 0 fail, 252 expects.
  • In my sandbox, FORGE_CHECK_SHARDS=4 is set in the environment, and one capacity test failed with it. It also fails on a tree without my change; with the variable unset it passes.
  • test/limits.test.ts, test/passkeys.test.ts, test/forge-signin.test.ts and the new file also pass.

Left out

  • The edge-login door (ensureEdgeUser) is not throttled, because the platform edge has already signed that person in.
  • Spawned-forge, claim and crew account creation are not throttled either, because they are not open signup.
commented

Signup is now rate-limited per source and per forge, with both limits set on /admin/limits. I merged main into the branch to clear the conflict in src/tui/screens/signin.ts.

  • What conflicted: main added SIGNUP_CLOSED_MESSAGE and signupClosed to the sign-in screen's import from actions/users.ts. This branch had added the rate-limit imports from http/signup-limit.ts. I kept both.
  • One test changed: after the merge, signup closed (#2166) › "switching back to open takes effect on the next request" got a 429 instead of a 201. That suite makes many signup attempts from one address, so it hit the default limit of 5 per source per minute. The test was wrong, not the code. I set signup.per_source to 1,000 and signup.per_forge to 100,000 in that suite's beforeAll in test/signup.test.ts. The dedicated limiter tests are unchanged.
  • What I ran: bun x tsc --noEmit is clean, and test/signup.test.ts plus test/signup-limit.test.ts pass (18 tests). I did not run the full bun test here. The first attempt ran past the 120-second command timeout and I stopped waiting for it, so the forge's check covers the rest.

To try it: lower signup.per_source on /admin/limits, then make that many sign-up attempts from one address within a minute. The next attempt is refused with a "Too many signups. Try again in N seconds." message.

commented

The branch is already pushed and merges cleanly with main, so I made no changes this run. Issue #2277 has no new comments.

What changed

  • Throttle: src/http/signup-limit.ts adds signupAllowed(ctx) with a per-source window and a per-forge window. The source is the socket's peer address. I have not re-run the tests since the previous run.
  • Limits: signup.per_source (default 5 a minute) and signup.per_forge (default 60 a minute) are in src/settings/limits.ts, so they show on /admin/limits.
  • Doors covered: the signup form, POST /api/v1/users, both passkey signup routes, and the terminal signup screen. The passkey routes used to share sign-in's limiter and no longer do.
  • When throttled: the form re-renders with 429, a "Try again in N seconds" message and retry-after. The API and the passkey routes answer 429 with retry-after and a rate_limited error. The terminal shows the message.
  • Test: test/signup-limit.test.ts is gated automatically, because the gate is every test file except the excluded ones. It covers:
    • the defaults;
    • the API throttled after 5 attempts with retry-after;
    • the form's 429 page;
    • a different route from the same source not throttled;
    • the per-forge window holding across sources.

Test results

  • bun test test/app-domains.test.ts test/capacity.test.ts gave 24 pass, 0 fail, 252 expects. This needs FORGE_CHECK_SHARDS unset: the sandbox sets it to 4, and one capacity test then fails, with or without this change.
  • The new test file and test/limits.test.ts, test/passkeys.test.ts, test/forge-signin.test.ts also pass, and the type check is clean.

Left out

  • Edge login: the platform edge has already signed that person in, so it is not throttled.
  • Account creation that isn't open signup: spawned-forge, claim and crew account creation are not throttled.
  • Client headers: clientAddress honours X-Forwarded-For from a trusted proxy, and loopback counts as trusted when FORGE_TRUSTED_PROXIES is unset. That rule was already there and I did not change it.
  • Per-route budgets: the per-source budget is per route, so passkey signup's options step and its create step each get their own.
commented

Parked by the crew: the check failed ("verified email > re-sending is rate limited") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs