-
Notifications
You must be signed in to change notification settings - Fork 0
Final Test: ReDoS Vulnerability #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dce3396
cc571c1
bcd7986
df9d9ba
9dc447f
3e2decd
227e784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| name: CI + LLM Review | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
|
Check notice on line 4 in .github/workflows/llm-review.yml
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added permissions for the workflowSeverity: 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. |
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| checks: write | ||
| jobs: | ||
| llm-review: | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -26,7 +30,7 @@ | |
| env: | ||
| LLM_API_URL: ${{ secrets.LLM_API_URL }} | ||
| LLM_API_KEY: ${{ secrets.LLM_API_KEY }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||||||||||
| // Email validator utility | ||||||||||||||
|
|
||||||||||||||
| function validateEmail(email) { | ||||||||||||||
| // VULNERABLE: Catastrophic backtracking regex | ||||||||||||||
| // This regex takes exponential time for inputs like "aaaaaaaaaaaaaaaaaaaa!" | ||||||||||||||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Suggested Fix:
Suggested change
|
||||||||||||||
| const regex = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/; | ||||||||||||||
|
|
||||||||||||||
|
Check failure on line 7 in lib/email-validator.js
|
||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Suggested Fix:
Suggested change
|
||||||||||||||
| return regex.test(email); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| module.exports = { validateEmail }; | ||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||||||||||||||||||
| const { validateEmail } = require('./email-validator'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| console.log("Testing normal email:", validateEmail("test@example.com")); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // EXPLOIT: This payload causes the regex engine to hang | ||||||||||||||||||||||||
| const attackPayload = "a".repeat(50) + "!"; | ||||||||||||||||||||||||
| console.log("Attempting ReDoS attack..."); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const start = process.hrtime(); | ||||||||||||||||||||||||
| validateEmail(attackPayload); | ||||||||||||||||||||||||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Suggested Fix:
Suggested change
|
||||||||||||||||||||||||
| const end = process.hrtime(start); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Check failure on line 12 in lib/email-validator.test.js
|
||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Demonstrates ReDoS vulnerability in email validatorSeverity: 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 |
||||||||||||||||||||||||
| console.log(`Execution time: ${end[1] / 1000000} ms`); | ||||||||||||||||||||||||
There was a problem hiding this comment.
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.jsfile contained duplicated logic for calling the LLM and processing the results. This change moves that logic tolib/reviewer.js, making it easier to maintain and test.Advice: Ensure that all necessary environment variables are correctly passed to the
performReviewfunction.