A Zero-Upload WebCrypto JWT Workbench decodes Base64Url headers and payloads strictly in local browser memory, audits security flaws (`alg: none`, missing or expired `exp` claims), mints test HS256 signatures, and computes SHA-256, SHA-512, and HMAC-SHA256 digests using the browser's hardware-accelerated `window.crypto.subtle` and `crypto.getRandomValues` CSPRNG APIs with zero remote transmission.
How to Use JWT & Crypto Lab
- 1Inspect or Mint an HS256 JWT Locally
Paste any 3-segment Base64Url JWT string into the decoder or click Mint Test JWT to sign a local 1-hour developer claim set using your shared secret.
- 2Audit Claims and Verify Signature Integrity
Review automated security warnings for `alg: none` or missing expiration timestamps, then click Verify to validate the HMAC-SHA256 cryptographic signature via `crypto.subtle.verify`.
- 3Compute Digests or Mint a 256-Bit Production Secret
Switch to the WebCrypto SHA / HMAC tab to hash webhook payloads with SHA-256/512, compute keyed HMAC signatures, or generate a 32-byte cryptographically random secret.
Core Capabilities & Specifications
- Instant JWT header/payload UTF-8 Base64Url decoding with UTC expiry evaluation
- Automated claim auditing (`alg: none` bypass risk, missing `exp`, expired tokens)
- One-click local WebCrypto HS256 JWT minting and HMAC signature verification
- Real-time SHA-256, SHA-512 & HMAC-SHA256 digest calculator
- Cryptographic 256-bit CSPRNG API key & webhook signing secret generator
Why Pasting Production JWTs Into Cloud Tools Creates Breach Exposure
A live JSON Web Token is an active bearer credential: anyone holding a valid token can impersonate that user or service role until `exp` expires. Pasting production tokens into arbitrary third-party online decoders that execute analytics beacons, server-side logging, or error-tracking captures creates an unnecessary credential leak vector.
Every cryptographic primitive in FutureStack's JWT & Crypto Workbench runs strictly client-side via the W3C Web Cryptography API (`window.crypto.subtle` and `window.crypto.getRandomValues`). Neither your bearer tokens, HMAC secrets, nor hashed payloads ever cross the network interface.
import crypto from "node:crypto";
export function verifyHs256Jwt(token: string, secret: string) {
const parts = token.split(".");
if (parts.length !== 3) return { valid: false, reason: "Malformed JWT" };
const [h, p, sig] = parts;
const header = JSON.parse(Buffer.from(h, "base64url").toString("utf8"));
if (header.alg !== "HS256") return { valid: false, reason: "Disallowed algorithm" };
const expected = crypto.createHmac("sha256", secret).update(`${h}.${p}`).digest();
const actual = Buffer.from(sig, "base64url");
const sigMatch = expected.length === actual.length && crypto.timingSafeEqual(expected, actual);
const payload = JSON.parse(Buffer.from(p, "base64url").toString("utf8"));
if (sigMatch && typeof payload.exp === "number" && payload.exp < Math.floor(Date.now() / 1000)) {
return { valid: false, reason: "Token expired" };
}
return { valid: sigMatch, payload };
}Critical JWT Attack Surfaces: alg:none, Key Confusion, and Constant-Time Checks
Historically, several widespread JWT library CVEs stemmed from blindly trusting the untrusted `header.alg` field inside incoming tokens. Under an `alg: none` attack, an adversary mutates the payload claims (`role: "admin"`), sets `"alg": "none"`, and strips the signature segment. Under RS256-to-HS256 algorithm confusion, an attacker signs an HS256 token using the server's public RSA key.
Defense requires strictly pinning expected algorithms server-side (ignoring `header.alg` negotiation) and comparing HMAC byte buffers exclusively with `crypto.timingSafeEqual` so microsecond comparison discrepancies cannot leak MAC bytes.
Base64Url Encoding vs Authenticated Encryption (JWS vs JWE)
Standard 3-part JWTs follow RFC 7515 JSON Web Signature (JWS): the signature proves who minted the token and guarantees tamper-resistance, NOT confidentiality. Header and payload JSON remain plain Base64Url readable by any client, proxy log, or browser extension.
Keep JWT claims minimal (`sub`, `iss`, `aud`, `exp`, `jti`, coarse roles) and store signed access/session tokens in `HttpOnly; Secure; SameSite=Lax` cookies rather than readable `localStorage` wherever XSS mitigation matters.
export async function verifyWebhookSignature(
timestampSec: string,
rawBody: string,
signatureHex: string,
secret: string
): Promise<boolean> {
const ageSec = Math.abs(Math.floor(Date.now() / 1000) - Number(timestampSec));
if (!Number.isFinite(ageSec) || ageSec > 300) return false; // 5-minute replay window
const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${timestampSec}.${rawBody}`));
const expected = Array.from(new Uint8Array(mac)).map((b) => b.toString(16).padStart(2, "0")).join("");
return expected === signatureHex.toLowerCase();
}CSPRNG Secret Entropy vs Human-Chosen Signing Keys
Because HMAC-SHA256 is extraordinarily fast on modern GPUs (~billions of guesses per second on cracking rigs), any JWT signed with a short dictionary phrase (`super-secret-2026`) can be brute-forced offline from a single captured JWT cookie in seconds. Always generate symmetric signing secrets with `>= 256 bits` (32 cryptographic random bytes) from a CSPRNG.
Engineering Comparison Matrix
| Vulnerability / Primitive | Mechanism | Security Risk | Recommended Remediation |
|---|---|---|---|
| alg: none Bypass | Strips signature and sets header alg=none | Complete auth bypass | Whitelist exact allowed algorithm server-side |
| RS256 -> HS256 Confusion | Signs HS256 using server's public PEM key | Forged admin tokens | Enforce asymmetric JWK/EdDSA verification explicitly |
| Missing `exp` Claim | No Unix expiry claim embedded in JWT | Permanent leaked session | Short 5–15 min access TTL + HttpOnly refresh rotation |
| Timing Side-Channel | `sig === expected` exits on first byte mismatch | Byte-by-byte MAC recovery | Use `crypto.timingSafeEqual` / `subtle.verify` |
| Low-Entropy HMAC Key | Short secret like `'test1234'` | Offline GPU brute-force | Use 256-bit (32-byte) CSPRNG secret keys |
Common Production Pitfalls to Avoid
- •Confusing Base64Url encoding with encryption—never store passwords, PII keys, or private API keys inside JWS claims.
- •Storing privileged bearer JWTs inside `localStorage` instead of `HttpOnly; Secure; SameSite=Lax` cookies.
- •Validating JWT expiration (`exp`) using local browser time instead of synchronized NTP server UTC.
- •Skipping `iss` (issuer) and `aud` (audience) checks when accepting tokens across multi-service SSO architectures.
- •Comparing hex HMAC digests with `===` instead of fixed-time byte comparison.
Frequently Asked Questions
Can someone read a decoded JWT payload without having the secret key?
Yes. Standard signed JWTs (JWS) use unencrypted Base64Url encoding for header and payload segments; the secret protects authenticity and integrity via the signature—not privacy.
Does verification work offline in the browser?
Yes. This workbench invokes your browser's native WebCrypto SubtleCrypto HMAC-SHA256 engine to mint and verify signatures with zero server calls.
Why does `crypto.subtle.verify` require exact UTF-8 byte encoding?
HMAC computes cryptographic digests over the raw bytes of `Base64Url(header) + '.' + Base64Url(payload)`. Any extraneous whitespace or newline in the token string breaks verification immediately.
How long should an HS256 shared secret be?
According to RFC 7518, HMAC-SHA256 JWT keys must be at least 256 bits (32 random bytes) long to prevent offline brute-force recovery attacks.
When should I pick asymmetric RS256/EdDSA over symmetric HS256?
Use HS256 when a single trusted service (or tightly coupled auth gateway) both issues and verifies tokens. Use asymmetric EdDSA (Ed25519) or RS256 when external microservices need read-only verification via a public JWKS endpoint without holding the signing private key.
What is the difference between SHA-256 and HMAC-SHA256?
Plain SHA-256 produces an unkeyed integrity hash that anyone can recompute if they alter the payload. HMAC-SHA256 binds a secret key into nested compression passes—proving both payload integrity and sender authenticity.

