fix: secure email regex against ReDoS vulnerability

- Replace vulnerable regex with bounded quantifiers
- Add email length check (max 254 chars per RFC 5321)
- Fixes SonarQube security hotspot S5852

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
soufiane 2025-12-04 15:39:27 +01:00
parent e480c7ee1e
commit 17a9dc7b22

View File

@ -328,9 +328,9 @@ export const checkEmail = asyncHandler(async (req, res, next) => {
return next(new AppError('Email requis', 400)); return next(new AppError('Email requis', 400));
} }
// Validation format email // Validation format email (regex sécurisée contre ReDoS avec limite de longueur)
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const isValidEmail = email.length <= 254 && /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(email);
if (!emailRegex.test(email)) { if (!isValidEmail) {
return res.json({ return res.json({
success: true, success: true,
isValid: false, isValid: false,