| name | security-review |
| description | Comprehensive security review workflow for identifying vulnerabilities |
| license | MIT |
Security Review Skill
Use this skill when conducting security audits or reviewing code for vulnerabilities.
When to Use
- Before deploying to production
- After adding authentication/authorization
- When handling sensitive data
- Processing user input
- Integrating third-party services
- Regular security audits
Security Review Checklist
1. Authentication
if (password === user.password) { ... }
import bcrypt from 'bcrypt';
if (await bcrypt.compare(password, user.passwordHash)) { ... }
const token = jwt.sign(payload, 'secret123');
const token = jwt.sign(payload, process.env.JWT_SECRET, {
expiresIn: '1h',
algorithm: 'HS256',
});
2. Authorization
app.delete('/api/posts/:id', async (req, res) => {
await db.posts.delete(req.params.id);
});
app.delete('/api/posts/:id', authenticate, async (req, res) => {
const post = await db.posts.findById(req.params.id);
if (post.authorId !== req.user.id && req.user.role !== 'admin') {
return res.status(403).json({ error: 'Forbidden' });
}
await db.posts.delete(req.params.id);
});
3. Input Validation
app.post('/api/users', (req, res) => {
db.users.create(req.body);
});
import { z } from 'zod';
const CreateUserSchema = z.object({
email: z.string().email().max(255),
name: z.string().min(1).max(100),
age: z.number().int().min(0).max(150).optional(),
});
app.post('/api/users', (req, res) => {
const result = CreateUserSchema.safeParse(req.body);
if (!result.success) {
return res.status(422).json({ errors: result.error.issues });
}
db.users.create(result.data);
});
4. SQL Injection Prevention
const user = await db.query(
`SELECT * FROM users WHERE email = '${email}'`
);
const user = await db.query(
'SELECT * FROM users WHERE email = $1',
[email]
);
const user = await db.users.findOne({
where: { email },
});
5. XSS Prevention
element.innerHTML = userInput;
element.textContent = userInput;
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userInput);
return <div>{userInput}</div>;
<div dangerouslySetInnerHTML={{ __html: userInput }} />
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userInput) }} />
6. CSRF Protection
import csrf from 'csurf';
app.use(csrf({ cookie: true }));
app.get('/form', (req, res) => {
res.render('form', { csrfToken: req.csrfToken() });
});
app.post('/submit', (req, res) => {
});
7. Secrets Management
const API_KEY = 'sk_live_abc123xyz';
const DB_PASSWORD = 'password123';
const API_KEY = process.env.API_KEY;
const DB_PASSWORD = process.env.DB_PASSWORD;
if (!process.env.API_KEY) {
throw new Error('API_KEY environment variable is required');
}
8. Secure Headers
import helmet from 'helmet';
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", "'unsafe-inline'"],
styleSrc: ["'self'", "'unsafe-inline'"],
imgSrc: ["'self'", 'data:', 'https:'],
},
},
hsts: {
maxAge: 31536000,
includeSubDomains: true,
},
}));
9. Rate Limiting
import rateLimit from 'express-rate-limit';
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
message: { error: 'Too many requests' },
});
app.use('/api/', limiter);
const authLimiter = rateLimit({
windowMs: 60 * 60 * 1000,
max: 5,
});
app.use('/api/auth/login', authLimiter);
10. File Upload Security
import multer from 'multer';
import path from 'path';
const upload = multer({
limits: {
fileSize: 5 * 1024 * 1024,
},
fileFilter: (req, file, cb) => {
const allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (!allowedTypes.includes(file.mimetype)) {
return cb(new Error('Invalid file type'));
}
const ext = path.extname(file.originalname).toLowerCase();
if (!['.jpg', '.jpeg', '.png', '.gif'].includes(ext)) {
return cb(new Error('Invalid file extension'));
}
cb(null, true);
},
});
Security Scan Commands
npm audit
npm audit fix
npx gitleaks detect
npx eslint --plugin security src/
npx semgrep --config auto
Common Vulnerabilities (OWASP Top 10)
| Rank | Vulnerability | Prevention |
|---|
| 1 | Broken Access Control | Verify permissions on every request |
| 2 | Cryptographic Failures | Use strong algorithms, secure storage |
| 3 | Injection | Parameterized queries, input validation |
| 4 | Insecure Design | Threat modeling, security requirements |
| 5 | Security Misconfiguration | Secure defaults, remove debug features |
| 6 | Vulnerable Components | Regular updates, dependency scanning |
| 7 | Auth Failures | MFA, secure session management |
| 8 | Data Integrity Failures | Verify signatures, validate inputs |
| 9 | Logging Failures | Log security events, monitor |
| 10 | SSRF | Validate URLs, allowlist destinations |
Security Review Report Template
## Security Review: [Component/Feature]
### Scope
- Files reviewed: X
- Lines of code: Y
### Findings
#### Critical 🔴
1. [Finding description]
- Location: file:line
- Impact: [What could happen]
- Fix: [How to fix]
#### High ⚠️
...
#### Medium 💡
...
### Passed Checks ✅
- [ ] Authentication implemented correctly
- [ ] Authorization on all endpoints
- [ ] Input validation present
- [ ] No SQL injection vectors
- [ ] XSS prevention in place
- [ ] Secrets not in code
- [ ] Dependencies up to date
### Recommendations
1. [Action item]
2. [Action item]
Resources