{"success":true,"name":"rate-limit-the-sensitive-doors-login-signup-and-codes-must-n","description":"Building login, signup, password reset, or code-verification endpoints","category":"ai-brimind","path":"ai-brimind/rate-limit-the-sensitive-doors-login-signup-and-codes-must-n/SKILL.md","file":"SKILL.md","content":"---\nname: rate-limit-the-sensitive-doors-login-signup-and-codes-must-n\ndescription: \"Building login, signup, password reset, or code-verification endpoints\"\n---\n\n# Rate-Limit the Sensitive Doors: Login, Signup, and Codes Must Not Accept Infinite Tries\n\n## When to use\nYou are building or reviewing endpoints where repeated guessing pays off for an attacker — login, password reset, OTP/code verification, signup, or expensive public endpoints — and nothing currently limits how many attempts one client can make.\n\n## Example request\nLogin accepts unlimited tries → a script tests thousands of passwords per minute against one account; brute force is not clever, it is just a loop, and a rate limit breaks the loop. A 6-digit reset code with no attempt cap → a million possibilities is nothing for a script; limiting tries per code (and expiring it) is what makes 6 digits safe at all. Signup endpoint with no limit → a bot creates ten thousand junk accounts overnight and pollutes everything; per-IP throttling plus basic friction is the standard answer. An internal admin-only endpoint behind auth → low guessing value, rate limiting adds little; this discipline targets doors where retrying is the attack.\n\n## Instructions\nAct as a backend engineer who assumes every public endpoint will be visited by scripts, not just humans — patient scripts that try again forever, for free, unless you make retrying expensive. For each sensitive endpoint, do this: (1) Ask the attacker's question about it: 'what do I gain by calling this ten thousand times?' Guessing passwords, guessing codes, enumerating accounts, spamming signups, or just burning your server's CPU — if there is an answer, the endpoint needs a limit. (2) Add rate limiting with the mechanism your stack already offers (express-rate-limit or your framework's equivalent, or the hosting platform's built-in) — this is a solved, named problem; do not hand-roll counters in a global variable that resets on every deploy and breaks with multiple server instances. (3) Choose limits per door, not one global number: login might allow a handful of attempts per account and per IP over minutes, code verification a few tries per issued code (then invalidate the code), signup a small number per IP per hour. Say each number and why a human never hits it but a script dies on it. (4) Decide the failure behavior: respond with 429 and a clear retry-after, and log these events with who/where — a spike of 429s on login is your early warning that someone is at the door. (5) Pair limits with their natural partners where relevant: codes expire, accounts lock briefly after many failures (with a way back for the real owner), and responses for 'wrong password' vs 'no such user' stay identical so retries teach the attacker nothing. Only mark the endpoint done once you can state its limit, what a script experiences at attempt N, and where you would SEE an attack happening in the logs — 'nobody would bother attacking us' is not an answer, because scripts do not check who you are first.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #208\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}