OWASP Top 10 (2021)
- Broken Access Control
- Cryptographic Failures
- Injection
- Insecure Design
- Security Misconfiguration
- Vulnerable Components
- Identification & Auth Failures
- Software & Data Integrity
- Logging & Monitoring Failures
- SSRF
SQL Injection ⭐
input: " OR 1=1 --
SELECT * FROM users WHERE name="" OR 1=1 --" // returns ALL!
❌ $sql = "SELECT * WHERE name='$name'";
✅ $stmt = $pdo->prepare("SELECT * WHERE name=?");
$stmt->execute([$name]);
✅ ORM — auto parameterized
XSS (Cross-Site Scripting)
// Stored: comment = "<script>steal(cookie)</script>"
// ✅ Encode output
{{ comment }} // Vue/Angular auto-escape
${escapeHtml(comment)}
// ❌ innerHTML, v-html, dangerouslySetInnerHTML
CSP ⭐
Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline';
CSRF
// Attacker site auto-submits form to bank.com // Victim logged in → cookies sent → transfer! ✅ CSRF token per session ✅ SameSite=Strict cookie ✅ Custom header (X-CSRF)
IDOR
// /api/orders/123 → /api/orders/124 → other user's data! ✅ Auth check if (order.UserId != currentUserId) throw ForbiddenException();
Security Misconfig
- Default creds (admin/admin)
- Verbose errors (stack trace)
- Debug mode in prod
- Old versions, open S3 bucket
- Permissive CORS
Security Headers
Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff X-Frame-Options: DENY Referrer-Policy: strict-origin-when-cross-origin Permissions-Policy: geolocation=(), camera=()
Vulnerable Components
npm audit, Snyk, Dependabot, OWASP Dependency-Check, SBOM।
SSRF
// img_url = "http://169.254.169.254/..." (AWS metadata!) ✅ Allowlist domains, block private IPs
Mindset
- Defense in depth
- Least privilege
- Fail secure
- Don't trust input
- Encrypt sensitive data
- Log security events
- Patch regularly