The 7 Critical Pitfalls
1. **Accepting "alg": "none"**: Failing to enforce an algorithm whitelist, allowing unsigned forged tokens.
2. **Weak or Predictable Secrets**: Using secrets shorter than 256 bits, vulnerable to offline hashcat cracking.
3. **Storing Tokens in localStorage**: Exposing tokens to any cross-site scripting (XSS) vulnerability.
4. **No Expiration Claim (exp)**: Issuing tokens that live indefinitely.
5. **Putting Sensitive Data in Claims**: Storing credit cards, passwords, or PII in Base64URL-encoded payloads.
6. **Confusing Decoding with Verification**: Extracting user data from unverified tokens.
7. **Missing Audience (aud) Validation**: Permitting a token issued for one service to be accepted by another service.
Frequently Asked Questions
How do I protect against XSS token theft?
Store access tokens in memory or in an HttpOnly, Secure, SameSite=Strict cookie so JavaScript cannot access the token string.