Part 05 · Practice · 5.3

Lab API, networking và security

Chín lab biến semantics thành evidence: contract snapshots, concurrent outcomes, timing waterfall, token validation, exploit regression và incident timeline.

Definition of done chung: ghi version/config, fixture và threat boundary; chạy cả happy path lẫn failure path; lưu command/trace/response đã redacted; có regression assertion và kết luận trade-off.
Lab 01 · Contract

OpenAPI contract

Thiết kế Order API với resource URI, status, RFC 9457 errors, cursor pagination, filtering allow-list, ETag và schema backward-compatible.

  • Deliver: OpenAPI, examples, contract tests.
  • Gate: required/null/unknown fields và 4xx/5xx mapping rõ.
Lab 02 · Idempotency

Idempotent payment

POST /payments nhận Idempotency-Key; lưu fingerprint/state/result atomically; test concurrent duplicate, crash sau charge trước response, cùng key khác payload và TTL.

  • Deliver: state machine, unique constraint, replay evidence.
  • Gate: không double-charge và unknown outcome được reconcile.
Lab 03 · Resilience

Timeout budget

Dựng client→gateway→service→DB/mock downstream. Cấu hình connect/read/overall deadline, retry một tầng có jitter; trace timeline và tạo retry storm rồi sửa.

  • Deliver: waterfall trace, budget table, load comparison.
  • Gate: retry dừng theo deadline, pool/queue bounded.
Lab 04 · OAuth

OAuth/OIDC flow

Chạy authorization server local, Authorization Code + PKCE cho frontend, resource server validate issuer/audience/scope. Test expired token, wrong audience, key rotation và object authorization.

  • Deliver: flow trace, negative tests, JWKS overlap.
  • Gate: ID token không được dùng như access token.
Lab 05 · Threats

OWASP attack lab

Tạo rồi sửa BOLA, mass assignment, SQL injection, SSRF, unrestricted payload/page size, CORS sai và XSS output. Mỗi lỗi có regression test.

  • Deliver: exploit fixture, patch, test and residual risk.
  • Gate: authorization/data-boundary test không chỉ UI test.
Lab 06 · Operations

Security operations

Rate limit theo principal/operation, structured audit log có redaction, secret từ external store/env, security headers và dependency scan.

  • Deliver: policy config, log samples, scan report.
  • Gate: token/cookie/secret không xuất hiện trong log.
Lab 07 · Forensics

Network waterfall

Dựng DNS/proxy/service với artificial DNS, connect, TLS và upstream delays. Thu timing từng phase, stale keepalive/reset và forwarded-header spoof; viết timeout budget.

  • Deliver: phase timings, trusted-proxy policy.
  • Gate: xác định hop gây P99 thay vì chỉ nhìn CPU.
Lab 08 · Browser

Browser security

Dựng hai origins, thử simple/preflight credentialed CORS, CSRF cookie request, reflected/DOM XSS và CSP Report-Only→enforce.

  • Deliver: headers, browser traces, regression tests.
  • Gate: phân biệt response-read với request-send.
Lab 09 · Incident

Key rotation & drill

Rotate JWT signing key với JWKS overlap, revoke refresh family khi reuse, mô phỏng leaked credential; thu audit timeline, redact logs và thực hiện containment/recovery runbook.

  • Deliver: timeline, runbook, revoke/rollback evidence.
  • Gate: rotate không downtime và recovery invariant pass.