Skip to content

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

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

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

Conversation

@liorn-test-app

Copy link
Copy Markdown

🔍 The problem

Polynomial regular expression used on uncontrolled data
See issue in Legit

🔒 Fix Details

Fixed Regular Expression Denial of Service (ReDoS) Vulnerability

The bankRouting parameter from user input was being tested against a regex pattern without length validation. While the regex /[0-9]+\#/ is simpler than the commented-out vulnerable version, the + quantifier can still cause polynomial-time backtracking when processing very long strings of digits that don't match the pattern (e.g., "999...999X").

Fix applied: Added input validation before the regex test to ensure bankRouting is a string and does not exceed 20 characters. This prevents attackers from submitting arbitrarily long inputs that could trigger excessive CPU consumption through regex backtracking. The validation rejects invalid inputs early with an appropriate error message, protecting the application from ReDoS attacks.

--- a/app/routes/profile.js
+++ b/app/routes/profile.js
@@ -32,6 +32,20 @@
     this.handleProfileUpdate = (req, res, next) => {
 
         const {firstName, lastName, ssn, dob, address, bankAcc, bankRouting} = req.body;
+
+        // Validate bankRouting length to prevent ReDoS
+        if (!bankRouting || typeof bankRouting !== 'string' || bankRouting.length > 20) {
+            return res.render("profile", {
+                updateError: "Bank Routing number format is invalid",
+                firstName,
+                lastName,
+                ssn,
+                dob,
+                address,
+                bankAcc,
+                bankRouting: ''
+            });
+        }
 
         // Fix for Section: ReDoS attack
         // The following regexPattern that is used to validate the bankRouting number is insecure and vulnerable to

@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