$ whoami && id && curl -I https://api.internal
Identity, Access & Web Security
// end-to-end trust boundaries & attack surface
System overview
// who are you, and how do you prove it?
Authentication, Passwords & MFA
Authentication (AuthN)
Verifies who the principal is (password, FIDO2, mTLS, OIDC id_token). Failure returns HTTP 401 Unauthorized.
Authorization (AuthZ)
Verifies what an authenticated principal may do on a specific resource (RBAC/ABAC, OAuth2 access_token). Failure returns HTTP 403 Forbidden.
| Primitive | Mechanic | Stops | Gotcha / Limit |
|---|---|---|---|
| Salt | Per-user random ≥128-bit value, stored in plaintext alongside the hash | Precomputed rainbow tables and detecting identical passwords across users | Does NOT slow offline cracking of a single dumped hash |
| Pepper | App-wide secret key (HMAC-SHA256 or AEAD) stored in HSM/KMS, never in the DB | Offline cracking after a DB-only leak (SQLi dump, stolen backup) | Compromised if attacker gets both DB and app/KMS secret; rotation requires key versioning |
| Argon2id (preferred) | Memory-hard KDF (OWASP min: m=19 MiB, t=2, p=1) | GPU/ASIC brute force by requiring RAM bandwidth + side-channel resistance (hybrid Argon2i/d) | Tune memory/iterations per hardware budget; verify with constant-time compare |
| bcrypt / PBKDF2 | Legacy KDFs (bcrypt cost ≥10; PBKDF2-HMAC-SHA256 ≥600k iters) | CPU brute force (bcrypt) or FIPS compliance (PBKDF2) | bcrypt silently truncates at 72 bytes and stops at NUL; PBKDF2 is weak against GPUs |
| MFA Factor | Mechanism | Phishing | Hard Reality |
|---|---|---|---|
| FIDO2 / WebAuthn (Passkeys) | Hardware/platform public-key signature bound to TLS origin (rpId) | Phishing-resistant | Browser enforces origin match; AitM reverse-proxy phishing fails cryptographically |
| TOTP / HOTP (Authenticator) | Shared secret + time step (30s) or counter → 6-digit HMAC-SHA1 | Phishable (AitM) | Real-time phishing proxy relays the code; DB leak exposes shared seeds unless encrypted |
| Push notification | Out-of-band approve tap on enrolled mobile device | MFA fatigue | Requires number matching + geo/app context to resist prompt bombing |
| SMS / Voice OTP | Code sent over PSTN/SS7 cellular network | Weakest | Vulnerable to SIM swap, SS7 interception, and social engineering of carriers |
// tokens, delegation & single sign-on
Sessions, OAuth 2.0, OIDC, JWT & SSO
code is useless without code_verifier. OAuth 2.0 delegates API access (access_token); OIDC adds AuthN on top (id_token JWT + nonce); SSO is the shared IdP session in step 2. Implicit grant is deprecated. Sources: OAuth 2.0, OIDC, JWT, SSO, OWASP Session Management.| Axis | Server-side Session (Cookie) | JWT (Stateless Token) |
|---|---|---|
| State & Revocation | Opaque ≥128-bit CSPRNG ID; server store (Redis/DB) → instant logout & revocation | Stateless signed token (JWS) → cannot revoke before exp without a denylist (which re-adds state) |
| Confidentiality | ID reveals nothing; payload stays server-side | JWS is Base64url-encoded plaintext (anyone can decode); encrypt with JWE if claims are sensitive |
| Key Pitfalls | Session fixation (must regenerate ID on login/privilege change); missing idle + absolute timeouts | alg: none, RS256→HS256 key confusion, kid path/SQL injection, skipping aud/iss/exp/nbf checks |
| Browser Storage | Cookie with Secure; HttpOnly; SameSite=Lax (or Strict) + __Host- prefix | localStorage is readable by any XSS; prefer BFF pattern (HttpOnly cookie) + short-lived access tokens + refresh rotation with reuse detection |
// least privilege & zero standing secrets
Access Control, Zero Trust, Cloud IAM & Secrets
| Concept | Core Rule | Hard Detail |
|---|---|---|
| RBAC | Permissions bound to roles (`admin`, `auditor`), users assigned to roles | Simple to audit, but suffers role explosion for fine-grained/tenant-scoped rules |
| ABAC / ReBAC | Decisions from attributes (owner, env, risk) or object relationship graphs (Zanzibar) | Solves object-level checks (IDOR) without role explosion; harder to audit statically |
| Least Privilege | Grant exact actions on exact resource ARNs/IDs for minimal duration (JIT) | AWS evaluation order: Explicit Deny > SCP/Boundary > Identity/Resource Allow > Implicit Deny |
| Zero Trust | Never trust network location (LAN/VPN ≠ trusted); verify identity + device + context per request | Enforce at PEP/PDP with mTLS, micro-segmentation, and short-lived credentials |
| Cloud IAM & Secrets | Zero long-lived keys: use OIDC federation / Pod Identity / STS; dynamic secrets from KMS/Vault | Never bake secrets into Git, images, or env dumps; support zero-downtime dual-key rotation |
// where boundaries break
Web & LLM Attack Primitives
| Attack | Broken Boundary | Hard Edge Cases | Real Fix |
|---|---|---|---|
| SQL Injection | Data crosses into SQL grammar | Second-order SQLi (stored payload runs later); ORDER BY/table identifiers cannot be bound; blind boolean/time extraction | Parameterized queries (prepared statements) everywhere + strict static allowlist for dynamic identifiers |
| XSS | Untrusted data parsed as DOM/JS | Reflected, Stored, DOM-based (innerHTML, eval), and mXSS (browser parser mutates sanitized HTML into executable JS) | Context-aware output encoding + Trusted Types + strict nonce-based CSP + HttpOnly cookies (limits theft, not actions) |
| CSRF | Cross-site request rides ambient cookies | SameSite=Lax still sends cookies on top-level GETs (never mutate on GET) and does not block same-site subdomains; text/plain skips CORS preflight | Per-session synchronizer token (or signed double-submit) + SameSite + Origin/Sec-Fetch-Site validation |
| CORS Misconfig | Server relaxes Same-Origin Policy read block | ACAO: * cannot pair with ACAC: true, so buggy servers reflect Origin, trust null (sandboxed iframe), or fail regex (evil-bank.com) | Exact static allowlist of trusted origins; never reflect Origin or allow null with Access-Control-Allow-Credentials: true |
| SSRF | Server coerced to make internal requests | Cloud metadata 169.254.169.254, DNS rebinding (TOCTOU between check and connect), HTTP 302 to 127.0.0.1, IPv6-mapped ::ffff:127.0.0.1 | IMDSv2 (PUT + hop-limit=1), network-layer egress allowlist, resolve-and-pin IP before connect, disable redirects |
| IDOR (BOLA) | Missing object-level authorization | Swapping /api/orders/1042 → /api/orders/1043; UUIDs slow guessing but are NOT authorization | Bind every data query to the authenticated principal (WHERE id = $1 AND owner_id = $subject) |
| Prompt Injection | Untrusted data shares LLM instruction stream | Direct (user override) and Indirect (poisoned web page, PDF, or email ingested by RAG/agent triggers unintended tool calls or exfiltration) | No 100% prompt-only fix: enforce least-privilege tools, isolate data vs control planes, require human approval for state-changing actions |