Skip to content

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

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

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

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 the bank routing number validation. The code previously tested user-supplied input directly against a regex pattern without length limits, allowing attackers to submit extremely long strings that would cause catastrophic backtracking and CPU exhaustion.

The fix adds input validation before the regex test: it checks that bankRouting is a string and enforces a maximum length of 20 characters (sufficient for legitimate routing numbers). This prevents malicious input from triggering exponential-time regex evaluation while preserving the existing validation logic for properly-sized inputs.

--- 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]+\#/;
+        // Prevent ReDoS by limiting input length before regex evaluation
+        if (typeof bankRouting !== 'string' || bankRouting.length > 20) {
+            return res.render("profile", {
+                updateError: "Bank Routing number exceeds maximum allowed length",
+                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