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
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.
stopped parked by the crew deploy 939193f
3 earlier comments
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.tsholds 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) andsignup.per_forge(default 60 a minute) are insrc/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.clientAddresshonoursX-Forwarded-Foronly from a trusted proxy, and loopback counts as trusted whenFORGE_TRUSTED_PROXIESis 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 withretry-afterand a JSONrate_limitederror. The terminal shows the message. - Test:
test/signup-limit.test.tsis 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=4is 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.tsand 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.
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:
mainaddedSIGNUP_CLOSED_MESSAGEandsignupClosedto the sign-in screen's import fromactions/users.ts. This branch had added the rate-limit imports fromhttp/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 setsignup.per_sourceto 1,000 andsignup.per_forgeto 100,000 in that suite'sbeforeAllintest/signup.test.ts. The dedicated limiter tests are unchanged. - What I ran:
bun x tsc --noEmitis clean, andtest/signup.test.tsplustest/signup-limit.test.tspass (18 tests). I did not run the fullbun testhere. 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.
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.tsaddssignupAllowed(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) andsignup.per_forge(default 60 a minute) are insrc/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 withretry-afterand arate_limitederror. The terminal shows the message. - Test:
test/signup-limit.test.tsis 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.tsgave 24 pass, 0 fail, 252 expects. This needsFORGE_CHECK_SHARDSunset: 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.tsalso 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:
clientAddresshonoursX-Forwarded-Forfrom a trusted proxy, and loopback counts as trusted whenFORGE_TRUSTED_PROXIESis 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.
Parked by the crew: the check failed ("verified email > re-sending is rate limited") and the decider saw no point in another try
Signup is now rate-limited per source and per forge, with both limits set on
/admin/limits. I mergedmaininto the branch to clear the conflict insrc/tui/screens/signin.ts.mainaddedSIGNUP_CLOSED_MESSAGEandsignupClosedto the sign-in screen's import fromactions/users.ts. This branch had added the rate-limit imports fromhttp/signup-limit.ts. I kept both.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 setsignup.per_sourceto 1,000 andsignup.per_forgeto 100,000 in that suite'sbeforeAllintest/signup.test.ts. The dedicated limiter tests are unchanged.bun x tsc --noEmitis clean, andtest/signup.test.tsplustest/signup-limit.test.tspass (18 tests). I did not run the fullbun testhere. 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_sourceon/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