Skip to content

[LEGIT] Fix - js/polynomial-redos - #117

Open
liorn-test-app[bot] wants to merge 1 commit into
masterfrom
legit-security-a4b461
Open

[LEGIT] Fix - js/polynomial-redos#117
liorn-test-app[bot] wants to merge 1 commit into
masterfrom
legit-security-a4b461

Conversation

@liorn-test-app

Copy link
Copy Markdown

🔍 The problem

Polynomial regular expression used on uncontrolled data
See issue in Legit

🔒 Fix Details

Fixed a Regular Expression Denial of Service (ReDoS) vulnerability in email validation. The EMAIL_RE regex was applied directly to user-controlled input without length constraints, allowing attackers to craft malicious email strings that could cause catastrophic backtracking and block the Node.js event loop. Added a length check limiting email input to 254 characters (per RFC 5321) before regex evaluation. This bounds the input size and prevents exponential backtracking time, mitigating the DoS risk while maintaining the existing validation logic.

--- a/app/routes/session.js
+++ b/app/routes/session.js
@@ -163,6 +163,10 @@
             return false;
         }
         if (email !== "") {
+            if (email.length > 254) {
+                errors.emailError = "Invalid email address";
+                return false;
+            }
             if (!EMAIL_RE.test(email)) {
                 errors.emailError = "Invalid email address";
                 return false;
@@ -193,7 +197,6 @@
                 }
 
                 userDAO.addUser(userName, firstName, lastName, password, email, (err, user) => {
-
                     if (err) return next(err);
 
                     //prepare data for the user

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants