The scripts/security-audit.js script performs comprehensive security checks on your AuthKit API according to your exact specifications.
What it checks: Verifies that the /api/refresh route sets httpOnly: true for refresh token cookies.
Pass: β
Refresh token cookie has httpOnly protection
Fail: β Critical: Refresh token cookie missing httpOnly! [FIX: npm run fix]
What it checks: Ensures JWT_EXPIRATION is not longer than 1800 seconds (30 minutes).
Pass: β
JWT expiration is 900 seconds (within 30 min limit)
Warn:
What it checks: Verifies that /api/me route exists and has authentication middleware.
Pass: β
/api/me route is properly protected with auth middleware
Fail: β Critical: Unprotected route! [FIX: Add auth middleware]
The npm run fix command automatically fixes common security issues:
-
httpOnly Cookie Fix
- Adds
httpOnly: trueto refresh token cookies - Modifies
backend/routes/auth.js
- Adds
-
JWT Expiration Fix
- Sets
JWT_EXPIRATION=900(15 minutes) in.envfile - Adds the setting if it doesn't exist
- Sets
- Exit Code 0: All security checks passed β
- Exit Code 1: Critical security issues found β
npm run auditnpm run fixnode scripts/security-audit.js --fixπ‘οΈ AuthKit Security Audit
β
Refresh token cookie has httpOnly protection
β
JWT expiration is 900 seconds (within 30 min limit)
β
/api/me route is properly protected with auth middleware
β
Security audit passed!
π‘οΈ AuthKit Security Audit
β Critical: Refresh token cookie missing httpOnly! [FIX: npm run fix]
β οΈ Warn: JWT expiration too long (30+ mins). Reduce to 15 mins.
β
/api/me route is properly protected with auth middleware
β Security audit failed - issues found!
π‘οΈ AuthKit Security Audit
β
Refresh token cookie has httpOnly protection
β
JWT expiration is 900 seconds (within 30 min limit)
β
/api/me route is properly protected with auth middleware
π§ Auto-fixing issues...
β
Fixed: Set JWT expiration to 900 seconds (15 mins)
β
Security audit passed!
backend/routes/auth.js- Refresh token route and cookie configurationbackend/middleware/cookieAuth.js- Cookie security middlewarebackend/routes/user.js- API route protection.env- JWT expiration configuration
- Refresh route:
/router\.post\s*\(\s*['"]/refresh['"]/gi - httpOnly cookie:
/httpOnly:\s*true/gi - Secure cookie function:
/setSecureRefreshTokenCookie/gi - /me route:
/router\.get\s*\(\s*['"]/me['"]/gi - Auth middleware:
/authenticateToken/gi
Add to your CI/CD pipeline:
# GitHub Actions example
- name: Security Audit
run: npm run audit
# This will fail the build if security issues are foundCurrent AuthKit security status:
- 3/3 checks passing β
- 0 critical issues β
- 0 warnings β
- Exit code: 0 β
π Your AuthKit API is secure and ready for production!