Web Security Checklist
Security checklist I use for every project:
Authentication & Authorization
- Use strong password requirements
- Implement proper session management
- Use JWT tokens with short expiration
- Implement refresh token rotation
- Add rate limiting to auth endpoints
- Use HTTPS everywhere
- Implement proper logout functionality
Input Validation
// Always validate and sanitize input
const validateEmail = (email) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email) && email.length <= 254;
};
// Use parameterized queries
const getUser = async (userId) => {
return await db.query('SELECT * FROM users WHERE id = $1', [userId]);
};
Security Headers
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],
scriptSrc: ["'self'"],
imgSrc: ["'self'", "data:", "https:"]
}
},
hsts: {
maxAge: 31536000,
includeSubDomains: true
}
}));
OWASP Top 10 Prevention
- Injection - Use parameterized queries
- Broken Authentication - Implement proper auth
- Sensitive Data Exposure - Encrypt data at rest/transit
- XML External Entities - Disable XML external entity processing
- Broken Access Control - Implement proper authorization
- Security Misconfiguration - Regular security audits
- XSS - Sanitize output, use CSP
- Insecure Deserialization - Validate serialized data
- Known Vulnerabilities - Keep dependencies updated
- Insufficient Logging - Implement comprehensive logging