pgjssg/postgres · PR #987
fix: SQL injection in user lookup
pending [TEST] 5 comments by @JaneDeveloper ↗ View on GitHub
🧪 This is a synthetic test review. Approving comments will NOT post to GitHub — it just confirms the pipeline works end-to-end.
📄 db/user-queries.js
line 28 (RIGHT)
**[CRITICAL] SQL injection vulnerability**\n\nUser input `req.params.id` is concatenated directly into the SQL query. This allows attackers to manipulate query logic or exfiltrate data. Use parameterized queries.\n\n```js\n// Fix: use $1 parameter\nconst result = await pool.query('SELECT * FROM users WHERE id = $1', [req.params.id]);\n```
line 45 (RIGHT)
**[HIGH] Password stored in plain text**\n\nThe `password` column is compared using `===` against plain text. Use bcrypt to hash passwords before storage and comparison.
line 58 (RIGHT)
**[MEDIUM] Missing rate limiting on auth endpoint**\n\nThis endpoint has no rate limit. An attacker can brute-force credentials without restriction. Add per-IP rate limiting (e.g., 5 attempts/minute).
line 71 (RIGHT)
**[LOW] Session token has no expiry**\n\nSessions are created without an expiration time. Tokens may remain valid indefinitely if the user does not log out. Set `expiresIn` on the JWT.
line 83 (RIGHT)
**[MEDIUM] CORS allows all origins**\n\n`Access-Control-Allow-Origin: *` is overly permissive for an authenticated endpoint. Restrict to known origins only.