The authoritative list of critical web application security risks. Every developer must know these. Read →
| Risk | Prevention |
|---|---|
| Broken Access Control | Verify authorization on every request; never trust client roles |
| Cryptographic Failures | bcrypt for passwords; encrypt PII at rest; TLS everywhere |
| Injection | Parameterized queries; never concatenate user input into SQL |
| Security Misconfiguration | Disable debug mode; remove default credentials; set security headers |
| Vulnerable Components | npm audit; Dependabot; update regularly |
| Auth Failures | Rate-limit login; strong passwords; MFA; short sessions |
npm install helmet
import helmet from 'helmet';
app.use(helmet()); // Applies all defaults: CSP, HSTS, X-Frame-Options, etc.
// Or customize:
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", "https://www.googletagmanager.com"],
styleSrc: ["'self'", "'unsafe-inline'"],
}
},
hsts: { maxAge: 31536000, includeSubDomains: true, preload: true }
}));
import cors from 'cors';
app.use(cors({
origin: (origin, callback) => {
const allowed = ['https://yourapp.com', 'https://www.yourapp.com'];
if (!origin || allowed.includes(origin)) callback(null, true);
else callback(new Error('CORS: not allowed'));
},
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE'],
}));
npm audit # Check for vulnerabilities
npm audit fix # Auto-fix safe updates
# GitHub Dependabot (.github/dependabot.yml):
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule: { interval: "weekly" }
open-pull-requests-limit: 10
.env in .gitignore