Authentication interview question · Most asked
What are the most common JWT security pitfalls?
Summary
Accepting alg: none or the wrong algorithm, not validating exp/aud/iss, using weak HMAC secrets, storing tokens in localStorage, putting sensitive data in the payload, very long expiry without revocation, and confusing ID tokens with access tokens.
Longer Answer
Always pin accepted algorithms when verifying, validate standard claims, use strong keys (or asymmetric RS256/EdDSA with JWKS rotation), keep access tokens short-lived (5–15 minutes) and use rotating refresh tokens. The payload is only base64-encoded, so anyone can read it. Validate tokens on every request, not just at the gateway, when services are reachable internally.
Key Points
- Pin algorithms
- Validate exp/aud/iss/nbf
- Strong keys, rotate via JWKS
- Short-lived access tokens
- Payload is not secret
More most-asked Authentication questions
- What is the difference between authentication and authorization?
- Compare session-based authentication with token-based (JWT) authentication.
- What are OAuth 2.0 and OpenID Connect, and how do they differ?
- Explain the OAuth 2.0 Authorization Code flow with PKCE.
- How do refresh tokens work, and how do you secure them?
- How should passwords be stored?
- What is multi-factor authentication, and which factors are strongest?
- How do you secure session cookies?