Rewrite JSON Web Token Cheat Sheet: language-agnostic, drop Java code#2083
Rewrite JSON Web Token Cheat Sheet: language-agnostic, drop Java code#2083
Conversation
…at Sheet - Add 'JSON Web Tokens (JWT)' section to Authentication Cheat Sheet with common implementation mistakes (storage, expiration, alg:none, claim validation, payload data, weak secrets, revocation) - Rename JSON_Web_Token_for_Java_Cheat_Sheet.md to JSON_Web_Token_Cheat_Sheet.md and update Objective section to note Java examples are language-neutral - Update all cross-references across Index.md, IndexASVS.md, IndexASVS4.md, IndexMASVS.md, IndexProactiveControls.md, IndexTopTen.md, Forgot_Password_Cheat_Sheet.md, REST_Security_Cheat_Sheet.md Closes #1973 Closes #1176 Co-authored-by: mackowski <[email protected]> Agent-Logs-Url: https://github.com/OWASP/CheatSheetSeries/sessions/a9a54bd6-cdc5-4d96-86db-c4c2583cfe89
|
This is WIP, I am still working on this ;-) |
…alone JWT Cheat Sheet - Expand Authentication_Cheat_Sheet.md JWT section to cover all topics from the removed JWT CS: token structure overview, session management reference, token sidejacking (fingerprinting), expanded revocation options (denylist + fingerprinting+sessionStorage), JWE reference (RFC 7516), and Further Reading (RFC 8725, JWT Attack Playbook) - Delete JSON_Web_Token_Cheat_Sheet.md completely (no content duplication) - Update Forgot_Password_Cheat_Sheet.md link → Auth CS JWT section - Update REST_Security_Cheat_Sheet.md link → Auth CS JWT section - Update IndexASVS, IndexASVS4, IndexMASVS, IndexProactiveControls, IndexTopTen to replace JWT CS link with Auth CS JWT section link - Regenerate Index.md via script (count: 112 → 111, JWT CS entry removed) Closes #1973 Closes #1176 Agent-Logs-Url: https://github.com/OWASP/CheatSheetSeries/sessions/c2eb6d41-32a8-46f5-bdbf-e0abc98044ad Co-authored-by: mackowski <[email protected]>
|
@mackowski my concern is that this is the wrong direction. I would much rather move all the JWT content into a JWT cheatsheet and link the AuthN cheatsheet to it. My goal is to avoid building large guides and keep these to small cheatsheets. So I politely think this is the wrong direction, but I also do not want to derail you. If you want this in, go ahead and force-merge it and we can address splitting out the JWT work in a different issue. |
|
Good idea @jmanico I will move this to separate cheatsheet and reference in AuthN cheatsheet. For now I will keep it short and concise. |
…T section
Per reviewer feedback ("move all the JWT content into a JWT cheatsheet and
link the AuthN cheatsheet to it; keep these to small cheatsheets"):
- Restore cheatsheets/JSON_Web_Token_Cheat_Sheet.md as standalone
comprehensive cheatsheet (token structure, sidejacking, revocation,
info disclosure, storage, weak secrets, implementation examples)
- Fix self-reference anchor in JWT CS (JSON_Web_Token_Cheat_Sheet.md
#token-sidejacking → #token-sidejacking)
- Trim Authentication_Cheat_Sheet.md JWT section to a 2-sentence
paragraph with links to JWT CS and Session Management CS
- Update Forgot_Password_Cheat_Sheet.md → JSON_Web_Token_Cheat_Sheet.md
- Update REST_Security_Cheat_Sheet.md → JWT CS #no-built-in-token-revocation
- Restore IndexASVS, IndexASVS4, IndexMASVS, IndexProactiveControls,
IndexTopTen to link to JWT CS (not Auth CS anchor)
- Regenerate Index.md (count: 111 → 112)
Agent-Logs-Url: https://github.com/OWASP/CheatSheetSeries/sessions/1caf9112-f7dd-4b0a-b47c-c0da156cbadd
Co-authored-by: mackowski <[email protected]>
…rity guide - Remove all Java code examples (629 lines → 164 lines) - Restructure around 8 security vulnerability categories with risk/mitigation format - Cover: alg:none, RS256→HS256 confusion, weak secrets, missing claims validation, sensitive data in payload, insecure storage, token sidejacking, lack of revocation, header injection (kid/jku/x5u) - Add Best Practices Summary and References sections - All markdownlint checks pass Agent-Logs-Url: https://github.com/OWASP/CheatSheetSeries/sessions/a7188aba-1cb6-4b4f-a4c4-cf5fb6cc048a Co-authored-by: mackowski <[email protected]>
|
FWIW is have a very WIP branch about JWT in here: https://github.com/randomstuff/CheatSheetSeries/tree/jwt_cheatsheet It was originally based on a branch by @chalbersma |
|
Here is a copy of that WIP cheatsheet. JWT Cheat SheetIntroductionJSON Web Token (JWT) is a standard format (RFC 7519)
JWT can provide authenticity (JWS) and/or confidentiality (JWE) to the token content:
In addition, the JWT specification allows the usage of unsecure JWTs ( JWT is a profile of the more general ConceptsActorsIssuer: the issuer of the JWT is the party which created the token. Audience: the audience of the JWT is the actor which is supposed to verify its authenticity, Presenter/Holder: TODO, add some examples? Type of tokensBearer token: TODO Proof-of-posession token: TODO Authenticity (JWS)An authenticated JWT (JWS) is protected against tampering (authenticity).
In most applications, you want the token to be authenticated Structure of a signed JWTThe following elements are present in signed JWTs:
An authenticated JWT has the following format: The following example is taken from RFC 7519 The decoded protected header is: {
"typ": "JWT",
"alg": "HS256"
}The decoded claims are: {
"iss": "joe",
"exp": 1300819380,
"http://example.com/is_root": true
}Signature vs. MACRecommendation: use a digital signature scheme when possible? A JWE can be authenticated using either a digital signature or a MAC:
Using a MAC may be interesting in the following cases:
Public-key signatureBenefits of using a digital signature:
Recommended signature algorithms in order of preference:
The following algorithms are NOT recommended:
TODO, ES256K? Notes:
TODO, Post-quantum signatures. ML-DSA (ML-DSA-44, ML-DSA-65, ML-DSA-87)? very large signature, probably not great justified at the moment for short-lived signatures. ML-DSA is designed to be resistant against quantum computers. However its support in JWT implementation is currently very limited. The size of if the signatures in ML-DSA is much larger than in ECDSA and EdDSA, resulting into very large JWTs. MACThe following MAC algorithms are recommended:
Secret management:
Valid HMAC secret generation example: import secrets
secret_for_hs256 = secrets.token_bytes(256//8)Invalid HMAC secret generation: import random
# Using a password/passphrase is not OK.:
bad_secret1_for_hs256 = "MyProject2025!"
# Not a secure randomness source:
bad_secret2_for_hs256 = random.randbytes(256//8)
# Not enough entropy:
bad_secret3_for_hs256 = random.randbytes(128//8)
# Not enough entropy for HS512:
bad_secret_for_hs512 = random.randbytes(256//8)Protected headersTODO Token Media TypeThe
It is recommended to use a specific media type for specific applications instead of using the generic Using a specific media type in your tokens and validating this specific media type can be used to prevent cross-application JWT Notes:
An an issuer,
As a consumer,
ClaimsSee the JWT IANA Registry for a list of standard claims. ValidityTODO, AudienceTODO, A JWT can include more than one audience: {"aud": ["audience1","audience2"]}If these token represent unrelated entities, this might present unrelated (and possibly distrusting entitied). When receiving the JWT from its presente r TODO, audience ambiguity/etc. eg. when the audience is chosen by another party. IssuerTODO, PresenterTODO, MetadataTODO, SubjectTODO, TODO, AuthorizationsTODO, Confidentiality (JWE)Usually, you want a token which provides authenticity (JWS). In some cases, you might want to have confidentiality as well. This might be important if the claims contain some sensitive information (such as PII) that should not be exposed to the presenter (for example). This is achieved by using a Nested JWT: this is usually done by first signing the claims and then encrypting the resulting token. You usualy don't want to have a JWT which provides confidentiality only: when using an encrypted JWT, you usually want to provide authenticity as well. The correct handling of encryption introduces additional requirements such as:
For these reasons, these considerations are currently not addessed in this Cheat Sheet but will be addressed in a upcoming version. Key publishingTODO Recognizing a public key from a private key in JWK format:
TODO, add missing TODO, other algorithms TODO, JSON Web Key Use Attacks on JWTFor more details, see RFC 8725. TODO, align with RFC 8725 Accepting Unsecured JWTSome JWT libraries, used to accept unsecured JWTs by default ( This issue should now be fixed in JWT libraries. Cross-JWT ConfusionTODO RecommendationsFor more details, see RFC 8725. General
Key ManagementTODO Key generation:
Key distribution:
Issuer
Verifier
Alternatives to JWT and JOSEDepending on the application, some alternatives to JWT and JOSE might be:
Critique of JWT and JOSE: Further ReadingMain JWT and JOSE specifications:
IANA registries: Attacks on JWT and JOSE:
Other useful links: |
Replaces the Java-specific JWT cheat sheet (629 lines) with a concise, language-agnostic security guide (164 lines) covering all known JWT attack classes.
Changes
alg: none, RS256 → HS256 key confusion)exp,nbf,iat,iss,aud,sub)localStoragevs memory/closures vs hardened cookies)jtidenylist, refresh token rotation)kid,jku,x5u— SQL injection, path traversal, SSRF vectors)Checklist
[TEXT](URL)AI Tool Usage Disclosure (required for all PRs)
the contents and I affirm the results. The LLM used is
claude-sonnet-4-5and the prompt used is: Rewrite JSON_Web_Token_Cheat_Sheet as a concise, language-agnostic security cheat sheet covering all known JWT security flaws with good references. Drop Java code.
⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.