AuthN vs AuthZ
Authentication (AuthN) = who you are (validate identity). Authorization (AuthZ) = what you are allowed to do (enforce permissions on actions/resources).
CIA triad
Confidentiality (prevent data leaks), Integrity (prevent unauthorized changes), Availability (keep service usable). Security decisions usually trade off among these.
Least privilege
Grant only the minimum permissions needed (IAM policies, DB roles, app permissions). Reduce blast radius if credentials are leaked.
Trust boundary
A point where data crosses from a less-trusted zone to a more-trusted one (client→API, service→service, API→DB). Re-validate/authorize at each boundary.
Defense in depth
Use multiple independent layers (network controls + IAM + app authz + validation + logging). Assume one layer can fail.
What is OWASP Top 10 used for?
A reference list of common web app/API risk categories (e.g., broken access control, injection, misconfiguration). Useful as a checklist for reviews.
Broken Access Control (example)
IDOR: user accesses /accounts/123 and can see another user’s data by guessing IDs. Fix: authorize access to the specific resource (ownership/tenant checks).
IDOR prevention
Never trust only the resource ID. Always check ownership/tenant match server-side. Prefer opaque IDs when possible (still must authorize).
SQL injection prevention
Use parameterized queries/prepared statements. Avoid string concatenation for SQL. Validate/allowlist dynamic sort fields and column names.
Sensitive data exposure prevention
TLS for in-transit, encryption at rest, strict access controls, minimize data returned, avoid logging secrets/PII, and strong key management.
Security misconfiguration examples
Publicly accessible databases, overly permissive security groups, default credentials, verbose error pages, missing security headers.
SSRF (what is it?)
Server-Side Request Forgery: attacker makes your server fetch internal/privileged URLs (metadata endpoints, internal services). Prevent with allowlists, egress controls, and URL validation.
Input validation principle
Validate at boundaries (controller DTO validation + business rules). Prefer allowlists over blocklists (e.g., enum values).
Do not trust client claims
Never accept roles/tenant IDs from request body; derive them from the validated token or server-side lookup.
Encryption in transit
Use HTTPS/TLS for client↔API and ideally TLS/mTLS for service↔service in sensitive environments.
Encryption at rest
Encrypt DB/storage (e.g., RDS encryption, EBS, S3 SSE). Ensure backups and snapshots are encrypted too.
Token vs session (high level)
Sessions often use cookies and server-side state; tokens (JWT) are usually stateless and validated on each request.
JWT is not encrypted
JWT payload is Base64URL-encoded, not encrypted by default. Never put secrets in JWT claims.
JWT must-validate checklist
Validate signature, expiration (exp), issuer (iss), audience (aud), and token not-before (nbf) if used. Reject tokens with weak/none algorithms.
JWT key rotation
Use key IDs (kid) and rotate signing keys. Services should fetch keys from a JWKS endpoint and cache with TTL.
OAuth2 in one sentence
A framework for delegated authorization. APIs often act as ‘resource servers’ validating access tokens issued by an Identity Provider.
Scopes vs roles
Scopes are typically OAuth2 permissions for an app/client (e.g., read:orders). Roles are user/group permissions. Many systems map both into authorities.
Access token vs refresh token
Access token: short-lived, used on requests. Refresh token: longer-lived, used to obtain new access tokens (should be stored/handled very carefully).
Why short-lived tokens?
Limits damage if token is stolen. Combine with rotation and revocation strategies where needed.