Skip to content

fix(auth): limit sign-ups per client IP (unconfirmed per day, once a minute) - #727

Merged
fclairamb merged 4 commits into
mainfrom
fix/signup-pending-per-ip
Oct 31, 2026
Merged

fclairamb merged 4 commits into
mainfrom
fix/signup-pending-per-ip

Conversation

@fclairamb

@fclairamb fclairamb commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

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

A bot has been using the public sign-up form to make the server email
third-party addresses. A client IP may now have at most
`auth.registration_max_pending_per_ip` sign-ups waiting for email
confirmation, counting those submitted in the last 24 hours (default 3,
0 turns the limit off). Past it, sign-up answers 429 and sends nothing.

- The pending registration keeps the client IP, taken with the
  trusted-proxy rules (`SP_SERVER_RATE_LIMITING_TRUSTED_PROXIES`), so a
  forged X-Forwarded-For does not get a fresh budget.
- Confirming a sign-up frees its slot. Signing up again for an address
  already pending replaces its entry and is not counted against itself.
- The check runs before the taken-email branch, so an IP over its limit
  gets 429 for every address and cannot use it to find which ones have
  an account.
- Count and write are serialized, so a parallel burst cannot all pass.
- Setting: `SP_AUTH_REGISTRATION_MAX_PENDING_PER_IP`, the
  `auth.registration_max_pending_per_ip` config key and system parameter.
  Off in test run mode unless the variable is set.
- dash0 shows a translated message on 429 (en, fr, de, es). OpenAPI
  documents the 429; pkg/client regenerated.

Replaces #718.

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

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.72131% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.76%. Comparing base (2ae5575) to head (0e3b92e).

Files with missing lines Patch % Lines
...er/internal/handlers/auth/registration_ip_limit.go 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #727      +/-   ##
==========================================
- Coverage   89.79%   89.76%   -0.03%     
==========================================
  Files        1302     1304       +2     
  Lines      132534   132584      +50     
==========================================
+ Hits       119003   119019      +16     
- Misses      13522    13556      +34     
  Partials        9        9              
Files with missing lines Coverage Δ
server/internal/config/config.go 94.09% <100.00%> (+<0.01%) ⬆️
server/internal/config/envvars.go 100.00% <100.00%> (ø)
server/internal/config/registration_limit.go 100.00% <100.00%> (ø)
server/internal/handlers/auth/handler.go 90.43% <100.00%> (+0.09%) ⬆️
server/internal/handlers/auth/service.go 90.04% <100.00%> (+0.03%) ⬆️
server/internal/systemconfig/systemconfig.go 96.30% <100.00%> (+0.01%) ⬆️
...er/internal/handlers/auth/registration_ip_limit.go 90.47% <90.47%> (ø)

... and 22 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.

- `auth.registration_max_pending_per_ip` now defaults to 10 in SaaS mode
  and is off otherwise (still off in test run mode unless set). An env
  variable or config-file value wins over the mode default.
- While the limit is on, one client IP may sign up at most once a
  minute: a second request answers 429 with `Retry-After: 60` and sends
  nothing. This also caps re-sends to an address already pending. A
  taken email spends the minute like a real sign-up, so the limit is not
  an enumeration oracle.
- The minute counter is bumped atomically by the database before the
  pending count, so a parallel burst lets one request through on any
  replica; the in-process mutex is gone.
- dash0 tells the two 429s apart by Retry-After (new string in en, fr,
  de, es).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fclairamb fclairamb changed the title fix(auth): limit unconfirmed sign-ups per client IP fix(auth): limit sign-ups per client IP (unconfirmed per day, once a minute) Oct 31, 2026
fclairamb and others added 2 commits October 31, 2026 08:42
…-per-ip

# Conflicts:
#	web/docs/docs/configuration/index.md
@fclairamb
fclairamb merged commit b2eb48f into main Oct 31, 2026
56 of 58 checks passed
@fclairamb
fclairamb deleted the fix/signup-pending-per-ip branch October 31, 2026 08:25
fclairamb added a commit that referenced this pull request Oct 31, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.43.0](v0.42.1...v0.43.0)
(2026-10-31)


### Features

* auto-create a personal org for new users, resume OAuth after org
creation ([#716](#716))
([2ae5575](2ae5575))


### Bug Fixes

* **auth:** limit sign-ups per client IP (unconfirmed per day, once a
minute) ([#727](#727))
([b2eb48f](b2eb48f))
* **deps:** update github.com/dop251/goja digest to 032d024
([#724](#724))
([025e97a](025e97a))
* **deps:** update go dependencies (non-major)
([#725](#725))
([5796b1f](5796b1f))
* **deps:** update module github.com/prometheus/common to v0.73.1
([#720](#720))
([9bef875](9bef875))
* **deps:** update module github.com/slack-go/slack to v0.33.0
([#722](#722))
([ad19df4](ad19df4))
* **security:** bug-report budget for non-members, retention sparing
crawl reports
([#715](#715))
([d929999](d929999))
* **security:** JS check memory budget, re-authentication for new
sign-in factors
([#728](#728))
([a78f954](a78f954))


### Performance Improvements

* **dash0:** load only the active language's translations
([#729](#729))
([406f211](406f211))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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