OWASP Top 10 Cheatsheet
Quick reference for OWASP Top 10 vulnerabilities covering injection, broken auth, sensitive data, XXE, access control, misconfiguration, XSS, deserialization, components, and logging
57 commands
パラメータ化クエリUse prepared statements to prevent SQL injection
db.query('SELECT * FROM users WHERE id = ?', [userId])ORMの使用Use ORM instead of raw SQL to prevent injection
User.findOne({ where: { id: userId } })入力バリデーションValidate all user input with whitelist approach
if (!/^[a-zA-Z0-9]+$/.test(input)) throw Error()ストアドプロシージャUse stored procedures to prevent SQL injection
CALL get_user_by_id(@user_id)エスケープ処理Escape special characters to prevent injection
mysql.escape(userInput)NoSQLインジェクション対策Prevent $operator injection in MongoDB queries
sanitize-mongo: mongo-sanitize(req.body)LDAPインジェクション対策Escape special characters in LDAP queries
ldap.escape.filter(userInput)bcryptハッシュHash passwords with bcrypt before storing
bcrypt.hash(password, 12)多要素認証 (MFA)Implement TOTP-based two-factor authentication
speakeasy.totp.verify({ secret, token })セッション管理Regenerate session ID after authentication
req.session.regenerate(callback)レート制限Implement rate limiting to prevent brute force
express-rate-limit: { max: 5, windowMs: 15*60*1000 }パスワードポリシーEnforce strong password policy
zxcvbn(password).score >= 3アカウントロックアウトTemporarily lock account after consecutive failures
if (failCount >= 5) lockUntil = Date.now() + 30*60*1000HTTPS強制Force all communication over HTTPS
Strict-Transport-Security: max-age=31536000AES-256暗号化Encrypt sensitive data with AES-256-GCM
crypto.createCipheriv('aes-256-gcm', key, iv)TLS 1.2以上Allow only TLS 1.2 or higher
ssl_protocols TLSv1.2 TLSv1.3;機密データのマスキングMask sensitive data in logs and responses
card: '****-****-****-' + last4鍵管理Manage encryption keys with HSM or dedicated service
AWS KMS: aws kms encrypt --key-id alias/mykey外部エンティティ無効化Disable external entity processing in XML parser
factory.setFeature(DISALLOW_DOCTYPE, true)DTD無効化Completely disable DTD processing
libxml_disable_entity_loader(true)JSONの使用Use JSON format instead of XML where possible
Content-Type: application/jsonXMLバリデーションValidate XML input against XML Schema (XSD)
schema.validate(xmlDocument)SAST検出Detect XXE vulnerabilities with static analysis tools
semgrep --config=p/owasp-top-tenRBAC実装Implement role-based access control
@Roles('admin') @UseGuards(RolesGuard)JWTクレーム検証Verify JWT token claims on every request
jwt.verify(token, secret, { audience: 'api' })CORS設定Explicitly specify allowed origins
Access-Control-Allow-Origin: https://example.comIDOR防止Verify ownership when accessing object references
if (resource.ownerId !== req.user.id) return 403最小権限の原則Grant only the minimum required permissions
GRANT SELECT ON users TO readonly_roleデフォルト認証情報変更Change default passwords and admin accounts
ALTER USER admin SET PASSWORD 'strongP@ss!'不要なサービス無効化Disable unused ports and services
systemctl disable --now telnet.socketエラーメッセージ制御Hide stack traces in production
app.use((err, req, res, next) => res.status(500).json({error:'Internal'}))セキュリティヘッダー設定Set security headers using Helmet middleware
app.use(helmet())ディレクトリリスティング無効化Disable directory listing on web server
Options -Indexesサーバーバナー非表示Remove server information from HTTP response
server_tokens off;出力エンコーディングEncode output based on HTML context
DOMPurify.sanitize(userInput)CSP設定Set Content-Security-Policy header
Content-Security-Policy: default-src 'self'HttpOnly CookieSet HttpOnly flag on cookies
Set-Cookie: session=abc; HttpOnly; Secureテンプレートエンジンの自動エスケープEnable auto-escaping in template engine
{{ user.name | escape }}DOM操作の安全化Use textContent instead of innerHTML
element.textContent = userInputサニタイゼーションSanitize rich text input with whitelist approach
sanitizeHtml(input, { allowedTags: ['b','i','em'] })署名付きシリアライズAdd HMAC signature to serialized data
hmac = crypto.createHmac('sha256', secret).update(data)型チェックStrictly check types during deserialization
zod.object({ name: z.string(), age: z.number() }).parse(data)Javaデシリアライズ対策Filter Java ObjectInputStream deserialization
ObjectInputFilter.Config.setSerialFilter(filter)JSON Webトークン検証Explicitly specify JWT signature algorithm
jwt.verify(token, key, { algorithms: ['RS256'] })pickle回避Avoid Python pickle for untrusted data
json.loads(data) # instead of pickle.loads(data)npm auditScan Node.js dependencies for vulnerabilities
npm audit --productionSnykスキャンScan project vulnerabilities with Snyk
snyk test --all-projectsDependabot有効化Enable GitHub Dependabot for automatic security updates
dependabot.yml: schedule: interval: dailyOWASP Dependency-CheckDetect vulnerable libraries with OWASP Dependency-Check
dependency-check --project myapp --scan ./libTrivy コンテナスキャンScan container image vulnerabilities with Trivy
trivy image myapp:latestpip-auditScan Python dependencies for vulnerabilities
pip-audit --requirement requirements.txt認証イベントログAlways log authentication success and failures
logger.info('login_success', { userId, ip, timestamp })アクセスログ設定Configure detailed access logging
access_log /var/log/nginx/access.log combined;SIEM連携Send logs to SIEM for correlation analysis
filebeat -> Elasticsearch -> Kibanaアラート設定Set up alerts for anomalous activity
alert: login_failures > 10 in 5m -> notify監査ログRecord audit logs for permission changes and data access
auditLog.record({ action: 'delete', resource, actor })ログの改ざん防止Store logs in write-once storage to prevent tampering
aws s3api put-object-lock-configuration --bucket logs