-
Notifications
You must be signed in to change notification settings - Fork 0
P0/P1 Competitive Test: Cross-File Auth Logic #3
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
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const { verifySignature } = require('./auth'); | ||
| const crypto = require('crypto'); | ||
|
|
||
| // AN ATTACKER WHO KNOWS THE SECRET CAN FORGE SIGNATURES | ||
| const KNOWN_SECRET = "REALLY_BAD_HARDCODED_SECRET_123"; | ||
| const forgedPayload = "{\"admin\": true}"; | ||
| const forgedSig = crypto.createHmac('sha256', KNOWN_SECRET) | ||
|
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. Demonstration of signature forgerySeverity: CRITICAL | Confidence: 100% Why: This code directly uses the hardcoded secret from Advice: Remove this exploit code from production. |
||
| .update(forgedPayload) | ||
| .digest('hex'); | ||
|
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. Demonstration of signature forgerySeverity: CRITICAL | Confidence: 100% Why: This code directly uses the hardcoded Advice: Remove this file from production code. It serves only as a proof-of-concept exploit.
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. Demonstration of signature forgerySeverity: CRITICAL | Confidence: 100% Why: This code directly uses the hardcoded Advice: Remove this file from production code. It serves only as a proof-of-concept exploit.
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. Demonstration of signature forgerySeverity: CRITICAL | Confidence: 100% Why: This code directly uses the hardcoded Advice: Remove this file from production code. It serves only as a proof-of-concept exploit.
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. Demonstration of signature forgerySeverity: CRITICAL | Confidence: 100% Why: This code directly uses the hardcoded Advice: Remove this file from production code. It serves only as a proof-of-concept exploit. |
||
|
|
||
| console.log("Attack successful?", verifySignature(forgedPayload, forgedSig)); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||||||||||||||||||
| const crypto = require('crypto'); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // WEAK SECRET: Should be in environment variables | ||||||||||||||||||||||||||
|
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. Hardcoded secret keySeverity: CRITICAL | Confidence: 100% Why: The Suggested Fix:
Suggested change
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. Hardcoded secret keySeverity: CRITICAL | Confidence: 100% Why: The Suggested Fix:
Suggested change
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. Hardcoded secret keySeverity: CRITICAL | Confidence: 100% Why: The Suggested Fix:
Suggested change
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. Hardcoded secret keySeverity: CRITICAL | Confidence: 100% Why: The Suggested Fix:
Suggested change
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. Hardcoded secret keySeverity: CRITICAL | Confidence: 100% Why: The Suggested Fix:
Suggested change
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. Hardcoded secret keySeverity: CRITICAL | Confidence: 100% Why: The Suggested Fix:
Suggested change
|
||||||||||||||||||||||||||
| const API_SECRET = "REALLY_BAD_HARDCODED_SECRET_123"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function verifySignature(payload, signature) { | ||||||||||||||||||||||||||
| const expected = crypto.createHmac('sha256', API_SECRET) | ||||||||||||||||||||||||||
| .update(payload) | ||||||||||||||||||||||||||
| .digest('hex'); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // VULNERABLE: Direct string comparison instead of timing-safe comparison | ||||||||||||||||||||||||||
|
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. Timing-unsafe string comparisonSeverity: LOW | Confidence: 60% Why: The Advice: Use a timing-safe comparison function to prevent timing attacks.
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. Timing-unsafe string comparisonSeverity: LOW | Confidence: 60% Why: The Advice: Use a timing-safe comparison function to prevent timing attacks.
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. Timing-unsafe string comparisonSeverity: LOW | Confidence: 60% Why: The Advice: Use a timing-safe comparison function to prevent timing attacks.
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. Timing-unsafe string comparisonSeverity: LOW | Confidence: 60% Why: The Advice: Use a timing-safe comparison function to prevent timing attacks.
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. Vulnerable to timing attacksSeverity: LOW | Confidence: 70% Why: The code uses a direct string comparison ( Advice: Use a timing-safe comparison function to prevent timing attacks. |
||||||||||||||||||||||||||
| return expected === signature; | ||||||||||||||||||||||||||
|
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. Vulnerable timing attackSeverity: LOW | Confidence: 60% Why: Direct string comparison is susceptible to timing attacks. A timing-safe comparison should be used to prevent attackers from inferring information about the signature by measuring the time it takes for the comparison to complete. Advice: Use a timing-safe comparison function. |
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| module.exports = { verifySignature }; | ||||||||||||||||||||||||||
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.
Hardcoded secret used for exploit
Severity: CRITICAL | Confidence: 100%
Why: This line uses the same hardcoded secret as
auth.jsto forge a signature, proving the vulnerability.Advice: Remove this file from production code. It serves only as a demonstration of the vulnerability.