Lesson 6 of 14 · 15m
JWT Attacks That Shipped
alg confusion, kid injection, and jku SSRF all ship from one defect: the verifier trusting the token's own metadata.
The verifier is the attack surface
JWT libraries don't get attacked at the signature math. They get attacked at the point where the token tells the verifier how to verify it. Three header fields do this: alg picks the algorithm, kid picks the key, and jku/x5u point at where keys live. Every one of those was attacker-controlled input, and each has shipped exploits in production libraries.
alg confusion: the 2015 class
In March 2015 Tim McLean published "Critical vulnerabilities in JSON Web Token libraries," covering the same bug across several major implementations: the verifier read alg from the token and then applied it. Two failure modes:
alg: none— the signature segment is empty; libraries that honored it accepted a completely unsigned token. Forgedsub, forgedexp, accepted.RS256→HS256downgrade — the server holds an RSA public key for verification. The attacker re-signs a forged payload withHS256using the public key as the HMAC secret — public keys are, by definition, public. A verifier that accepts the header'salgdutifully computesHMAC(public_key, forged_payload), gets a match, and accepts. node-jsonwebtoken's version of this is CVE-2015-9235 (fixed in 4.2.2, August 2015), and PyJWT, java-jwt, and friends had their own. It has re-appeared in libraries since — CVE-2022-23529 in node-jsonwebtoken ≤8.5.1 (fixed in 9.0.0, December 2022) was another verifier-side flaw in the same family, this time insecretOrPublicKeyhandling.
The bug isn't "RSA vs HMAC." It's let the attacker pick the contract.
kid: key selection as injection
kid is a lookup hint the token supplies so verifiers supporting key rotation know which key to use. Two ways it goes wrong: the naive verifier dereferences kid as a filesystem path (kid=../../dev/null verifies the signature against an empty key — an HMAC of the payload with an empty secret) or as a SQL value into a keys table (injection). The fix is the same shape as alg: kid must index into a fixed, server-side key set — a map lookup that 404s on anything else, never a path, URL, or query.
jku/x5u: fetch your own keys
jku names a URL where the JWKS lives; x5u names one holding an X.509 chain. A verifier that fetches the named URL gets a two-for-one: SSRF into your network plus a key the attacker minted, which validates the forged token. JWKS location is configuration, not token input — https://idp.example/.well-known/jwks.json hardcoded or allowlisted.
How to test your own verifier
You don't need a pentest vendor to check the 2015 class — craft the attack yourself. Take a real token, decode the header, set alg to none, strip the signature segment (leave the trailing dot), and send it. Then re-sign a forged payload with HS256 keyed by your published RSA public key. Then set kid to ../../dev/null. A correctly-pinned verifier rejects all three instantly; each acceptance is a shipped-CVE-shaped bug in your stack. Run this against every endpoint that verifies tokens — the API middleware, the websocket upgrade handler, the file-download presign — because JWT verification has a way of being implemented twice.
What to actually do
Pin the algorithm server-side, per issuer: jwt.verify(token, key, { algorithms: ['RS256'] }). Never let the token select it. Keep kid as an index into a fixed map. Keep JWKS URLs in config. Verify iss, aud, exp explicitly with a small clock-skew tolerance (~30s), and upgrade libraries past the CVEs above — the 2015 lessons are in every modern lib's changelog, but only if you're on a version that contains them. When in doubt, denylist alg=none is not a control; an allowlist of exactly the algorithms your issuers emit is.
Keep reading
Related articles from the SudoSecurity blog.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.
Zero-Trust Access for Homelabbers: Teleport vs. Tailscale vs. WireGuard vs. Cloudflare Tunnel
Four tools solve four different problems that all get pitched as the same problem. Here's what each one does, where each one breaks, and the combination that covers a real homelab without paying an SSO tax you didn't see coming.
The SSO Tax: Why Self-Hosted Projects Are Gating Login Behind a Paywall
A growing list of open-core self-hosted projects, from Grafana to Planka, gate single sign-on behind an Enterprise tier. Here's which protocol actually gets paywalled, and what to check before you deploy.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.