You are performing a comprehensive security audit of this codebase. The code was generated with AI assistance and may contain common security vulnerabilities introduced by vibe coding patterns.
Audit the entire codebase against the 20 security parameters below. For each issue found:
- Identify the exact file(s) and line number(s) where the vulnerability exists
- Explain why it is a security risk in 1-2 sentences
- Fix it — provide the corrected code inline, not just a description
- Verify no other instances of the same pattern exist elsewhere in the codebase
Work through all 20 parameters systematically. Do not skip any. If a parameter does not apply to this codebase, state "Not applicable — [reason]".
- Search all client-side JS/TS files for API keys, tokens, secrets, or credentials
- Look for:
apiKey,secret,token,password,keyassigned to string literals - Fix: Move all secrets to backend environment variables, expose only via server-side API calls
- Check
/login,/register,/forgot-password,/reset-password, and any token endpoints - Fix: Add rate limiting (max 5 attempts per IP per 15 minutes) + lockout mechanism
- Search for any query built with string concatenation or template literals containing user input
- Look for:
"SELECT" +,`SELECT ${`,query + userId, etc. - Fix: Replace with parameterized queries or ORM methods only
- Check all CORS configuration for
origin: "*"orAccess-Control-Allow-Origin: * - Fix: Whitelist specific allowed origins from environment variables
- Search client-side code for
localStorage.setItemstoring tokens, JWTs, or session data - Fix: Move to httpOnly, Secure, SameSite=Strict cookies set by the server
- Check JWT signing configuration for hardcoded secrets or weak values
- Look for:
secret: "secret",secret: "password", short strings, tutorial defaults - Fix: Generate a 256-bit random secret, load from environment variable, document rotation procedure
- Identify any admin, dashboard, or privileged routes
- Verify each has server-side middleware enforcing authentication and authorization
- Fix: Add auth middleware to every protected server route — React Router guards are not security
- Run:
git log --all --full-history -- .env .env.local .env.production - Also check
.gitignoreto confirm all env files are excluded - Fix: If found in history, rotate every key immediately. Add
.env*to.gitignore
- Search error handlers for responses that include
error.stack,error.message, table names, file paths - Fix: Log full errors server-side only. Return generic
{"error": "Internal server error"}to clients
- Check all file upload endpoints for validation logic
- Extension checks alone are insufficient — validate actual MIME type server-side
- Fix: Use a library like
file-typeto validate MIME type from file buffer, not filename
- Search for any use of
md5,sha1,sha256for password hashing - Fix: Use
bcrypt(cost factor ≥ 12) orargon2. Never implement your own hashing
- Check JWT and session token configuration for expiry settings
- Look for missing
expiresIn,exp, or overly long expiry (> 24h for access tokens) - Fix: Access tokens ≤ 15 minutes, refresh tokens ≤ 7 days with rotation on use
- List every single API route in the codebase
- Verify each route that accesses user data or performs actions has auth middleware applied
- Fix: Audit every route. Apply middleware at the router level, not just individual routes
- Check Dockerfile, docker-compose, and process configuration for user settings
- Look for missing
USERdirective in Dockerfiles - Fix: Add
USER node(or equivalent non-root user) to all Dockerfiles
- Check docker-compose port mappings for database services
- Look for
5432:5432,3306:3306,27017:27017with no network restrictions - Fix: Remove public port mappings for databases. Use internal Docker networks only
- Identify all endpoints that accept a resource ID parameter (
/users/:id,/orders/:id, etc.) - Verify each checks that the authenticated user owns or has permission to access that resource
- Fix: Add ownership validation on every resource endpoint — never trust the ID alone
- Check server configuration, nginx/caddy config, and middleware for HTTP→HTTPS redirect
- Fix: Redirect all HTTP traffic to HTTPS at the server/proxy level
- Check logout handler — does it invalidate the session/token server-side?
- Client-side cookie clearing is not sufficient
- Fix: Maintain a token blocklist or invalidate session in database on logout
- Run
npm auditin all packages (root, client, server, shared) - List all critical and high severity vulnerabilities found
- Fix: Run
npm audit fixwhere safe. Document any that require manual intervention
- Search for any redirect logic that uses user-supplied URLs
- Look for:
res.redirect(req.query.returnTo),window.location = params.redirect, etc. - Fix: Validate all redirect destinations against a whitelist of allowed URLs. Never redirect to arbitrary user-supplied URLs
For each of the 20 parameters, structure your response as:
## [N]. [Parameter Name]
**Status**: VULNERABLE / CLEAN / NOT APPLICABLE
**Location**: [file:line or "N/A"]
**Issue**: [1-2 sentence description]
**Fix**: [corrected code or commands]
After completing all 20, provide:
- Total vulnerabilities found
- Critical (fix before deploying): list
- High (fix this week): list
- Informational (good practice): list
- Recommended deployment blockers
- Do not just describe fixes — implement them
- Check every file, not just obvious ones — AI-generated code often puts auth logic in unexpected places
- If you find one instance of a pattern, search the entire codebase for others
- Some vulnerabilities interact — note dependencies (e.g., fixing #5 may affect #12 and #18)
- After all fixes, do a final pass to confirm no new issues were introduced