Skip to content

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

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

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

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 potential denial-of-service vulnerability where uncontrolled user input (bankRouting from POST data) was passed directly to a regular expression test without length validation. An attacker could submit an extremely long string that would cause excessive CPU consumption during regex evaluation.

The fix adds input validation before the regex test to ensure bankRouting is a string and does not exceed 50 characters. This length limit is appropriate for bank routing numbers (typically 9 digits plus the '#' suffix) and prevents abuse while maintaining legitimate functionality.

--- a/app/routes/profile.js
+++ b/app/routes/profile.js
@@ -41,6 +41,19 @@
         // The Fix: Instead of using greedy quantifiers the same regex will work if we omit the second quantifier +
         // const regexPattern = /([0-9]+)\#/;
         const regexPattern = /[0-9]+\#/;
+        // Validate bankRouting input before regex to prevent DoS via excessive input length
+        if (typeof bankRouting !== 'string' || bankRouting.length > 50) {
+            return res.render("profile", {
+                updateError: "Bank Routing number format is invalid",
+                firstName,
+                lastName,
+                ssn,
+                dob,
+                address,
+                bankAcc,
+                bankRouting: ''
+            });
+        }
         // Allow only numbers with a suffix of the letter #, for example: 'XXXXXX#'
         const testComplyWithRequirements = regexPattern.test(bankRouting);
         // if the regex test fails we do not allow saving

@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