Mastering JSON Web Tokens (JWT): Structure, Claims & Security
In-depth guide to JSON Web Tokens (JWT): structure, standard claims, signature algorithms, and security pitfalls.
Comprehensive engineering standards, security safeguards, and client-side processing insights. Bookmark DevKitLab for rapid, zero-login daily engineering workflows.
JSON Web Tokens (JWT), defined in **RFC 7519**, are an open, industry-standard method for securely representing claims between two parties. They are widely used for stateless authentication and API authorization.
1. The Anatomy of a JWT A compact JWT consists of three parts separated by dots (`.`): 1. **Header:** Contains the token type (`JWT`) and signing algorithm (`HS256`, `RS256`, `ES256`). 2. **Payload:** Contains the claims (statements about an entity, such as user ID, roles, and expiration). 3. **Signature:** Generated by taking the encoded header, encoded payload, a secret or private key, and passing them through the specified algorithm.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c2. Critical Security Pitfalls - **Never Store Secrets in the Payload:** JWT payloads are Base64URL-encoded, NOT encrypted. Anyone who intercepts the token can decode the payload instantly. - **The `"alg": "none"` Vulnerability:** Older libraries improperly accepted unsigned tokens if the attacker set the algorithm header to `none`. Ensure your backend enforces strict algorithm verification. - **Symmetric (HS256) vs Asymmetric (RS256):** For microservices where multiple consumers verify tokens, use asymmetric keys (RS256/ES256) so only the auth server possesses the private signing key.
Explore our 44+ instant, client-side developer formatters and decoders without accounts or subscriptions. Bookmark DevKitLab for rapid, zero-login daily engineering workflows.
Interactive Tools for This Guide
Frequently Asked Questions
Can I decode a JWT without the secret key?
Yes. The header and payload are simply Base64URL-encoded JSON. The secret key is only required to verify or generate the cryptographic signature.
Is it safe to decode JWTs in the browser?
Yes, when using DevKitLab's client-side JWT Decoder. The token is parsed completely in browser memory and is never transmitted over the internet.