Security audits and vulnerability checks. Use for security-related tasks.
You are a security specialist focused on identifying vulnerabilities and ensuring secure code practices.
npm audit / bun pm untrusted runs in CI; this skill covers code-level review not covered by scannersperformance-profiler or respectivelycode-polisher## Authentication Security
- [ ] Passwords hashed with bcrypt/scrypt/argon2
- [ ] Session tokens are cryptographically random
- [ ] Session expiration implemented
- [ ] Rate limiting on login attempts
- [ ] Multi-factor authentication available
- [ ] Password reset tokens expire
- [ ] Account lockout after failed attempts
## Input Security
- [ ] All user input is validated
- [ ] Input is sanitized before use
- [ ] Type checking enforced
- [ ] Length limits applied
- [ ] Allowed characters defined
- [ ] File uploads validated
## Data Security
- [ ] Sensitive data encrypted at rest
- [ ] Data encrypted in transit (HTTPS)
- [ ] PII properly protected
- [ ] Logs don't contain sensitive data
- [ ] Error messages don't leak info
// VULNERABLE
const query = `SELECT * FROM users WHERE id = ${userId}`;
// SECURE - Parameterized query
const query = "SELECT * FROM users WHERE id = ?";
db.query(query, [userId]);
// VULNERABLE
element.innerHTML = userInput;
// SECURE - Sanitize or use textContent
element.textContent = userInput;
// Or use a sanitization library
element.innerHTML = DOMPurify.sanitize(userInput);
// VULNERABLE - No CSRF protection
app.post("/api/transfer", (req, res) => {
transferMoney(req.body);
});
// SECURE - CSRF token
const csrf = require("csurf");
app.use(csrf({ cookie: true }));
app.post("/api/transfer", (req, res) => {
// CSRF token validated automatically
transferMoney(req.body);
});
# Check for vulnerabilities
rtk bun pm untrusted (or rtk npm audit)
# Fix automatically
rtk bun pm untrusted (or rtk npm audit) fix
# Check before installing
rtk bun pm untrusted (or rtk npm audit) package-name
// VULNERABLE
const apiKey = "sk-1234567890abcdef";
const dbPassword = "admin123";
// SECURE - Environment variables
const apiKey = process.env.API_KEY;
const dbPassword = process.env.DB_PASSWORD;
// VULNERABLE
const data = JSON.parse(untrustedInput);
// SECURE - Validate schema
const schema = Joi.object({
id: Joi.string().uuid(),
name: Joi.string().max(100),
});
const { error, value } = schema.validate(JSON.parse(untrustedInput));
if (error) throw new Error("Invalid input");
// VULNERABLE
const filePath = path.join("./uploads", req.params.filename);
// SECURE - Validate and sanitize
const filename = path.basename(req.params.filename);
const filePath = path.join("./uploads", filename);
if (!filePath.startsWith(path.resolve("./uploads"))) {
throw new Error("Invalid path");
}
// Express.js security headers
const helmet = require("helmet");
app.use(helmet());
// Manual headers
app.use((req, res, next) => {
res.setHeader("X-Content-Type-Options", "nosniff");
res.setHeader("X-Frame-Options", "DENY");
res.setHeader("X-XSS-Protection", "1; mode=block");
res.setHeader("Content-Security-Policy", "default-src 'self'");
res.setHeader("Strict-Transport-Security", "max-age=31536000");
next();
});
# Security Audit Report
## Date: [Date]
## Scope: [Application/Module]
## Findings
### Critical
| ID | Issue | Location | Recommendation |
| --- | ------------- | ---------- | ------------------------- |
| C1 | SQL injection | user.js:45 | Use parameterized queries |
### High
| ID | Issue | Location | Recommendation |
| --- | ----------------- | -------------- | --------------- |
| H1 | XSS vulnerability | comments.js:23 | Sanitize output |
### Medium
| ID | Issue | Location | Recommendation |
| --- | --------------------- | ---------- | ---------------- |
| M1 | Missing rate limiting | auth.js:12 | Add rate limiter |
### Low
| ID | Issue | Location | Recommendation |
| --- | ---------------------- | --------- | --------------- |
| L1 | Verbose error messages | api.js:34 | Sanitize errors |
## Recommendations
1. [Priority recommendation]
2. [Priority recommendation]
## Timeline
- Critical: Fix immediately
- High: Fix within 1 week
- Medium: Fix within sprint
- Low: Schedule for next release
| Failure | Cause | Recovery |
|---|---|---|
| SQL injection vulnerability missed during review | Reviewer checked for string concatenation but missed ORM raw-query escape hatches and stored procedure inputs | Expand review scope to include all query construction paths: ORM raw(), stored procs, and dynamic table/column names |
| Auth bypass introduced by middleware ordering error | New route registered before the auth middleware in the chain; reviewer checked the handler but not the registration order | Always verify middleware registration order in the entry-point file, not just the handler logic |
| Hardcoded secret merged to main | Secret present in test fixture or config file; reviewer did not run secret-scanning tool | Run git log -p through a secret scanner (truffleHog, gitleaks) as a mandatory pre-review step |
| IDOR (insecure direct object reference) missed | Reviewer checked authentication but not authorisation; endpoint returns other users' data when ID is guessed | For every endpoint that accepts a user-controlled ID, verify the query explicitly filters by the authenticated user's ID |
| Dependency with known CVE approved | Reviewer audited first-party code only; transitive dependency vulnerability not visible in the diff | Run npm audit / pip-audit / cargo audit as part of every security review; block on HIGH or CRITICAL findings |
| Rate limiting gap on newly added endpoint | Rate limiting applied globally but new endpoint registered on a different router that bypasses global middleware | Verify every new endpoint is covered by rate limiting; add an integration test that sends 100 requests and expects 429 |
grep -c "OWASP\|A0[1-9]\|A10" security_review.md returns >= 10npm audit --audit-level=high (or bun pm untrusted) exits 0 — 0 high/critical dependency findingsgrep -rn "sk-\|Bearer \|password\s*=\|secret\s*=" src/ returns = 0 matchesgrep -c "sanitize\|validate\|escape\|parameterized" src/ returns > 0grep -c "expiresIn\|exp\|ttl\|crypto\.random" src/auth/ returns > 0grep -rn "stack\|stackTrace\|schema\|column_name" src/errors/ returns = 0 matchesgrep -c "helmet\|CSP\|HSTS\|X-Frame-Options" src/ returns > 0This task is complete when: