Header
Base64URL encoded
Contains the token type (JWT) and signing algorithm (e.g. HS256, RS256).
Payload
Base64URL encoded
Contains claims: sub, iat, exp, user roles, and custom data.
Signature
HMAC / RSA signed
Ensures integrity. Cannot be forged without the secret key.
The Header and Payload are NOT encrypted — they are simply Base64URL encoded. Anyone holding the token can read them. Only the Signature guarantees authenticity.
JWT Security: Cryptographic Algorithms (HS256 vs RS256)
HS256 vs. RS256: Symmetric vs. Asymmetric
The 'alg' claim in your JWT header defines how the token was signed. HS256 uses a single shared secret, while RS256 uses a private/public key pair (RSA). Auditing this header is critical for developers to ensure they aren't accidentally using insecure defaults. A common vulnerability is the 'none' algorithm, where a server might accept unsigned tokens if the header is maliciously modified.
Detecting Infrastructure Patterns
The header also includes the 'kid' (Key ID) and 'typ' (Type), which tell your authentication server which part of the infrastructure should handle the validation. Verifying these fields locally allows you to debug 'Signature Invalid' errors without exposing your token lifecycle or key management patterns to third-party logs.