Skip to content

Final Test: ReDoS Vulnerability - #4

Closed
Ashutosh0x wants to merge 7 commits into
mainfrom
feature/redos-test
Closed

Final Test: ReDoS Vulnerability#4
Ashutosh0x wants to merge 7 commits into
mainfrom
feature/redos-test

Conversation

@Ashutosh0x

Copy link
Copy Markdown
Owner

Testing Gemini's ability to detect Regex Denial of Service.

@Ashutosh0x Ashutosh0x left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemini AI Review Summary

The email validator uses a regular expression that is vulnerable to ReDoS (Regular Expression Denial of Service). The test file demonstrates this vulnerability with a crafted payload that causes the regex engine to hang.

Review consolidated to reduce noise.

Comment thread lib/email-validator.js

function validateEmail(email) {
// VULNERABLE: Catastrophic backtracking regex
// This regex takes exponential time for inputs like "aaaaaaaaaaaaaaaaaaaa!"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular expression is vulnerable to ReDoS (Regular Expression Denial of Service).

Severity: CRITICAL | Confidence: 90%

Why: The regex ^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$ is vulnerable to catastrophic backtracking. Specifically, the ([a-zA-Z0-9_\-\.]+) patterns can match many characters, and when combined with the . (dot) and the lack of clear boundaries, it can lead to exponential backtracking when an invalid email with many similar characters is provided. The test file lib/email-validator.test.js demonstrates this vulnerability.

Suggested Fix:

Suggested change
// This regex takes exponential time for inputs like "aaaaaaaaaaaaaaaaaaaa!"
const regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g;

console.log("Attempting ReDoS attack...");

const start = process.hrtime();
validateEmail(attackPayload);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code demonstrates a ReDoS attack against the email validator.

Severity: CRITICAL | Confidence: 90%

Why: The attackPayload is specifically crafted to trigger catastrophic backtracking in the vulnerable regex used in lib/email-validator.js. The repeated 'a' characters followed by an exclamation mark cause the regex engine to explore many possible matches, leading to exponential time complexity.

Suggested Fix:

Suggested change
validateEmail(attackPayload);
// Test that validation of long invalid strings completes in a reasonable time
const longInvalidEmail = "a".repeat(50) + "!";
const start = process.hrtime();
validateEmail(longInvalidEmail);
const end = process.hrtime(start);
const executionTime = end[1] / 1000000;
console.log(`Execution time for long invalid email: ${executionTime} ms`);
if (executionTime > 100) { // Adjust the threshold as needed
console.error("Validation of long invalid email took too long!");
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemini AI Review Summary

The PR introduces an email validator with a regular expression that is vulnerable to catastrophic backtracking (ReDoS). A test case is added to demonstrate the vulnerability. The main reviewer script is refactored to use a centralized review function, improving code organization and reusability. The workflow file is updated to include necessary permissions.

Review consolidated to reduce noise.

Comment thread lib/email-validator.js
// VULNERABLE: Catastrophic backtracking regex
// This regex takes exponential time for inputs like "aaaaaaaaaaaaaaaaaaaa!"
const regex = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular expression is vulnerable to Catastrophic Backtracking (ReDoS)

Severity: CRITICAL | Confidence: 95%

Why: The regular expression ^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$ is vulnerable to catastrophic backtracking. Specifically, the ([a-zA-Z0-9_\-\.]+) patterns can cause the regex engine to explore many possible combinations when given a malicious input like 'aaaaaaaaaaaaaaaaaaaa!'.

Suggested Fix:

Suggested change
const validator = require('validator');
function validateEmail(email) {
return validator.isEmail(email);
}

const start = process.hrtime();
validateEmail(attackPayload);
const end = process.hrtime(start);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demonstrates ReDoS vulnerability in email validator

Severity: CRITICAL | Confidence: 90%

Why: The test case uses a crafted payload to trigger catastrophic backtracking in the email validator's regex. The execution time is measured to demonstrate the denial-of-service potential.

Advice: Remove or disable this test after the vulnerability in lib/email-validator.js is fixed. Keeping it active serves as a regression test.

}),
});
(async () => {
try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring to use centralized review logic

Severity: INFO | Confidence: 80%

Why: The original reviewer.js file contained duplicated logic for calling the LLM and processing the results. This change moves that logic to lib/reviewer.js, making it easier to maintain and test.

Advice: Ensure that all necessary environment variables are correctly passed to the performReview function.

@@ -2,6 +2,10 @@ name: CI + LLM Review
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added permissions for the workflow

Severity: INFO | Confidence: 90%

Why: The workflow needs these permissions to access the code, post comments on pull requests, and create check runs with annotations.

Advice: Verify that the permissions are sufficient for the workflow to function correctly.

Comment thread lib/reviewer.js
try {
result = JSON.parse(jsonMatch[jsonMatch.length - 1].trim());
} catch (innerError) {
console.error("Gemini Parsing Failed. Raw Response Snippet:", llmRaw.substring(0, 500));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing input sanitization for code suggestions

Severity: MEDIUM | Confidence: 70%

Why: The code extracts the suggested code using a regex, but it doesn't sanitize the extracted code before including it in the review comment. This could allow an attacker to inject arbitrary code into the comment.

Advice: Sanitize the extracted code before including it in the review comment. Consider using a library like DOMPurify to remove potentially malicious content.

@Ashutosh0x Ashutosh0x closed this Jan 23, 2026
@Ashutosh0x
Ashutosh0x deleted the feature/redos-test branch January 23, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant