Quick reference for common security concerns when building web applications.
- Validate all user input on the server side (never trust client-side validation alone)
- Use allowlists (whitelist valid values) over blocklists
- Validate type, length, format, and range
- Sanitize input before storing or displaying (prevent XSS)
- Never store passwords in plain text — use bcrypt or argon2
- Use established auth libraries/OAuth providers instead of rolling your own
- Implement password strength requirements
- Use multi-factor authentication (MFA) for sensitive operations
- Set reasonable session expiry times
- Invalidate tokens on logout
- Check permissions on every request, not just in the UI
- Use the principle of least privilege — give users only the access they need
- Never expose internal IDs if users can guess other users' resources (use UUIDs or check ownership)
| # | Risk | Quick fix |
|---|---|---|
| A01 | Broken Access Control | Check authorization on every endpoint |
| A02 | Cryptographic Failures | Use HTTPS, encrypt sensitive data at rest |
| A03 | Injection (SQL, XSS) | Use parameterized queries, escape output |
| A04 | Insecure Design | Threat model during design phase |
| A05 | Security Misconfiguration | Disable default accounts, hide error details |
| A06 | Vulnerable Components | Keep dependencies updated |
| A07 | Auth Failures | Use strong password hashing, rate limit logins |
| A08 | Data Integrity Failures | Validate deserialized data, check file integrity |
| A09 | Logging & Monitoring Gaps | Log auth events, monitor for anomalies |
| A10 | SSRF | Validate and restrict outbound requests |
Never do this:
SELECT * FROM users WHERE email = '${email}'Always do this (parameterized):
SELECT * FROM users WHERE email = ?Or use an ORM/query builder that parameterizes automatically.
- Escape all user-generated content before rendering in HTML
- Use Content Security Policy (CSP) headers
- Use
textContentinstead ofinnerHTMLwhen possible - Set cookies with
HttpOnlyandSecureflags
- Never commit secrets (API keys, passwords, tokens) to git
- Use
.envfiles for local development (add.envto.gitignore) - Use environment variables in production
- Rotate secrets periodically
- Use a secrets manager (AWS Secrets Manager, HashiCorp Vault) for production
- Use HTTPS everywhere
- Rate limit your APIs to prevent abuse
- Validate
Content-Typeheaders - Return generic error messages (don't leak stack traces or internal details)
- Use CORS headers intentionally, not
*
- No secrets in code or git history
- All endpoints have authentication where needed
- All user input is validated and sanitized
- HTTPS is enforced
- Error pages don't expose internal details
- Dependencies are up to date
- Rate limiting is in place
- Logging covers auth events (logins, failures, permission changes)