Login accepts a password list and confirms which emails exist
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
A login route with no limit lets an attacker try password lists as fast as the network allows. Hashing the password makes each guess slower and does not cap how many guesses arrive. The same route becomes a username oracle when an unknown email and a wrong password return different statuses or different bodies. The attacker keeps the addresses that exist and spends the rest of the list only on those. Forgot-password does the same job for them if it says mail was sent only when the account is real. The rate-limit lesson on the Node track already built the counter. The failure here is that the counter is not on these two routes, and that the response text answers a question the caller should not get to ask.
Minimal reproduction
Two answers, no limit
if (!users[email]) return res.status(404).json({ error: 'no such user' });
if (password !== secret) return res.status(401).json({ error: 'wrong password' });
The 404 tells the attacker the email is worth guessing, and nothing slows them down.
The fix
Put the existing limiter on POST /login and POST /forgot, counted by address and by account identifier, and return 429 when the bucket is empty. Do not invent a second algorithm beside the one that lesson already runs. Return the same status and the same body for an unknown email and a wrong password. Return the same forgot-password body whether or not the account exists. You may still look the email up on the server so you can send mail. That boolean stays out of the . Log the 429s so a stuffing run is visible instead of looking like ordinary traffic.
One body, then the limit
if (!known || password !== secret) return res.status(401).json({ error: 'invalid credentials' });
if (hits.login > limit) return res.status(429).json({ error: 'slow down' });
Unknown and wrong look the same, and a full bucket stops the list.