Rate limiting and user enumeration
Understand the idea
Login and forgot-password are where a password list and a username oracle meet.
The idea
The counter itself is the one in Rate limiting and abuse basics. This lesson does not build another algorithm. It puts that limit on POST /login and POST /forgot, the two routes a password list actually hits. A bucket that starts full answers 429 on the next guess. The other half is enumeration. If an unknown email returns no such user and a known email returns wrong password, the attacker keeps the addresses that exist and spends the list only there. Both failures here are 401 with invalid credentials. Forgot-password has the same leak if it admits the account exists. The function still looks the email up, because you might send mail, and then it returns one sentence either way. The lookup result is not in the JSON.
What changes
| Behavior | What an attacker learns | What you return |
|---|---|---|
| Different login errors | Which emails are real | One 401 body for unknown and wrong |
| Forgot-password that varies | The same list | One sentence, whether or not the account exists |
| No limit on those routes | They can try the whole list | 429 once the bucket from the Node lesson is empty |
The command
Unknown email
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Known email, wrong password
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Bucket already empty
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Forgot-password says the same thing
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
The mistake
Check the result
Both login failures are 401 and invalid credentials. The pre-filled bucket is 429 and slow down. The two forgot-password bodies are equal, so same is true.
Guided challenge
Use one failure string
loginError tells the caller no such user or wrong password. Return invalid credentials for both failures so the two prints match.
Use one failure string
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
EXPECTED RESULT
invalid credentials invalid credentials
Hints 0/2
Use all hints or make 3 failed checks (0/3).
Free exploration
Change this example and run it again. Each run is a new process. Nothing is saved.
Your variation
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 200 XP. You can always revisit it.