--- id: security-owasp-api-top10 title: OWASP API Top 10 — modern API security category: Coding status: draft source_trust_level: B verification_status: conceptual created_at: 2026-05-09 updated_at: 2026-05-09 tags: [security, api, vibe-coding] tech_stack: { language: "TS", applicable_to: ["Backend", "Security"] } applied_in: [] aliases: [OWASP API, BOLA, broken authorization, mass assignment, API security, 2023] --- # OWASP API Top 10 (2023) > API 의 가장 흔한 vulnerability. **BOLA, broken auth, mass assignment, ...**. ## 📖 핵심 개념 - 매 endpoint 가 attack surface. - Web OWASP 와 다름 (API-specific). - Access control 가 가장 흔한 problem. ## 💻 코드 패턴 ### API1: BOLA (Broken Object Level Authorization) ```ts // ❌ User A 가 User B 의 data 가져옴 app.get('/api/users/:id', (req, res) => { const user = await db.users.findById(req.params.id); res.json(user); }); // ✅ Authorization check app.get('/api/users/:id', (req, res) => { const user = await db.users.findById(req.params.id); if (user.id !== req.user.id && !req.user.isAdmin) { return res.status(403).json({ error: 'forbidden' }); } res.json(user); }); ``` → 가장 흔한 API bug. Object 의 ownership 검증. ### API2: Broken Authentication ```ts // ❌ Weak password / no rate limit app.post('/login', async (req, res) => { const user = await db.users.findOne({ email: req.body.email }); if (user && user.password === req.body.password) { return res.json({ token: '...' }); } }); // ✅ app.post('/login', rateLimit({ max: 5 }), async (req, res) => { const user = await db.users.findOne({ email: req.body.email }); if (user && await bcrypt.compare(req.body.password, user.passwordHash)) { return res.json({ token: signJWT(user) }); } await sleep(1000); // timing attack 방지 res.status(401).json({ error: 'invalid' }); }); ``` → Bcrypt + rate limit + 시간 const. ### API3: BOPLA (Broken Object Property Level Authorization) ```ts // ❌ User 가 자기 role 변경 app.patch('/api/users/:id', async (req, res) => { await db.users.update(req.params.id, req.body); }); // → req.body 가 { role: 'admin' } 일 수. // ✅ Whitelist const ALLOWED = ['name', 'email', 'avatar']; const update = pick(req.body, ALLOWED); await db.users.update(req.params.id, update); ``` → Mass assignment 방지. ### API4: Unrestricted Resource Consumption ```ts // ❌ 무한 result app.get('/api/items', async (req, res) => { const items = await db.items.find({}); // 매 item. res.json(items); }); // ✅ Pagination + limit app.get('/api/items', async (req, res) => { const limit = Math.min(Number(req.query.limit) || 50, 100); const items = await db.items.find({}).limit(limit); res.json(items); }); ``` ### API5: Broken Function Level Authorization ```ts // ❌ Admin endpoint 가 admin check 안 app.delete('/api/users/:id', (req, res) => { await db.users.delete(req.params.id); }); // ✅ app.delete('/api/users/:id', requireAdmin, (req, res) => { await db.users.delete(req.params.id); }); function requireAdmin(req, res, next) { if (!req.user?.isAdmin) return res.status(403).end(); next(); } ``` ### API6: Unrestricted Access to Sensitive Business Flows ```ts // ❌ 1 user 가 매 product 의 1 차 buy. // → Reseller bot 가 모두 buy. // ✅ Per-user limit + CAPTCHA + behavior detect if (await purchaseCount(req.user.id, productId, '1h') > 1) { return res.status(429).end(); } ``` → Business logic abuse. ### API7: Server-Side Request Forgery (SSRF) ```ts // ❌ User 가 임의 URL fetch app.post('/api/preview', async (req, res) => { const r = await fetch(req.body.url); res.json(await r.text()); }); // → http://169.254.169.254/ (AWS metadata). // → http://localhost/admin. // ✅ Whitelist + DNS resolve check const url = new URL(req.body.url); if (!ALLOWED_HOSTS.includes(url.host)) return res.status(400).end(); const ip = await dns.resolve(url.host); if (isPrivateIP(ip)) return res.status(400).end(); const r = await fetch(req.body.url); ``` ### API8: Security Misconfiguration ``` - Debug mode in production. - Default credentials. - CORS '*' (production). - TLS 약 (1.0, 1.1). - Verbose error message. - No security header. → Helmet (Node), Rails defaults, etc. ``` ```ts import helmet from 'helmet'; app.use(helmet()); ``` ### API9: Improper Inventory Management ``` - v1 API 가 deprecated 가 still up. - Test endpoint 가 production. - 매 endpoint 의 schema doc. → OpenAPI spec + audit. ``` ### API10: Unsafe Consumption of APIs ```ts // ❌ External API 의 response 가 trust const user = await externalAPI.getUser(id); const html = `