JWT Security

A guided, one-scene-at-a-time walkthrough

01 / 19

JWT Security WalkthroughSigned is not secret. Valid is not authorized.0 · StartThree parts, one dot apartHeaderalg · typPayloadsub · exp · iss · audSignatureintegrity..Base64URL is not encryptionAnyone can decode it. Only the key proves it.1 · AnatomyStateless has a priceJWTstatelessrevoking is hardSession cookieserver-side stateinstant logoutNeed instant logout? Prefer sessions.2 · Do you need it?Who can mint a token?Public keyprivate keyconsumers can only verifyShared secretsecretevery holder can forge3 · SigningPick strong, pin onepublic keyEdDSAES256PS256shared secretHS256HS384HS512avoidnoneRS256 (old)allow one,in your codeNever let the token choose its algorithm4 · AlgorithmsStrong random secrets onlyDorandom 256+ bitsecrets managerNevera passwordhardcoded in codenon-crypto randomtoo short5 · SecretsThe header is attacker inputHeaderalgalgorithm confusionjku / x5uSSRFjwkattacker's own keykidinjectiontrusted keysKeys come from your config, not the token6 · Header risksValidate every claimiss · who signedaud · is it for meexp · not expirednbf · not too earlysub · right subjecttyp · right purposeOptional in the spec? Require them anyway.7 · ClaimsNo signature, no entry"alg": "none"signedAllowlist algorithms. Reject none.8 · alg: nonePublic key as a secretpublic keyHS256ES256 onlyalgorithms=["ES256"]Bind each key to one algorithm9 · Alg confusionNever fetch the attacker's keyown jwk / jkuattacker keykidtrusted JWKSkid picks a trusted key. It never creates trust.10 · Trusted keysA token is for one serviceIdPaud: paymentsPaymentsInternal APIcheck audReject tokens meant for someone else11 · AudienceBind keys to issuersCombined keysissuer Aissuer Bone key setOwn keys eachissuer Aissuer BExact iss match, then that issuer's keys only12 · IssuerRight token, right jobat+jwtlogout+jwtreset+jwttyp?APIID, logout and reset tokens are not access tokens13 · Token typeWays to cancel a tokenShort-livedaccess tokensDenylistjti + issStatus liststatus claimSender-boundDPoP · mTLSKey denylists on claims, not raw token bytes14 · RevocationA stolen token needs a keytoken + proofno private keyAPIDPoP or mTLS binds the token to its holder15 · ReplaySigned is not secretSigned (JWS)anyone can read itEncrypted (JWE)only the recipient canNo passwords or secrets in claims16 · Confidential?Sign, then encryptIssuerConsumerClaimsSignEncryptDecryptVerifyValidateDecryption alone proves nothing. Verify the signature.17 · Sign + encryptChecklist at a glancePin algorithmNo alg noneStrong keysTrusted keysiss + audexp + nbfToken typeRevocationReplay guardPayload cleanJWE if neededVerify first18 · Recap

Use Previous / Next (or the arrow keys) to step through all 19 panels, or Auto-play for a hands-free presentation. The SVG artwork is embedded in this page.