diff options
| author | Adam Soltys <[email protected]> | 2026-12-02 13:45:44 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-12-02 13:45:44 -0700 |
| commit | 5b7881f3195d9c1479cfffc207014540a9db4d9a (patch) | |
| tree | 1316b495e207db65001c120c0ef3ff48c26c59f4 /routes/users.ts | |
| parent | 796999cb8a6fc7abbfb9dc2643e372795fed9882 (diff) | |
| download | coinos-server-5b7881f3195d9c1479cfffc207014540a9db4d9a.tar.gz coinos-server-5b7881f3195d9c1479cfffc207014540a9db4d9a.zip | |
register: cap account creation over Tor at five an hour
Onion clients all arrive from the Tor gateway's address, so the per-IP and
per-range signup caps either let them create unlimited accounts or would
count unrelated internal traffic. Mark requests that came through Tor
(including ones the UI's server-side rendering relays, which forward the
client address in cf-connecting-ip) with req.isTor, and give them one
shared quota of five new accounts an hour for /register and first-time
nostr logins. The recaptcha bypass for onion users now uses the same flag
instead of trusting the Host header.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6SSfVopM1ZzXKZmLYU
Diffstat (limited to 'routes/users.ts')
| -rw-r--r-- | routes/users.ts | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/routes/users.ts b/routes/users.ts index 17bf5026..cfa41b8b 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -11,6 +11,7 @@ import { mail, templates } from "$lib/mail"; import { getNostrUser, getProfile, serverPubkey2 } from "$lib/nostr"; import deleteUser from "$lib/deluser"; import register from "$lib/register"; +import { allowTorRegistration } from "$lib/registration-limit"; import { assertNameFree } from "$lib/names"; import { isReserved } from "$lib/reserved"; import { emit } from "$lib/sockets"; @@ -47,8 +48,7 @@ const verifyRecaptcha = async ( if (!secret) return true; // Skip captcha for Tor users accessing via .onion - const reqHost = req?.headers?.["x-forwarded-host"] || req?.headers?.["host"] || ""; - if (reqHost.endsWith(".onion")) return true; + if (req?.isTor) return true; // Skip captcha for allowlisted User-Agents (prefix match) const uaRaw = req?.headers?.["user-agent"] || req?.headers?.["User-Agent"]; @@ -194,6 +194,7 @@ export default { try { const ip = headers["cf-connecting-ip"]; if (!body.user) fail("no user object provided"); + if (!(await allowTorRegistration(req, res))) return; let { user } = body; // Per-IP registration cap. Nothing else throttles /register (the @@ -679,6 +680,7 @@ export default { let user = await getUser(key); if (!user) { + if (!(await allowTorRegistration(req, res))) return; const k0 = await getProfile(key); let username = k0?.name?.replace(/[^a-zA-Z0-9 ]/g, ""); const exists = await getUser(username); |
