Mastering JSON Web Tokens: How to Decode, Inspect & Verify JWT Signatures
In-depth guide on RFC 7519 JWT structure, registered claims parsing, HMAC SHA-256 signature verification, and client-side security best practices.
1. What is a JSON Web Token (JWT)?
A **JSON Web Token (JWT)** is a compact, URL-safe container used for authorization and stateless user session management across modern web applications, microservices, and mobile APIs. RFC 7519 specifies the format of JWTs as 3 Base64Url encoded segments separated by dots:
1. Header
Contains token metadata specifying the signing algorithm (e.g. HS256 or RS256) and the type JWT.
2. Payload Claims
Holds user identity data and session timestamps (sub, exp, iat, role).
3. HMAC Signature
Cryptographic hash generated by signing header.payload with your secret key to prevent tampering.
2. Standard RFC 7519 Registered Claims Reference
Registered claims are reserved key names defined by the IANA JSON Web Token Registry to ensure interoperability across OAuth2 and OpenID Connect (OIDC) identity providers:
| Claim Key | Claim Name | Description & Example |
|---|---|---|
| iss | Issuer | Identifies the principal that issued the JWT (e.g. "https://auth.zeeaitools.com"). |
| sub | Subject | Identifies the user ID or principal subject of the token (e.g. "usr_9842"). |
| aud | Audience | Identifies the recipient service or API intended to consume the token (e.g. "https://api.zeeaitools.com"). |
| exp | Expiration Time | Unix timestamp specifying when the token expires and must be rejected by backend servers. |
| nbf | Not Before | Unix timestamp specifying the earliest time at which the token becomes valid. |
| iat | Issued At | Unix timestamp recording the exact time the token was created. |
3. JWT Security Vulnerabilities & Prevention Best Practices
- Never Store Secrets Client-Side: HMAC secret keys must remain strictly confidential on backend servers.
- Reject 'alg: none' Attacks: Configure servers to explicitly enforce expected algorithms (e.g. HS256) and reject unsigned
alg: noneheader manipulations. - Use Short Expiration Times: Set access token expiry times (
exp) between 15 minutes to 1 hour, paired with HTTP-only refresh tokens.