fix: BUG-022 check duplicate email before rate limit, BUG-024 support X-API-Key header
This commit is contained in:
parent
f59b99203e
commit
a67c16cd0f
3 changed files with 28 additions and 5 deletions
|
|
@ -22,8 +22,21 @@ const verifyLimiter = rateLimit({
|
|||
legacyHeaders: false,
|
||||
});
|
||||
|
||||
// Pre-check: reject already-registered emails BEFORE rate limiting (BUG-022)
|
||||
function rejectDuplicateEmail(req: Request, res: Response, next: Function) {
|
||||
const { email } = req.body || {};
|
||||
if (email && typeof email === "string") {
|
||||
const cleanEmail = email.trim().toLowerCase();
|
||||
if (isEmailVerified(cleanEmail)) {
|
||||
res.status(409).json({ error: "Email already registered" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
// Step 1: Request signup — generates 6-digit code
|
||||
router.post("/free", signupLimiter, async (req: Request, res: Response) => {
|
||||
router.post("/free", rejectDuplicateEmail, signupLimiter, async (req: Request, res: Response) => {
|
||||
const { email } = req.body || {};
|
||||
|
||||
if (!email || typeof email !== "string" || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue