Token Security¶
Deep dive into JWT token security.
Token Structure¶
Header¶
Payload¶
{
"sub": "user:abc123",
"iss": "http://localhost:8000",
"aud": "your-app",
"exp": 1730000000,
"iat": 1729996400,
"roles": ["editor"],
"scopes": ["read:posts", "write:posts"]
}
Signature¶
USSO signs tokens with EdDSA (Ed25519) by default.
Verification¶
1. Verify Signature¶
2. Check Expiration¶
3. Validate Audience¶
4. Validate Issuer¶
Common Attacks¶
Token Theft¶
Prevention: - Use HTTPS - HTTP-only cookies - Short token lifetime
Token Replay¶
Prevention: - Token expiration - One-time tokens for sensitive actions - JTI (JWT ID) for revocation
XSS Attacks¶
Prevention: - HTTP-only cookies - Content Security Policy - Input sanitization
CSRF Attacks¶
Prevention: - SameSite cookies - CSRF tokens - Validate Origin header