PRACTICAL JWT SECURITY
JWTs are credentials, not containers.
A JSON Web Token is convenient to move between services. Treat it with the same care as a session cookie: it can be replayed until it expires.
What a signed JWT contains
A compact signed JWT has three dot-separated values: a header, payload, and signature. The signature lets a recipient verify integrity; it does not encrypt the header or payload. Do not put passwords, private keys, internal paths, or unnecessary personal data in claims.
Claims worth checking
exp bounds the lifetime. nbf delays use until a point in time. iat records issue time. Validate these on the server with a small clock-skew allowance, plus issuer, audience, and subject where your protocol requires them.
Algorithms and keys
Reject alg: none. Pin the expected algorithm in application configuration rather than accepting whatever appears in a token header. Keep HMAC secrets secret; never use a public RSA/EC key as an HMAC secret. Rotate keys deliberately and use asymmetric keys where verification needs to be distributed.
Debug safely
Use a local decoder for real tokens. Redact sensitive values before putting tokens in tickets, chat, logs, screenshots, or production browser consoles. If expiry looks wrong, compare the client clock, server clock, UTC date, and NumericDate seconds—not milliseconds.