Why API Security Matters
APIs are the core of modern applications. OWASP updated the API Security Top 10 in 2023.
API1:2023 — Broken Object Level Authorization (BOLA)
This is the most common and most critical vulnerability.
Vulnerable code
// GET /api/orders/{orderId}
app.get('/api/orders/:orderId', async (req, res) => {
// 문제: 현재 사용자 소유 여부 확인 없음
const order = await Order.findById(req.params.orderId);
res.json(order);
});Fixed code
app.get('/api/orders/:orderId', authenticate, async (req, res) => {
const order = await Order.findOne({
_id: req.params.orderId,
userId: req.user.id // 소유자 검증 필수
});
if (!order) return res.status(403).json({ error: 'Forbidden' });
res.json(order);
});API2:2023 — Broken Authentication
Secure JWT configuration
import jwt from 'jsonwebtoken';
const token = jwt.sign(
{ userId: user.id },
process.env.JWT_SECRET,
{ algorithm: 'HS256', expiresIn: '1h' }
);
// 검증 시 알고리즘 명시 필수
const decoded = jwt.verify(token, process.env.JWT_SECRET, {
algorithms: ['HS256']
});API3:2023 — Broken Object Property Level Authorization
// 잘못된 예: 전체 객체 반환
res.json(user); // password_hash, internal_id 등 포함
// 올바른 예: 필요한 필드만 선택
const { id, name, email } = user;
res.json({ id, name, email });API4:2023 — Unrestricted Resource Consumption
import rateLimit from 'express-rate-limit';
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
message: { error: 'Too many requests' }
});
app.use('/api/', limiter);API5–10: Key Takeaways
| Rank | Vulnerability | Key mitigation |
|---|---|---|
| API5 | Function Level Authorization | Role-based access control (RBAC) |
| API6 | Unrestricted Business Flows | Rate limiting on business logic |
| API7 | Server Side Request Forgery | Validate against a URL allowlist |
| API8 | Security Misconfiguration | Disable unused HTTP methods |
| API9 | Improper Inventory Management | API version management |
| API10 | Unsafe Consumption of APIs | Validate third-party API responses |
API security must start in the development phase. Fixing issues after deployment costs 10–100× more.
References: Official Documentation
The primary sources for the behavior, configuration, and errors covered in this article are the official documents below. Check them for version-specific options and exact behavior.
Nodelog는 모든 콘텐츠의 내용과 출처를 공개 전에 검토합니다. 환경(OS·버전)에 따라 결과가 달라질 수 있는 기술 정보는 공식 문서와 함께 확인하며, 검토 기준과 정정 원칙은 편집 정책에서 안내합니다. 오류를 발견하시면 이메일로 제보해 주세요 — 확인 후 신속히 정정합니다.
Comments
Be the first to comment.