80%
DefinitionAuthentication = who are you? (login).
RBAC: permissions by role (admin, doctor, patient).
Always check ownership too: "can this user see *this* order?" — missing checks cause IDOR bugs.
Authorize on the server for every request; hiding a button is not security.
Use slow, salted algorithms: argon2id or bcrypt.
Rate-limit login and OTP endpoints; lock out or add delays after failures.
Same error for "no such user" and "wrong password" (no user enumeration).
Offer MFA (TOTP / passkeys) for sensitive apps.
State: stored on the server (Redis/DB); cookie holds only an id · claims inside a signed token
Logout / revoke: easy: delete the session · hard: valid until it expires
Scaling: needs a shared store · any server can verify the signature
Best for: classic web apps · APIs, mobile, microservices
FlowAccess + refresh token patternLogin→Short access token (15 min) + refresh token (httpOnly cookie)→Access expires→POST /refresh → rotate refresh token→Logout → revoke refresh token
Common mistakeJWTs are signed, not encrypted — never put secrets in the payload.
OAuth 2.0 lets an app act on a user's behalf without their password (authorization).
App redirects to the provider with
client_id, redirect_uri, scope, state and a PKCE challenge.User logs in and consents.
Provider redirects back with a one-time
code.Server exchanges the code (+ PKCE verifier) for tokens.
TipUse the Authorization Code flow with PKCE;
state protects against CSRF on the callback.XSS: attacker script runs in your page · escape output (React does), avoid dangerouslySetInnerHTML or sanitise (DOMPurify), CSP, httpOnly cookies
CSRF: another site makes the browser send a request with your cookies · SameSite=Lax/Strict cookies, CSRF tokens, check Origin
SQL / NoSQL injection: input changes the query · parameterised queries / ORM, validate types, reject $ operators in input
Broken access control / IDOR: /orders/124 shows someone else's order · check ownership on every request
DefinitionSame-origin policy: a page can only read responses from the same scheme + host + port.
Non-simple requests (JSON body, custom headers, PUT/DELETE) trigger a preflight
OPTIONS request.Credentialed requests can't use
*; list exact origins.Cookie flags:
HttpOnly (no JS access), Secure (HTTPS only), SameSite=Lax (CSRF defence).Headers: HSTS, CSP,
X-Content-Type-Options: nosniff, Referrer-Policy — helmet sets sensible defaults.ReviseHash passwords with argon2/bcrypt, short access + rotating refresh tokens in httpOnly cookies, authorize every request (ownership!), parameterised…