Prevent user enumeration in sign up
Respond the same way to a sign-up with an existing email as to a new one, and send the real information by email only.
A sign-up form that says "email already registered" tells anyone who types an address whether that person uses your service. The fix is to show the same screen either way.
app.post('/signup', async (req, res) => {
const { email, password } = req.body;
const existing = await db.findUserByEmail(email);
if (existing) {
await mail(email, 'Someone tried to register with your address. Reset your password if that was you.');
} else {
await db.createUser({ email, passwordHash: await argon2.hash(password) });
await mail(email, 'Welcome! Confirm your address with this link: ...');
}
res.status(202).json({ message: 'Check your inbox to continue.' });
});HTTP/1.1 202 Accepted
{"message":"Check your inbox to continue."}The browser sees the same status and message in both cases. Only the owner of the mailbox learns what happened. Hash the password in the existing-user branch too, or do the equivalent work, so the timing is similar; moving the mail to a queue also hides the time spent sending. See the OWASP guidance on account enumeration.
The cost is a worse experience for someone who forgot they registered. A neutral message plus the email is the accepted trade-off for services where the list of users is sensitive.