Threat model theo OWASP API Security
OWASP API Security không chỉ là authentication. Hãy map từng risk vào object, property, function, resource cost, business flow, inventory và downstream trust boundary.
1. BOLA và object-level authorization
Broken Object Level Authorization xảy ra khi object ID từ client được đổi để đọc/sửa object khác. UUID khó đoán không phải authorization control. Query phải scope principal/tenant ngay tại data boundary và kiểm tra action cụ thể.
SELECT * FROM orders
WHERE id = :requestedId
AND tenant_id = :authenticatedTenant
AND owner_id = :principal;
2. Authentication và property-level policy
Credential stuffing, weak recovery, token validation sai, token quá dài và thiếu rate limit tạo broken authentication. Dùng MFA/risk controls, secure reset, lifecycle/revocation và generic errors. Property-level authorization chống mass assignment (client sửa role/status/owner) và excessive data exposure; request/response DTO phải explicit field policy.
3. Function-level authorization
Ẩn admin route hoặc nút UI không phải control. Policy server-side phải deny-by-default cho method/function, kiểm tra alternate HTTP verbs, content types và API versions. Test cả endpoint không nằm trong menu, batch/export và debug route.
4. Unrestricted resource consumption
Payload, page, filter, report, upload và parallel requests đều có thể tiêu CPU, memory, storage hoặc paid-provider calls. Rate limit global không đủ; quota phải cost-aware theo identity/IP/resource/tenant.
| Surface | Control |
|---|---|
| Body/upload | Max bytes, content type, decompression ratio, virus scan và streaming limit |
| Query/report | Allow-list, max depth/joins, timeout, result cap và async job quota |
| Concurrency | Per-principal/tenant semaphore, queue bound, backpressure và circuit breaker |
| Paid dependency | Budget theo operation, cache/aggregation và kill switch |
5. Sensitive business flows
Scalping, spam signup, fake account hoặc checkout abuse có thể dùng request hợp lệ nên không bị bắt bởi schema validation. Kết hợp business rate limits, device/risk signals, friction/challenge, velocity rules và anomaly detection; đo false positive và có manual recovery.
6. SSRF và outbound trust
Endpoint fetch URL do attacker chọn có thể truy metadata hoặc internal service. Allow-list scheme/host/port, canonicalize và resolve DNS; chặn private/link-local ranges ở mọi redirect, egress firewall, response size/time limit và không gửi credential nội bộ. DNS rebinding yêu cầu validate resolved destination ngay trước connect.
7. Misconfiguration và inventory
Debug endpoint, default credential, permissive CORS/TLS/header, cloud permission rộng và secret trong config mở rộng attack surface. Version cũ, shadow host và undocumented API vẫn phải được inventory. Dùng secure defaults, IaC/dependency scanning, deprecation telemetry và retirement evidence.
8. Unsafe API consumption
Response từ partner API vẫn là untrusted input. Validate schema/size, timeout, sanitize theo output context, authenticate đúng endpoint và review dependency/supply chain. Downstream compromise có thể biến response thành injection, SSRF hoặc resource exhaustion ở service của bạn.