Anatomy of a JSON Web Token
A JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object.
A JWT consists of three parts separated by dots (.):
- Header: Contains the token type (JWT) and the signing algorithm being used (e.g., HMAC SHA256 or RSA).
- Payload: Contains the claims. Claims are statements about an entity (typically, the user) and additional data.
- Signature: Used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn't changed along the way.
Common Security Pitfalls
- Exposing Sensitive Data: The payload is simply Base64Url encoded, not encrypted. Anyone can read the contents of a JWT payload. Never store passwords, SSNs, or other sensitive data in the payload.
- Ignoring the
expClaim: Always set a short expiration time (exp) for access tokens. - Accepting the
noneAlgorithm: Ensure your server strictly enforces the expected algorithm and does not accept tokens where the header specifies"alg": "none".
Need to decode a token to see what claims it holds? Use our offline JWT Debugger to safely inspect tokens without sending them to an external server.