JSON Web Tokens (JWT): Header, Payload Claims & The Standard Token Validation Checklist
A JSON Web Token (RFC 7519) is a compact, URL-safe means of representing claims to be transferred between two parties. Encoded as three Base64URL-encoded segments separated by dots (Header.Payload.Signature), safe consumption requires executing an exhaustive 6-point cryptographic and temporal validation checklist.
{
"alg": "RS256",
"typ": "JWT"
}{
"sub": "usr_42",
"role": "admin",
"exp": 1735689600
}Step 1: Extract the Bearer token from the incoming HTTP Authorization header.
Microservices need a stateless way to trust caller identity without querying a central database for every single HTTP request. A digitally signed JWT contains the user ID, tenant ID, and permissions directly in its payload, verifiable purely through mathematics.
The Airline Boarding Pass: Printed with your passenger name, flight number, seat, and gate, accompanied by a high-density 2D barcode signed by the airline. Any gate agent or baggage handler can verify the pass offline using the barcode scanner without querying the central reservations database.
[ Base64URL(Header) ] . [ Base64URL(Payload) ] . [ Base64URL(Signature) ]
│ │ │
▼ ▼ ▼
{ "alg": "RS256", { "sub": "usr_42", Digital signature computed over:
"typ": "JWT", "iss": "cosmos.app", SHA256(Header + "." + Payload)
"kid": "key_2026" } "aud": "cosmos-api", using IdP's Private Key
"exp": 1735689600 }
│
▼
[ 6-Point Token Validation Checklist: ]
1. Verify Alg header against whitelist (Reject 'none'!)
2. Verify Signature with IdP Public Key
3. Verify exp (Expiration Time > now)
4. Verify nbf (Not Before <= now)
5. Verify iss (Issuer matches trusted IdP URL)
6. Verify aud (Audience matches our API identifier)CosmosApp microservices process incoming requests bearing Bearer JWTs. Every microservice runs the 6-point validation pipeline before routing requests. If a token has expired by even 1 second, or was issued for a different audience (e.g. mobile app rather than internal API), it is immediately rejected with HTTP 401.
Step 1: Extract the Bearer token from the incoming HTTP Authorization header.
Step 2: Split token string into exactly three segments delimited by periods ('.').
Step 3: Decode header; verify that 'alg' is in the strictly permitted whitelist (e.g., ['RS256', 'ES256']).
Step 4: Verify the cryptographic signature over (Header + '.' + Payload) using the matching public key.
Step 5: Inspect temporal claims: ensure current time < exp (with optional 30s clock skew tolerance) and >= nbf.
Step 6: Inspect structural claims: ensure iss matches the expected Identity Provider and aud matches this API service.
import { jwtVerify } from 'jose';
// CosmosApp Comprehensive 6-Point JWT Validator:
export async function validateCosmosJwt(rawToken: string, publicKey: CryptoKey) {
try {
const { payload, protectedHeader } = await jwtVerify(rawToken, publicKey, {
issuer: 'https://auth.cosmos.app',
audience: 'https://api.cosmos.app',
algorithms: ['RS256', 'ES256'], // Explicit algorithm whitelist!
clockTolerance: 30, // 30 seconds max clock skew
});
return { valid: true, user: payload };
} catch (err: any) {
return { valid: false, error: err.message };
}
}- ✕JWTs are encrypted by default (Standard JWTs are JWS - signed, not encrypted; anyone who reads the token can decode the Base64 payload in plaintext).
- ✕Valid signature means the token is trusted (Signature only proves integrity; you must also validate exp, iss, and aud).
Key Architectural Takeaways
- ✓JWT payloads are encoded, not encrypted; never store passwords, unhashed secrets, or PII in JWT claims.
- ✓Always validate all standard claims: alg, signature, exp, nbf, iss, and aud.
- ✓Keep access token expiration windows short (10–15 minutes) to mitigate token theft risk.
Decoding a JWT payload using jsonwebtoken.decode() or atob() without verifying the signature and claims.
Always use a cryptographic verification library (jwtVerify) that checks the signature before trusting claims.
Can an attacker read sensitive data (such as an email address or role) stored inside a standard signed JWT (JWS)?