Skip to content

fix(auth): stop bots abusing sign-up and password-reset emails - #718

Closed
fclairamb wants to merge 7 commits into
mainfrom
fix/signup-bot-protection
Closed

fclairamb wants to merge 7 commits into
mainfrom
fix/signup-bot-protection

Conversation

@fclairamb

@fclairamb fclairamb commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Cause

Since 2026-10-12 a bot has been using the public sign-up and forgot-password forms to make the server email third parties ("subscription bombing"): about 200 pending registrations for distinct webmail addresses, while real sign-ups stayed around 8 a week. The server logs show the same sequence for every one, within about 3 s, from a JS-running browser: load /d/forgot-password, POST /auth/request-password-reset, load /d/orgs/default/register, POST /auth/register about 1 s after the page loaded. Nobody fills a name, an email and a password that fast. The request log line had no client IP or user agent, so the source could not be traced.

Separately, the confirm-registration page spent the one-shot token in a useEffect on load, so mail link scanners that run JavaScript could burn it before the human clicked, leaving them on "Confirmation failed".

Fix

Form guard (auth.form_guard, enabled by default in every mode)

  • GET /api/v1/auth/form-ticket?form=register|password-reset returns a signed, single-use ticket: a JWT whose key is derived from the JWT secret for the form-ticket purpose (it can never verify as a session token), carrying the form, the issue time in ms and a random ID. The dashboard fetches it when the form renders and sends it back as formTicket.
  • Register and request-password-reset drop a submission with no ticket, a forged, expired, reused (single use through BumpGlobalCounter with a limit of 1) or other-form ticket, a ticket younger than min_fill_time (3 s), or a filled website honeypot (off-screen, tabindex=-1, autocomplete=off, aria-hidden, password-manager opt-outs).
  • Hourly budgets per form: 12 per client IP (answers 429, like the existing per-minute reset limit) and 3 emails per address (silent). For sign-up the IP budget counts only registrations still pending: the client IP is kept in the pending entry, confirmation deletes it and frees the slot, and the address being signed up again is left out of the count. So 20 colleagues behind one NAT get through as long as they confirm. Password reset counts every request.
  • A dropped submission gets exactly the success response (same status, same body; sign-up also spends the same filler hash as the taken-email branch, so timing does not tell either), sends nothing, is logged at INFO with its reason and IP (never the address), and is counted in solidping_auth_form_dropped_total{form,reason}.
  • Hard rejections a real visitor needs (registration disabled, email pattern, short password) are unchanged and still come first.
  • Settings: SP_AUTH_FORM_GUARD_ENABLED (true), _MIN_FILL_TIME (3s, 0s in test run mode unless set, so Playwright keeps passing while the ticket stays required), _TICKET_TTL (24h), _PER_IP_PER_HOUR (12), _PER_EMAIL_PER_HOUR (3). 0 turns a budget off.

Client IP

  • The reset per-minute IP limit used ExtractRemoteAddr (trusts X-Forwarded-For blindly), so it could be dodged with a fresh header per request. It now uses ExtractTrustedClientIP with SP_SERVER_RATE_LIMITING_TRUSTED_PROXIES, like the new budgets.
  • The HTTP request log line now carries ip (same trusted-proxy rule) and userAgent (truncated to 256 chars).

Clients

  • dash0 register and forgot-password send the ticket and the honeypot. Forgot-password waits out the ticket's minimum age before submitting, because its email is often pre-filled from the login page and it only ever emails existing accounts. Sign-up does not wait, so the server-side minimum stays meaningful there.
  • sp auth register / sp auth request-password-reset fetch a ticket before prompting and wait out minAgeMs. Against an older server without the endpoint, they send the request as before.
  • OpenAPI: new getFormTicket, formTicket / website on both request bodies, 429 documented on register; pkg/client regenerated.

Confirm page

  • confirm-registration/$token now shows a "Confirm my account" button (confirm-registration-button) and spends the token only on click. The ref-based double-call guard is kept (now guarding double clicks). New strings in en, fr, de, es.

Docs: a "Sign-Up and Password-Reset Forms Are Guarded" section in web/docs/docs/configuration/security.md (with the env table checked by TestDocumentedDefaultsMatchCode), and an Unreleased CHANGELOG entry.

Verification

  • Go, table-driven, with a positive control after every "nothing sent" assertion (internal/handlers/auth/form_guard_test.go): for both forms, a valid aged ticket is sent; too fast, honeypot, missing, garbage, forged with another secret, expired and other-form tickets each answer the success response, store nothing and queue no email, then the same address with a valid ticket is sent. Single use (the replay is dropped, the first use is sent). Per-email budget through the real handlers: over budget the status and body are identical to a sent one, and another address is still sent. Per-IP budget: 429 past it, a forged X-Forwarded-For does not reset it, another client is unaffected. Reset per-minute limit ignores a forged X-Forwarded-For. GET /form-ticket (200, Cache-Control: no-store, 422 on an unknown form).
  • internal/app/request_log_test.go: ip with no trusted proxy (forged header ignored) and with one, userAgent truncation, error only on failure.
  • internal/config/form_guard_test.go: defaults, env binding (0, garbage), test run mode.
  • test/integration: register through the real router and generated client, without a ticket (dropped) then with a fetched, aged one (sent).
  • dash0 unit (vitest): confirm page does not call confirm on load (then the click does, once, even on a double click; error shown), formTicketDelayMs; locale parity.
  • Playwright on a local side-car (SQLite, port 4317): new form-guard.spec.ts (ticket and empty honeypot sent, honeypot out of tab order and aria-hidden, forgot-password waits then succeeds, confirm spends nothing on load), confirm-registration-no-org.spec.ts (now clicks the button; the queued email proves dash0 sends a valid ticket), electric-identity-auth, login, email-language, membership-requests: all green. Also against a side-car with SP_AUTH_FORM_GUARD_MIN_FILL_TIME=3s: a ticket used at once, a filled honeypot and a replay are dropped with the same 200, an aged ticket is sent.
  • golangci-lint run ./...: 0 issues. make test: green. bun run lint:e2e, typecheck:e2e, tsc -p tsconfig.app.json: clean; no lint error in the touched files (the three files' testid suppressions are pruned).
  • Not run: make test-postgres (CI), the full Playwright suite (CI), and make lint-migrations locally (the script needs bash 4; no migration is touched).

Notes

  • A real visitor who autofills the whole sign-up form and submits within 3 s would be dropped silently. That trade-off is deliberate (the server's check is what stops the bot); forgot-password, where pre-filled instant submits are normal, waits client-side instead.
  • A third-party script calling POST /auth/register or /auth/request-password-reset directly now needs a ticket; the docs and the OpenAPI description say how. SP_AUTH_FORM_GUARD_ENABLED=false restores the previous behavior (the budgets still apply).

🤖 Generated with Claude Code

A bot has been submitting the public sign-up and forgot-password forms
about one second after loading them, making the server email third
parties. The forms are now guarded, and nothing a dropped submission
gets back tells it apart from a success.

- Form ticket: GET /api/v1/auth/form-ticket returns a single-use JWT
  (key derived from the JWT secret for the "form-ticket" purpose) with
  the issue time in ms. Register and request-password-reset drop a
  submission with no ticket, a forged, expired, reused or other-form
  ticket, one younger than auth.form_guard.min_fill_time (3s; 0 in test
  run mode unless set), or a filled "website" honeypot.
- Budgets per form: 12 submissions per client IP per hour (429) and 3
  emails per address per hour (silent), via BumpGlobalCounter.
- Drops answer exactly like a success, send no email, log at INFO and
  count in solidping_auth_form_dropped_total{form,reason}.
- The password-reset per-minute IP limit uses the trusted-proxy IP
  instead of a raw X-Forwarded-For.
- The HTTP request log line carries the client IP (trusted-proxy rule)
  and the user agent.
- dash0 sends the ticket and a hidden honeypot; forgot-password waits
  out the ticket's minimum age (its email is often pre-filled).
- The confirm-registration page confirms on a "Confirm my account"
  click, not on load, so mail link scanners cannot burn the token.
- sp auth register / request-password-reset fetch a ticket and wait.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.42932% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.81%. Comparing base (8344a9d) to head (39af9b4).

Files with missing lines Patch % Lines
server/internal/handlers/auth/service.go 96.61% 2 Missing ⚠️
server/pkg/cli/auth_selfservice.go 93.75% 2 Missing ⚠️
server/internal/handlers/auth/form_guard.go 98.82% 1 Missing ⚠️
server/internal/handlers/auth/handler.go 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #718      +/-   ##
==========================================
+ Coverage   89.74%   89.81%   +0.06%     
==========================================
  Files        1297     1301       +4     
  Lines      132288   132604     +316     
==========================================
+ Hits       118728   119103     +375     
+ Misses      13551    13492      -59     
  Partials        9        9              
Files with missing lines Coverage Δ
server/internal/app/request_log.go 100.00% <100.00%> (ø)
server/internal/app/server.go 91.99% <100.00%> (-0.03%) ⬇️
server/internal/config/config.go 94.06% <100.00%> (+0.01%) ⬆️
server/internal/config/envvars.go 100.00% <100.00%> (ø)
server/internal/config/form_guard.go 100.00% <100.00%> (ø)
server/internal/handlers/auth/join_policy.go 87.46% <100.00%> (+0.07%) ⬆️
server/internal/handlers/auth/personal_org.go 100.00% <100.00%> (ø)
...rver/internal/handlers/auth/post_login_redirect.go 100.00% <100.00%> (ø)
server/internal/handlers/testapi/users.go 92.50% <100.00%> (+3.21%) ⬆️
server/internal/oauth/authorize.go 80.00% <100.00%> (+2.55%) ⬆️
... and 6 more

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

fclairamb and others added 2 commits October 30, 2026 17:57
A team signing up from one office shares one IP. Counting every
submission would block the 13th colleague within the hour. The sign-up
budget now counts the pending registrations created from that IP in the
last hour: confirming deletes the entry and frees its slot, and signing
the same address up again does not take a second one. Password reset
keeps counting every request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fclairamb

Copy link
Copy Markdown
Owner Author

Superseded by a minimal version: per-IP cap on unconfirmed sign-ups, see the new PR on branch fix/signup-pending-per-ip.

fclairamb added a commit that referenced this pull request Oct 31, 2026
…minute) (#727)

Replaces #718 with the minimal version: per-IP limits on sign-ups, as
one server setting, on by default in SaaS mode only.

## Cause

A bot uses the public sign-up form to make the server email third-party
addresses (about 200 pending registrations since 2026-10-12, while real
sign-ups stay around 8 a week).

## Fix

- **Setting:** `auth.registration_max_pending_per_ip` (env
`SP_AUTH_REGISTRATION_MAX_PENDING_PER_IP`, also a system parameter
applied at startup).
- Default **10 in SaaS mode** (`SP_DEPLOYMENT_MODE=saas`), **0 (off)
otherwise**. An env or config-file value wins over the mode default.
- Off in test run mode unless the variable is set, because the
Playwright suites leave many sign-ups unconfirmed from one address.
- Prod and dev run in SaaS mode with `TRUSTED_PROXIES=1`, so both get it
with no extra setting.
- **Once a minute:** while the limit is on, one client IP may sign up at
most once a minute. A second request answers `429 RATE_LIMITED` with
`Retry-After: 60` and sends nothing. This also caps re-sends to an
address that is already pending.
- The counter (`registration_ip_rl:<ip>`) is bumped atomically by the
database, so a parallel burst lets one request through on any replica.
- **Unconfirmed per day:** the pending registration now keeps the client
IP. An IP with that many pending registrations written in the last 24
hours gets `429 RATE_LIMITED`, without `Retry-After`.
- Confirming deletes the entry and frees the slot, so colleagues behind
one NAT get through as long as they confirm.
- Signing up again for an address already pending rewrites its entry and
is not counted against itself.
- **No enumeration oracle:** both checks run before the taken-email
branch, and a taken email spends the minute like a real sign-up.
- **Client IP:** taken with `ExtractTrustedClientIP` and
`SP_SERVER_RATE_LIMITING_TRUSTED_PROXIES`, so a forged `X-Forwarded-For`
does not get a fresh budget.
- **dash0:** the register page tells the two 429s apart by `Retry-After`
and shows a translated message for each (en, fr, de, es).
- **API:** OpenAPI documents the 429 on `register`; `pkg/client`
regenerated.
- **Docs:** "Limiting Unconfirmed Sign-Ups per IP" in
`configuration/authentication.md`, a row in `configuration/index.md`,
and `wiki/api-specification/auth.md`.

## Verification

- `internal/handlers/auth/registration_ip_limit_test.go`:
- Pending cap: over it, no entry and no email. Positive controls:
another IP, re-registering a pending address, and confirming one freeing
a slot.
- Once a minute: a second sign-up, and a re-send, are refused with
nothing sent. Another IP passes, and the same IP passes a minute later.
- A taken email spends the minute, and an IP over the cap is refused for
taken and free addresses alike.
  - A pending entry older than 24 h no longer counts.
  - Limit `0` or no client IP: back-to-back sign-ups all pass.
  - A parallel burst of 6 stores exactly 1.
- Through the HTTP handler: `429` with `Retry-After: 60` within the
minute, `429` without it for the pending cap, a forged `X-Forwarded-For`
ignored, the port stripped, another client sent.
- `internal/config/registration_limit_test.go`, through `Load`:
self-hosted off, SaaS 10, test mode off even in SaaS, explicit value
wins (also in test mode), garbage and negative values ignored, a
config-file value kept over the mode default.
- `internal/systemconfig`: `ApplyFunc` coercion and
`TestAuthEnvVarsDocumented`.
- `go test -short ./...`: green.
- `golangci-lint run ./...`: 0 issues.
- dash0: `tsc -p tsconfig.app.json` clean, locale parity tests green.
- Not run: `make test-postgres` and Playwright (CI). No e2e spec for the
429s: the CI server runs in test mode with the limits off.

## Notes

- `make dev-saas` (SaaS mode, not test run mode) now has the limits on:
a developer trying sign-ups in a loop there hits the once-a-minute
limit. `SP_AUTH_REGISTRATION_MAX_PENDING_PER_IP=0` in `dev.priv.env`
turns it off.
- Not covered: a bot that rotates IPs, a per-address cap across IPs, and
the password-reset form.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant