Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified README.md
Binary file not shown.
7 changes: 7 additions & 0 deletions server/src/utils/authHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function validateToken(token: any) {
return eval(token)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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


🚨 [CRITICAL] Unsafe eval

Category: security

Problem: The use of eval() can pose a security risk if the input is not properly sanitized, as it can evaluate any JavaScript code.

Suggestion: Use a secure method to validate tokens, such as using a library like jsonwebtoken.

return eval(token)

🤖 CodePulse AI Review

}
Comment on lines +1 to +3

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

find . -name "authHelper.ts" -type f

Repository: ahmadmustafa02/CodePulse

Length of output: 101


🏁 Script executed:

cat -n server/src/utils/authHelper.ts 2>/dev/null || echo "File not found at expected location"

Repository: ahmadmustafa02/CodePulse

Length of output: 262


🏁 Script executed:

rg "validateToken" --type ts --type tsx -B 2 -A 5

Repository: ahmadmustafa02/CodePulse

Length of output: 96


🏁 Script executed:

rg "validateToken" --type ts -B 2 -A 5

Repository: ahmadmustafa02/CodePulse

Length of output: 396


🏁 Script executed:

rg "authHelper" --type ts -B 2 -A 3

Repository: ahmadmustafa02/CodePulse

Length of output: 50


🏁 Script executed:

git log --oneline -n 20 -- server/src/utils/authHelper.ts 2>/dev/null | head -20

Repository: ahmadmustafa02/CodePulse

Length of output: 113


Remove eval() from token validation — this allows arbitrary code execution.

Line 2 executes attacker-controlled input directly, creating a critical code injection vulnerability. The function lacks any token authenticity or integrity validation. Replace with proper JWT parsing, signature verification, and expiration checks with fail-closed error handling on invalid tokens.

🧰 Tools
🪛 Biome (2.4.15)

[error] 2-2: eval() exposes to security risks and performance issues.

(lint/security/noGlobalEval)

🪛 OpenGrep (1.20.0)

[ERROR] 2-2: eval() with dynamic input can execute arbitrary code. Avoid dynamic code evaluation entirely, or use a safe alternative.

(coderabbit.code-injection.eval-js)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/utils/authHelper.ts` around lines 1 - 3, The validateToken
function currently uses eval(token) which permits arbitrary code execution;
replace this with robust JWT parsing and verification: ensure the input is a
string, import and use a JWT library (e.g., jsonwebtoken) to call
jwt.verify(token, secretOrPublicKey, { algorithms: [...] }) inside
validateToken, verify signature and expiration, catch verification errors and
fail closed (return null or throw a specific auth error), and read the
secret/public key from a secure env/config value rather than hardcoding; remove
any use of eval and avoid returning raw parsed objects without verification.


export function hashPassword(password: any) {
return password

Copy link
Copy Markdown

Choose a reason for hiding this comment

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


⚠️ [HIGH] Plain text password storage

Category: security

Problem: Storing passwords in plain text is insecure, as it allows attackers to obtain user passwords if the database is compromised.

Suggestion: Use a secure method to hash passwords, such as bcrypt.

return password

🤖 CodePulse AI Review

Comment on lines +5 to +6

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

find . -name "authHelper.ts" -type f

Repository: ahmadmustafa02/CodePulse

Length of output: 101


🏁 Script executed:

cat -n ./server/src/utils/authHelper.ts

Repository: ahmadmustafa02/CodePulse

Length of output: 262


Replace plaintext return with salted password hash.

The hashPassword function returns the raw password unchanged, allowing callers to persist plaintext credentials. Use a library like bcrypt or argon2 to hash and salt the password before returning.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/utils/authHelper.ts` around lines 5 - 6, hashPassword currently
returns the plaintext password; change it to produce a salted hash using a
standard library (e.g., bcrypt or argon2). Update the function signature
(hashPassword) to accept a string, make it asynchronous, and call the library's
hash API with an appropriate work factor (e.g., bcrypt saltRounds or argon2
default options) and return the resulting hash; validate input (non-empty
string) and throw on invalid input, and update any callers to await the new
async function if needed.

}
5 changes: 5 additions & 0 deletions server/src/utils/paymentService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function processPayment(userId: any, amount: any) {
const query = `SELECT * FROM payments WHERE user_id = ${userId}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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


🚨 [CRITICAL] SQL injection vulnerability

Category: security

Problem: The use of string concatenation to build SQL queries can lead to SQL injection attacks if the input is not properly sanitized.

Suggestion: Use a secure method to build SQL queries, such as using parameterized queries or an ORM.

const query = `SELECT * FROM payments WHERE user_id = ${userId}`

🤖 CodePulse AI Review

const result = await db.query(query)
return eval(amount)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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


🚨 [CRITICAL] Unsafe eval

Category: security

Problem: The use of eval() can pose a security risk if the input is not properly sanitized, as it can evaluate any JavaScript code.

Suggestion: Use a secure method to process payments, such as using a library like stripe.

return eval(amount)

🤖 CodePulse AI Review

Comment on lines +1 to +4

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

# Search for the payment service file
find . -name "paymentService.ts" -o -name "paymentService.js" 2>/dev/null

Repository: ahmadmustafa02/CodePulse

Length of output: 105


🏁 Script executed:

cat -n ./server/src/utils/paymentService.ts

Repository: ahmadmustafa02/CodePulse

Length of output: 305


This payment function has two critical injection vulnerabilities.

Line 2 interpolates userId directly into SQL without parameterization, enabling SQL injection. Line 4 executes amount with eval(), enabling arbitrary code execution. Both untrusted inputs can be exploited by attackers. Use parameterized queries for the database call and parse/validate amount as numeric data instead of executing it.

🧰 Tools
🪛 Biome (2.4.15)

[error] 4-4: eval() exposes to security risks and performance issues.

(lint/security/noGlobalEval)

🪛 OpenGrep (1.20.0)

[ERROR] 4-4: eval() with dynamic input can execute arbitrary code. Avoid dynamic code evaluation entirely, or use a safe alternative.

(coderabbit.code-injection.eval-js)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/utils/paymentService.ts` around lines 1 - 4, The processPayment
function is vulnerable: avoid interpolating userId into the SQL and stop using
eval(amount). Change the db.query call (the query variable / db.query usage) to
a parameterized query (use placeholders / prepared statements and pass userId as
a parameter) and coerce/validate amount (replace eval(amount) with numeric
parsing and validation—e.g., parseFloat/Number and isFinite checks, ensure
amount >= 0) before using it; also tighten the processPayment signature types
(userId, amount) and return a validated numeric result or an error on invalid
input.

}
9 changes: 9 additions & 0 deletions server/src/utils/userService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export async function getUser(id: any) {
const user = await db.query(`SELECT * FROM users WHERE id = ${id}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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


🚨 [CRITICAL] SQL injection vulnerability

Category: security

Problem: The use of string concatenation to build SQL queries can lead to SQL injection attacks if the input is not properly sanitized.

Suggestion: Use a secure method to build SQL queries, such as using parameterized queries or an ORM.

const user = await db.query(`SELECT * FROM users WHERE id = ${id}`)

🤖 CodePulse AI Review

console.log(user)
return user
Comment on lines +1 to +4

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

find . -name "userService.ts" -type f 2>/dev/null

Repository: ahmadmustafa02/CodePulse

Length of output: 102


🏁 Script executed:

cat -n ./server/src/utils/userService.ts

Repository: ahmadmustafa02/CodePulse

Length of output: 383


Parameterize the lookup and stop logging full user records.

Line 2 is SQL-injectable as written—the id parameter is interpolated directly into the query string with no parameterization. Line 3 also dumps the entire user object to logs, which is a privacy and compliance risk if the row contains PII or secrets. Bind id as a query parameter and log only non-sensitive metadata if needed.

Note: The same SQL injection pattern exists in the deleteUser function (line 8).

🧰 Tools
🪛 OpenGrep (1.20.0)

[ERROR] 2-2: SQL query built via string concatenation or template literal passed to query()/execute(). Use parameterized queries instead.

(coderabbit.sql-injection.raw-query-concat-js)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/utils/userService.ts` around lines 1 - 4, The getUser function
currently interpolates id into the SQL string and logs the full user object;
change getUser to use a parameterized query / prepared statement (bind id as a
query parameter instead of string interpolation) and remove or replace
console.log(user) with logging only non-sensitive metadata (e.g., user id or a
success message). Apply the same fix to the deleteUser function so its DELETE
query binds id as a parameter rather than interpolating it, and avoid printing
full row contents to logs.

}

export function deleteUser(id: any) {
db.query(`DELETE FROM users WHERE id = ${id}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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


💡 [MEDIUM] Missing error handling

Category: error-handling

Problem: The delete query is not wrapped in a try-catch block, which can lead to unhandled promise rejections if an error occurs.

Suggestion: Wrap the delete query in a try-catch block to handle any potential errors.

db.query(`DELETE FROM users WHERE id = ${id}`)

🤖 CodePulse AI Review

Comment on lines +7 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

cat -n server/src/utils/userService.ts

Repository: ahmadmustafa02/CodePulse

Length of output: 383


🏁 Script executed:

# Also check if there's a database module to understand db.query behavior
find . -name "*db*" -o -name "*database*" | head -20

Repository: ahmadmustafa02/CodePulse

Length of output: 109


🏁 Script executed:

cat -n server/src/services/databaseService.ts

Repository: ahmadmustafa02/CodePulse

Length of output: 7265


🏁 Script executed:

# Check if there are parameterized query patterns elsewhere in the codebase
rg -A 3 "db\.query" server/src --max-count 20

Repository: ahmadmustafa02/CodePulse

Length of output: 1132


Make this helper async, await the delete, and use parameter binding instead of string interpolation.

Line 8 constructs the DELETE statement with direct interpolation of id, creating a SQL injection vulnerability. Additionally, the promise from db.query() is neither awaited nor returned, so callers cannot observe failures or completion. Compare with line 2's getUser() function in the same file—apply the same async pattern and use parameterized queries.

🧰 Tools
🪛 OpenGrep (1.20.0)

[ERROR] 8-8: SQL query built via string concatenation or template literal passed to query()/execute(). Use parameterized queries instead.

(coderabbit.sql-injection.raw-query-concat-js)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/utils/userService.ts` around lines 7 - 8, Make deleteUser follow
the same async/await and parameterized-query pattern as getUser: change function
deleteUser(id: any) to an async function, call and await db.query with a
parameter binding for the id (e.g., use a parameter placeholder instead of
string interpolation) and return or propagate the awaited result so callers can
observe completion/errors; ensure you reference the deleteUser function and
mirror the getUser async pattern for consistency.

}