Web Security
XSS, CSRF, cookie protection, JWT, and authorization.
7 questions
JuniorTheoryVery commonWhat is the difference between authentication and authorization?
What is the difference between authentication and authorization?
Authentication verifies WHO you are — login/password, biometrics, a token. Authorization decides WHAT that already-verified identity may do — its permissions on actions and resources. Authentication runs first; authorization follows.
Common mistakes
- ✗Treating authentication and authorization as the same concept
- ✗Swapping the two — thinking authorization verifies identity
- ✗Assuming authorization can precede authentication
Follow-up questions
- →Where does role-based access control (RBAC) fit in?
- →Can a request be authenticated but still unauthorized?
JuniorTheoryVery commonWhat is XSS (cross-site scripting)?
What is XSS (cross-site scripting)?
XSS is an injection flaw where attacker-supplied input is rendered unescaped into a page, so the browser runs it as HTML/JS. A comment with <script> then executes for every viewer, letting the attacker steal cookies or rewrite the page.
Common mistakes
- ✗Confusing XSS with a server-side SQL injection
- ✗Believing XSS needs a file download to trigger
- ✗Thinking XSS affects only the attacker, not other viewers
Follow-up questions
- →How do stored and reflected XSS differ?
- →Why does
HttpOnlyblunt cookie theft via XSS?
MiddleTheoryCommonWhat is a JWT?
What is a JWT?
A JSON Web Token — a compact header.payload.signature string, base64url-encoded, carrying claims, usually for stateless auth. It's SIGNED (HMAC/RSA) for integrity but NOT encrypted, so anyone holding it can read the payload.
Common mistakes
- ✗Believing the payload is encrypted and therefore secret
- ✗Thinking the signature is or contains the user's password
- ✗Assuming the server must store the token to validate it
Follow-up questions
- →What is the difference between
HMACandRSAsigning here? - →Where would you store a
JWTin a browser, and why?
SeniorTheoryOccasionalWhat are common JWT security pitfalls?
What are common JWT security pitfalls?
The payload is only base64url-encoded, not encrypted — never put secrets in it. Verify the signature and pin the expected alg to avoid alg:none and HMAC/RSA confusion. Tokens can't be revoked before expiry without extra state.
Common mistakes
- ✗Storing secrets in the payload, trusting the signature to hide them
- ✗Accepting the token's own
algheader instead of pinning one - ✗Assuming a
JWTcan be revoked instantly without extra state
Follow-up questions
- →How does the
alg:noneattack actually succeed? - →How would you build practical token revocation?
SeniorTheoryOccasionalHow do you defend against XSS?
How do you defend against XSS?
Escape/encode untrusted data for its output context (HTML, attribute, JS, URL), sanitize allowed HTML with a vetted library, set a Content-Security-Policy to limit scripts, and mark cookies HttpOnly. Never concatenate raw input.
Common mistakes
- ✗Trusting input length limits alone to stop
XSS - ✗Escaping on input instead of per output context
- ✗Believing HTTPS or TLS prevents
XSS
Follow-up questions
- →What does a strict
Content-Security-Policyactually restrict? - →Why must escaping match the exact output context?