dev

JSON Web Token (JWT) Architecture, Cryptographic Signatures & Security

JSON Web Tokens underpin modern stateless API authentication. We examine JWT cryptographic mechanics, signature verification workflows, and battle-tested mitigations against signature stripping and weak secrets.
Interactive ToolTest this architecture live in your browser: JWT Debugger
Open Tool

1. RFC 7519 JSON Web Token Anatomy

JSON Web Token (RFC 7519) is an open, URL-safe standard facilitating compact, verifiable data exchange between client applications and backend APIs.

Every JWT comprises three dot-separated components: Header, Payload, and Signature. Crucially, the header and payload are merely Base64URL-encoded strings, not encrypted data. Security is maintained strictly through the cryptographic signature.

JWT HEADER AND PAYLOAD DECODED
// 1. Header (Specifies signing algorithm and type)
{
  "alg": "HS256",
  "typ": "JWT"
}

// 2. Payload (Claims and metadata)
{
  "sub": "usr_94819284",
  "name": "Jane Doe",
  "role": "admin",
  "iat": 1730000000,
  "exp": 1730003600
}

// 3. Signature Construction
// HMACSHA256(base64Url(header) + "." + base64Url(payload), secretKey)

2. HMAC Symmetric vs RSA/ECDSA Asymmetric Signing

Symmetric algorithms (HS256, HS384) use a shared secret for both signing and verification, ideal for single-server architectures.

Asymmetric algorithms (RS256, ES256) employ public/private key pairs. The authorization server signs tokens with its private key, while downstream microservices verify authenticity using only the public key.

AttributeHMAC (HS256)RSA (RS256)ECDSA (ES256)
Key TypeShared Secret (Symmetric)Public / Private Key PairElliptic Curve Public / Private Pair
Signature SizeCompact (32 bytes)Large (256 - 512 bytes)Very Compact (64 bytes)
Verification SpeedExtremely FastFastFast
Best Use CaseSingle Backend APIDistributed Microservices, OAuth 2.0High-Throughput Mobile APIs

3. Common Vulnerabilities and Threat Mitigations

1. The 'alg: none' Exploit: Legacy libraries that blindly honor 'alg': 'none' allow attackers to forge valid tokens with administrative privileges without knowing the secret. Always enforce explicit algorithm whitelisting.

2. Weak Secret Brute-Forcing: Predictable shared secrets are easily cracked using hashcat dictionary attacks. Always generate keys with at least 256 bits of entropy.

Security Notice: Payloads Are PublicNever store passwords, secret keys, or PII in JWT payloads. Payloads are merely Base64URL-encoded and can be inspected in any browser console.

4. In-Browser Verification via W3C Web Crypto API

Our JWT Debugger verifies HMAC signatures directly within client memory using the native Web Crypto API:

IN-BROWSER CRYPTOGRAPHIC VERIFICATION
async function verifyJwtHs256(token, secret) {
  const [headerB64, payloadB64, signatureB64] = token.split('.');
  const dataToVerify = new TextEncoder().encode(`${headerB64}.${payloadB64}`);
  
  const key = await window.crypto.subtle.importKey(
    'raw',
    new TextEncoder().encode(secret),
    { name: 'HMAC', hash: 'SHA-256' },
    false,
    ['verify']
  );
  
  const rawSignature = Uint8Array.from(atob(signatureB64.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
  return await window.crypto.subtle.verify('HMAC', key, rawSignature, dataToVerify);
}

5. Safe Storage: HttpOnly Cookies vs LocalStorage

Never store access tokens in browser LocalStorage where any Cross-Site Scripting (XSS) vulnerability can exfiltrate them. Always store authentication tokens in HttpOnly, Secure, SameSite=Strict cookies.

Frequently Asked Questions & Technical Details

Can JWT payloads be encrypted?

Yes. Standard JWS (JSON Web Signature) only signs data. If payload confidentiality is required, employ JSON Web Encryption (JWE - RFC 7516).

How can a compromised JWT be revoked immediately?

Since JWTs are stateless, immediate revocation requires maintaining an in-memory revocation list (e.g., Redis) or maintaining short token lifespans (5-15 minutes) coupled with refresh tokens.

Are tokens pasted into Yazılım Motoru logged?

Never. All decoding and signature verifications execute entirely in your local browser sandbox.

Interactive ToolJWT Debugger aracını kullanarak bu işlemi doğrudan tarayıcınızda gerçekleştirin.
Open Tool