Skip to content

P0/P1 Competitive Test: Cross-File Auth Logic - #3

Closed
Ashutosh0x wants to merge 1 commit into
mainfrom
feature/secure-auth
Closed

P0/P1 Competitive Test: Cross-File Auth Logic#3
Ashutosh0x wants to merge 1 commit into
mainfrom
feature/secure-auth

Conversation

@Ashutosh0x

@Ashutosh0x Ashutosh0x commented Jan 23, 2026

Copy link
Copy Markdown
Owner

This PR introduces a new auth module and a test demonstrating a secret leak. Used to verify Gemini's cross-file reasoning and one-click suggestions.


Summary by cubic

Added HMAC-SHA256 signature verification (lib/auth.js) and a cross-file exploit script (lib/auth-exploit.js) that forges a valid signature. This exposes a security risk from a hardcoded secret and non–timing-safe string comparison.

Written for commit a4721f8. Summary will update on new commits.

@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 code contains a critical vulnerability due to a hardcoded secret key used for HMAC signature verification. The auth-exploit.js file demonstrates how an attacker can exploit this vulnerability to forge signatures and gain unauthorized access. Additionally, the auth.js file uses a non-timing-safe string comparison which could be vulnerable to timing attacks, although the hardcoded secret is the more pressing issue.

Review consolidated to reduce noise.

Comment thread lib/auth.js
@@ -0,0 +1,15 @@
const crypto = require('crypto');

// WEAK SECRET: Should be in environment variables

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.

Hardcoded secret key

Severity: CRITICAL | Confidence: 100%

Why: The API_SECRET is hardcoded directly in the code. This means anyone with access to the codebase (or even a decompiled version of it) can discover the secret and use it to generate valid signatures for arbitrary payloads. The auth-exploit.js file shows exactly how this can be done.

Suggested Fix:

Suggested change
// WEAK SECRET: Should be in environment variables
const API_SECRET = process.env.API_SECRET;

Comment thread lib/auth-exploit.js
const forgedPayload = "{\"admin\": true}";
const forgedSig = crypto.createHmac('sha256', KNOWN_SECRET)
.update(forgedPayload)
.digest('hex');

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.

Demonstration of signature forgery

Severity: CRITICAL | Confidence: 100%

Why: This code directly uses the hardcoded KNOWN_SECRET (which is the same as API_SECRET in auth.js) to create a valid signature for a payload containing {"admin": true}. This shows the direct impact of the hardcoded secret.

Advice: Remove this file from production code. It serves only as a proof-of-concept exploit.

Comment thread lib/auth.js
.update(payload)
.digest('hex');

// VULNERABLE: Direct string comparison instead of timing-safe comparison

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.

Timing-unsafe string comparison

Severity: LOW | Confidence: 60%

Why: The === operator performs a direct string comparison, which is vulnerable to timing attacks. If the comparison fails early, it will return faster than if it fails later. This difference in timing can be exploited to reveal the signature.

Advice: Use a timing-safe comparison function to prevent timing attacks.

@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 code contains a critical vulnerability due to a hardcoded secret key used for HMAC signature verification. The auth-exploit.js file demonstrates how an attacker can exploit this vulnerability to forge signatures and gain unauthorized access. Additionally, the auth.js file uses a non-timing-safe string comparison which could be vulnerable to timing attacks, although the hardcoded secret is the more pressing issue.

Review consolidated to reduce noise.

Comment thread lib/auth.js
@@ -0,0 +1,15 @@
const crypto = require('crypto');

// WEAK SECRET: Should be in environment variables

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.

Hardcoded secret key

Severity: CRITICAL | Confidence: 100%

Why: The API_SECRET is hardcoded directly in the code. This means anyone with access to the codebase (or even a decompiled version of it) can discover the secret and use it to generate valid signatures for arbitrary payloads. The auth-exploit.js file shows exactly how this can be done.

Suggested Fix:

Suggested change
// WEAK SECRET: Should be in environment variables
const API_SECRET = process.env.API_SECRET;

Comment thread lib/auth-exploit.js
const forgedPayload = "{\"admin\": true}";
const forgedSig = crypto.createHmac('sha256', KNOWN_SECRET)
.update(forgedPayload)
.digest('hex');

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.

Demonstration of signature forgery

Severity: CRITICAL | Confidence: 100%

Why: This code directly uses the hardcoded KNOWN_SECRET (which is the same as API_SECRET in auth.js) to create a valid signature for a payload containing {"admin": true}. This shows the direct impact of the hardcoded secret.

Advice: Remove this file from production code. It serves only as a proof-of-concept exploit.

Comment thread lib/auth.js
.update(payload)
.digest('hex');

// VULNERABLE: Direct string comparison instead of timing-safe comparison

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.

Timing-unsafe string comparison

Severity: LOW | Confidence: 60%

Why: The === operator performs a direct string comparison, which is vulnerable to timing attacks. If the comparison fails early, it will return faster than if it fails later. This difference in timing can be exploited to reveal the signature.

Advice: Use a timing-safe comparison function to prevent timing attacks.

@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 code contains a critical vulnerability due to a hardcoded secret key used for HMAC signature verification. The auth-exploit.js file demonstrates how an attacker can exploit this vulnerability to forge signatures and gain unauthorized access. Additionally, the auth.js file uses a non-timing-safe string comparison which could be vulnerable to timing attacks, although the hardcoded secret is the more pressing issue.

Review consolidated to reduce noise.

Comment thread lib/auth.js
@@ -0,0 +1,15 @@
const crypto = require('crypto');

// WEAK SECRET: Should be in environment variables

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.

Hardcoded secret key

Severity: CRITICAL | Confidence: 100%

Why: The API_SECRET is hardcoded directly in the code. This means anyone with access to the codebase (or even a decompiled version of it) can discover the secret and use it to generate valid signatures for arbitrary payloads. The auth-exploit.js file shows exactly how this can be done.

Suggested Fix:

Suggested change
// WEAK SECRET: Should be in environment variables
const API_SECRET = process.env.API_SECRET;

Comment thread lib/auth-exploit.js
const forgedPayload = "{\"admin\": true}";
const forgedSig = crypto.createHmac('sha256', KNOWN_SECRET)
.update(forgedPayload)
.digest('hex');

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.

Demonstration of signature forgery

Severity: CRITICAL | Confidence: 100%

Why: This code directly uses the hardcoded KNOWN_SECRET (which is the same as API_SECRET in auth.js) to create a valid signature for a payload containing {"admin": true}. This shows the direct impact of the hardcoded secret.

Advice: Remove this file from production code. It serves only as a proof-of-concept exploit.

Comment thread lib/auth.js
.update(payload)
.digest('hex');

// VULNERABLE: Direct string comparison instead of timing-safe comparison

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.

Timing-unsafe string comparison

Severity: LOW | Confidence: 60%

Why: The === operator performs a direct string comparison, which is vulnerable to timing attacks. If the comparison fails early, it will return faster than if it fails later. This difference in timing can be exploited to reveal the signature.

Advice: Use a timing-safe comparison function to prevent timing attacks.

@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 code contains a critical vulnerability due to a hardcoded secret key used for HMAC signature verification. The auth-exploit.js file demonstrates how an attacker can exploit this vulnerability to forge signatures and gain unauthorized access. Additionally, the auth.js file uses a non-timing-safe string comparison which could be vulnerable to timing attacks, although the hardcoded secret is the more pressing issue.

Review consolidated to reduce noise.

Comment thread lib/auth.js
@@ -0,0 +1,15 @@
const crypto = require('crypto');

// WEAK SECRET: Should be in environment variables

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.

Hardcoded secret key

Severity: CRITICAL | Confidence: 100%

Why: The API_SECRET is hardcoded directly in the code. This means anyone with access to the codebase (or even a decompiled version of it) can discover the secret and use it to generate valid signatures for arbitrary payloads. The auth-exploit.js file shows exactly how this can be done.

Suggested Fix:

Suggested change
// WEAK SECRET: Should be in environment variables
const API_SECRET = process.env.API_SECRET;

Comment thread lib/auth-exploit.js
const forgedPayload = "{\"admin\": true}";
const forgedSig = crypto.createHmac('sha256', KNOWN_SECRET)
.update(forgedPayload)
.digest('hex');

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.

Demonstration of signature forgery

Severity: CRITICAL | Confidence: 100%

Why: This code directly uses the hardcoded KNOWN_SECRET (which is the same as API_SECRET in auth.js) to create a valid signature for a payload containing {"admin": true}. This shows the direct impact of the hardcoded secret.

Advice: Remove this file from production code. It serves only as a proof-of-concept exploit.

Comment thread lib/auth.js
.update(payload)
.digest('hex');

// VULNERABLE: Direct string comparison instead of timing-safe comparison

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.

Timing-unsafe string comparison

Severity: LOW | Confidence: 60%

Why: The === operator performs a direct string comparison, which is vulnerable to timing attacks. If the comparison fails early, it will return faster than if it fails later. This difference in timing can be exploited to reveal the signature.

Advice: Use a timing-safe comparison function to prevent timing attacks.

@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 code contains a hardcoded secret key used for HMAC signature verification, making it trivial for an attacker to forge signatures. The auth-exploit.js file demonstrates this vulnerability by forging a signature for an admin payload using the known secret and successfully bypassing the authentication check in auth.js.

Review consolidated to reduce noise.

Comment thread lib/auth.js
@@ -0,0 +1,15 @@
const crypto = require('crypto');

// WEAK SECRET: Should be in environment variables

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.

Hardcoded secret key

Severity: CRITICAL | Confidence: 100%

Why: The API_SECRET is hardcoded directly in the code. This makes it easily discoverable, especially if the code is committed to a public repository. The auth-exploit.js file demonstrates how an attacker can use this known secret to forge a signature.

Suggested Fix:

Suggested change
// WEAK SECRET: Should be in environment variables
const API_SECRET = process.env.API_SECRET;

Comment thread lib/auth.js
.update(payload)
.digest('hex');

// VULNERABLE: Direct string comparison instead of timing-safe comparison

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.

Vulnerable to timing attacks

Severity: LOW | Confidence: 70%

Why: The code uses a direct string comparison (===) to compare the expected signature with the provided signature. This is vulnerable to timing attacks, where an attacker can measure the time it takes for the comparison to fail and infer information about the correct signature. While the primary vulnerability is the hardcoded secret, this secondary issue exacerbates the problem.

Advice: Use a timing-safe comparison function to prevent timing attacks.

Comment thread lib/auth-exploit.js
const { verifySignature } = require('./auth');
const crypto = require('crypto');

// AN ATTACKER WHO KNOWS THE SECRET CAN FORGE SIGNATURES

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.

Hardcoded secret used for exploit

Severity: CRITICAL | Confidence: 100%

Why: This line uses the same hardcoded secret as auth.js to forge a signature, proving the vulnerability.

Advice: Remove this file from production code. It serves only as a demonstration of the vulnerability.

@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 code contains a hardcoded secret key used for HMAC signature verification, making it trivial for an attacker to forge signatures. The auth-exploit.js file demonstrates this vulnerability by forging a signature for an admin payload.

Review consolidated to reduce noise.

Comment thread lib/auth.js
@@ -0,0 +1,15 @@
const crypto = require('crypto');

// WEAK SECRET: Should be in environment variables

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.

Hardcoded secret key

Severity: CRITICAL | Confidence: 100%

Why: The API_SECRET is hardcoded directly in the code. This means anyone with access to the codebase (or even decompiled code) can discover the secret and use it to generate valid signatures for arbitrary payloads. The auth-exploit.js file demonstrates how an attacker can exploit this vulnerability.

Suggested Fix:

Suggested change
// WEAK SECRET: Should be in environment variables
const API_SECRET = process.env.API_SECRET;

Comment thread lib/auth-exploit.js
// 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)

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.

Demonstration of signature forgery

Severity: CRITICAL | Confidence: 100%

Why: This code directly uses the hardcoded secret from lib/auth.js to create a valid signature for a malicious payload ({"admin": true}). This highlights the severity of the hardcoded secret vulnerability.

Advice: Remove this exploit code from production.

Comment thread lib/auth.js
.digest('hex');

// VULNERABLE: Direct string comparison instead of timing-safe comparison
return expected === signature;

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.

Vulnerable timing attack

Severity: 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.

@Ashutosh0x Ashutosh0x closed this Jan 23, 2026
@Ashutosh0x
Ashutosh0x deleted the feature/secure-auth branch January 23, 2026 08:23
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