Security & Auth • 12 min read

Understanding JSON Web Tokens (JWT): Structure, Cryptographic Signatures, and Security Best Practices

A comprehensive technical examination of RFC 7519 stateless authentication. Learn how JWTs structure claims, how cryptographic signatures prevent tampering, and how to protect APIs against algorithm substitution and token hijacking.

By HundredForge Engineering Team — Security & Authentication (OAuth2 & Identity Infrastructure) • Published August 2026

Key Takeaways

  • A JSON Web Token consists of three base64url-encoded parts separated by periods: Header, Payload, and Signature.
  • The payload of a standard JWT is encoded, NOT encrypted. Never place passwords, API secrets, or personally identifiable information (PII) inside a JWT.
  • Symmetric algorithms (HS256) share a secret key between token issuer and validator, while asymmetric algorithms (RS256, ES256) use public/private key pairs.
  • Always enforce strict algorithm verification on backend servers to neutralize the infamous "alg: none" vulnerability.

1. What is a JWT and Why Do Modern Systems Use It?

In traditional stateful web authentication, when a user logs in, the server generates a random session identifier, stores it in an in-memory database like Redis or Memcached, and sends the session ID in a Set-Cookie header. On every subsequent request, the server must query Redis to verify the session.

JSON Web Tokens (specified in RFC 7519) provide a stateless alternative. All necessary claims (user ID, roles, permissions, expiration timestamp) are serialized into a JSON object, signed cryptographically by the identity provider, and stored on the client. Any microservice can verify the authenticity of the token using the issuer’s public key or secret without querying a central database.

2. Deconstructing the Three Token Segments

A JWT appears as a long alphanumeric string with two dots separating three distinct components:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.  <-- 1. Header (Base64Url)
eyJzdWIiOiIxMjM0NTYiLCJ1c2VyIjoiQWxpY2UiLCJyb2xlIjoiYWRtaW4iLCJleHAiOjE3NjE5MjAwMDB9. <-- 2. Payload (Base64Url)
4b7N6z8...k8m0XyZ1...  <-- 3. Cryptographic Signature

1. Header: A JSON object specifying the cryptographic algorithm used (such as HS256, RS256) and the token type ("JWT").

2. Payload: The claims object containing standard registered claims (sub for subject, exp for expiration time, iat for issued-at timestamp) and custom application data.

3. Signature: Computed by taking the base64url-encoded header, appending a period, appending the base64url-encoded payload, and hashing it with your secret key using the specified algorithm.

3. Symmetric vs. Asymmetric Signing: HS256 vs. RS256

Choosing your cryptographic signature scheme has massive architectural ramifications:

• HMAC SHA-256 (HS256): A symmetric algorithm where both the service issuing the token and every service verifying the token must share the exact same secret key. If a microservice is compromised, an attacker can forge arbitrary admin tokens for the entire ecosystem.

• RSA Signature with SHA-256 (RS256): An asymmetric algorithm where the auth server signs tokens with a private key, and microservices verify tokens using a publicly exposed key (via JWKS - JSON Web Key Sets). Even if a downstream microservice is breached, it cannot forge signatures.

FeatureHS256 (Symmetric)RS256 (Asymmetric)
Key ArchitectureSingle shared secret keyPrivate key to sign, public key to verify
PerformanceExtremely fast CPU computationSlightly higher verification CPU cost
Security in MicroservicesVulnerable if any consumer leaks secretZero risk of token forgery from consumers
Standard Industry UseSingle monolithic web applicationsEnterprise OAuth2, OpenID Connect, Microservices

4. Critical Security Vulnerabilities to Avoid

1. The "alg: none" attack: Early JWT libraries permitted a token with {"alg": "none"} to bypass signature verification. Always enforce explicit algorithm whitelisting on your API gateways.

2. Long-lived access tokens: Access tokens should have short lifespans (10-15 minutes). Use rotating refresh tokens stored in secure, HttpOnly, SameSite cookies to mitigate token theft.

3. Sensitive data exposure: Because Base64Url is easily decoded in the browser (or with tools like HundredForge JWT Decoder), never place social security numbers, database IDs, or secrets in the payload.