appsec.fyi

JWT — A Practical Guide

A curated AppSec resource library covering XSS, SQLi, SSRF, IDOR, RCE, XXE, OSINT, and more.

JWT: A Practical Guide

Curated and synthesized by . Last updated 2026-07-01. Synthesized from 108 of 108 curated resources. Browse all 108 JWT resources →

The Problem with JWTs: Flexibility vs. Security

JSON Web Tokens (JWTs) have become a ubiquitous component in modern authentication and authorization systems, especially within APIs and microservices architectures. Their popularity stems from their stateless nature, allowing for efficient and scalable handling of user identity and session information without requiring persistent server-side state management [1][2][3]. However, this flexibility, coupled with the specification's extensibility, opens the door to a wide array of security pitfalls if not implemented with meticulous attention to detail.

At their core, JWTs are self-contained tokens representing claims, typically signed to ensure integrity and authenticity [1][2]. This signature verification is paramount; without it, or if improperly handled, the token becomes a vector for attackers to impersonate users, escalate privileges, or bypass security controls entirely [2][4][5]. The common structure of a JWT—HEADER.PAYLOAD.SIGNATURE—is base64url encoded, making the header and payload readily decipherable [1][2]. This transparency means sensitive data should never be placed directly within the payload [1][4][6].

The JWT standard itself, while providing a flexible format, leaves many security considerations to implementation. This is where many vulnerabilities arise, often not from fundamental cryptographic weaknesses, but from how libraries and applications utilize the specification [7][8][6]. The sheer number of discovered vulnerabilities and CVEs related to JWT libraries underscores this challenge [9][10][11][12][13][14].

Core Mechanics of JWTs

A JWT is fundamentally a JSON object containing structured data, encoded and transmitted in a specific format. Understanding its components is crucial for identifying potential weaknesses.

Structure

Signing Algorithms

The alg parameter in the header dictates the cryptographic algorithm used. Common algorithms include:

Statelessness and Lifecycle Management

JWTs are designed for stateless architectures. The server doesn't maintain session state; it validates the token's signature and claims on each request [1][3]. Key lifecycle aspects include:

Notable Techniques and Vulnerabilities

The flexibility of JWTs, particularly in how algorithms and keys are handled, leads to several well-known attack vectors.

Signature Verification Bypass

The most fundamental security check is signature verification. If an application fails to verify the signature or uses an insecure method (like a decode() function instead of verify()), attackers can tamper with the payload or even forge tokens entirely [1][2][29][24][30][31]. This can be exploited by modifying claims like isAdmin or role to gain elevated privileges [2][5][32][12][33].

alg: "none" Algorithm Abuse

If a JWT library or application improperly supports or handles the alg: "none" algorithm, an attacker can remove the signature and change the header to indicate no signature is required. If the server trusts this, it will accept the token, allowing arbitrary payload manipulation [2][9][34][35][36][29][23][12][14][37][31].

Algorithm Confusion (Key Confusion)

This is one of the most severe and prevalent JWT vulnerabilities [10][22][37][31]. It occurs when a JWT library or application trusts the alg parameter in the token header to determine the verification algorithm. An attacker can switch the declared algorithm (e.g., from RS256 asymmetric to HS256 symmetric) and then use the server's publicly available public key as the secret for the HMAC signature. Since the public key is known, the attacker can sign a forged token that the server will incorrectly validate [38][9][21][10][39][35][36][29][22][13][17][14][37][31]. This is also applicable to ECDSA to HMAC confusion [40].

Weak Secret Keys (HS256)

When using HMAC algorithms (like HS256), the security hinges entirely on the strength and secrecy of the shared secret key. If the key is weak, guessable, or hardcoded, attackers can brute-force or dictionary-attack it offline using a captured JWT to obtain the key and forge valid tokens [25][27][41][20][42][6][19][17][43][44][30][45][46].

kid Header Injection and Path Traversal

The kid (Key ID) header parameter is used to specify which key to use for verification. If not properly validated, an attacker can inject malicious values, potentially leading to path traversal if the kid is used to construct file paths for key retrieval [15][16][17][33]. This can allow an attacker to force the server to use arbitrary files (e.g., /dev/null) as the signing key, effectively bypassing verification [15][16][33].

jku and x5u Header Injection

The jku (JWK Set URL) and x5u (X.509 URL) header parameters specify URLs for retrieving public keys. If not strictly validated against an allowlist, an attacker can point these parameters to a malicious server hosting their own JWKS or certificate, allowing them to sign forged tokens with their private key [47][48][22][17][49].

Improper Claim Validation

Even if the signature is valid, certain claims must be validated correctly. For example, the iss (issuer) and aud (audience) claims are crucial for ensuring the token was issued by a trusted party and intended for the current recipient [25][7][50][27][4][51][8][18][52]. Vulnerabilities can arise from partial string matches on the issuer or a failure to validate the audience claim entirely [50][51].

Nested and Encrypted JWT Vulnerabilities

When JWTs are encrypted (JWEs), vulnerabilities can occur if the inner JWT's signature is not verified after decryption, or if the encryption process itself is flawed [53][54][55]. For instance, a JWE containing an unsigned PlainJWT could be accepted if the library fails to enforce signature verification on the inner token [53][54].

Library Vulnerabilities

Many vulnerabilities are found in specific JWT library implementations due to insufficient validation or insecure defaults. Examples include issues with PyJWT [56][57][50][58], jsonwebtoken [1][59][60], Authlib [61], fast-jwt [62], Hono [63][10][36], pac4j-jwt [53][64][54], HarbourJwt [65][10], and Python JOSE [66][67]. Keeping these libraries updated is critical [25][56][61][63][53][65][66][54][36][67][59].

Detection and Prevention Strategies

Securing JWT implementations requires a multi-layered approach focusing on strict validation, secure key management, and constant vigilance.

Strict Validation Practices

Secure Key Management

Secure Transmission and Storage

Token Lifecycle Management

Tooling for JWT Analysis and Testing

A variety of tools can assist in identifying JWT vulnerabilities and testing implementations.

Recent Developments and Emerging Threats

The landscape of JWT vulnerabilities is continually evolving. Recent trends highlight:

Where to Go Deeper

For a more in-depth understanding and practical exploration of JWT security:

Sources cited in this guide

  1. Can Snyk Detect JWT Security Issues? — snyk.io
  2. JSON Web Token Attacks and Vulnerabilities — Acunetix — acunetix.com
  3. JWT Security Guide: Best Practices & Implementation (Gupta Deepak) — guptadeepak.com
  4. JWT Security Best Practices (Phase Two) — phasetwo.io
  5. Understanding JWT Security and Common Vulnerabilities (secops) — secops.group
  6. Vaadata: JWT vulnerabilities, common attacks and security best practices — vaadata.com
  7. draft-ietf-oauth-rfc8725bis: JSON Web Token Best Current Practices — datatracker.ietf.org
  8. RFC 8725 - JSON Web Token Best Current Practices — datatracker.ietf.org
  9. Known Exploits and Attacks (jwt_tool Wiki) — github.com
  10. JWT Algorithm Confusion Attack: Two Active CVEs in 2026 — tools.pinusx.com
  11. JWT Security in 2025: Critical Vulnerabilities for B2B SaaS — securityboulevard.com
  12. Intigriti: Exploiting JWT vulnerabilities — advanced exploitation guide — intigriti.com
  13. Auth0: Critical vulnerabilities in JSON Web Token libraries — auth0.com
  14. PayloadsAllTheThings: JSON Web Token — github.com
  15. JWT authentication bypass via kid header path traversal (siunam) — siunam321.github.io
  16. JWT Signature Bypass via kid Path Traversal — invicti.com
  17. KathanP19/HowToHunt: JWT — github.com
  18. OWASP JSON Web Token for Java Cheat Sheet — cheatsheetseries.owasp.org
  19. Curity: JWT Security Best Practices — curity.io
  20. Brute Forcing HS256 is Possible — auth0.com
  21. JWT authentication bypass via algorithm confusion (siunam) — siunam321.github.io
  22. WorkOS: JWT algorithm confusion attacks explained — workos.com
  23. PortSwigger KB: JWT none algorithm supported — portswigger.net
  24. OWASP WSTG: Testing JSON Web Tokens — owasp.org
  25. Top 3 security best practices for handling JWTs — snyk.io
  26. JWT Token Lifecycle: Expiration, Refresh, and Revocation — skycloak.io
  27. JWT Security Best Practices for 2025 (JWT.app) — jwt.app
  28. These are the security issues with JWT — scip.ch
  29. The Ultimate Guide to JWT Vulnerabilities and Attacks — pentesterlab.com
  30. jwt_tool Attack Methodology wiki — github.com
  31. JWT attacks | Web Security Academy — portswigger.net
  32. November CTF Challenge: Exploiting JWT vulnerabilities to achieve RCE — intigriti.com
  33. tuhin1729 Bug Bounty Methodology: JWT — github.com
  34. JWT Authentication Bypass Using alg:none - CTF Writeup — medium.com
  35. JWT Vulnerabilities List: 2026 Security Risks & Mitigation Guide (Red Sentry) — redsentry.com
  36. JWT Algorithm Confusion Attacks: CVE-2026-22817 Fix Guide — dev.to
  37. Algorithm confusion attacks | Web Security Academy — portswigger.net
  38. How JWT Libraries Block Algorithm Confusion: Code Review Lessons — pentesterlab.com
  39. JWT Algorithm Confusion: Turning RS256 Tokens into HS256 Disasters — medium.com
  40. PentesterLab: Another JWT Algorithm Confusion Vulnerability (CVE-2024-54150) — pentesterlab.com
  41. Cracking JWT Keys - Authentication Lab — authlab.digi.ninja
  42. Lab: JWT authentication bypass via weak signing key — portswigger.net
  43. brendan-rius/c-jwt-cracker: JWT brute-force cracker in C — github.com
  44. mazen160/jwt-pwn: Security testing scripts for JWT — github.com
  45. ticarpi/jwt_tool: A toolkit for testing, tweaking and cracking JSON Web Tokens — github.com
  46. dr34mhacks/jwtauditor: JWT Auditor – Analyze, break, and understand your tokens like a pro. — github.com
  47. JWT Forgery via unvalidated jku parameter (Invicti) — invicti.com
  48. JWT Signature Bypass via unvalidated jku parameter — invicti.com
  49. JWT Scanner Burp extension — portswigger.net
  50. CVE-2024-53861: PyJWT Issuer Field Partial Match — vulert.com
  51. HackerOne: Argo CD JWT audience claim not verified — hackerone.com
  52. JWT (Json Web Token) Audience aud versus Client_Id - What's the difference? — stackoverflow.com
  53. Proof of Concept for CVE-2026-29000 (pac4j-jwt) — github.com
  54. CVE-2026-29000: Authentication Bypass in pac4j-jwt — arcticwolf.com
  55. HackerOne: Critical vulnerability in JWE Specification — hackerone.com
  56. CVE-2026-32597: PyJWT Information Disclosure Vulnerability — sentinelone.com
  57. CVE-2025-45768: PyJWT Information Disclosure Vulnerability — sentinelone.com
  58. Top 3 security best practices for handling JWTs — snyk.io
  59. Severe Security Flaw Found in jsonwebtoken Library — thehackernews.com
  60. Detecting JWT Security Issues — snyk.io
  61. Authlib Critical JWT Forgery (CVE-2026-27962) — thehackerwire.com
  62. CVE-2026-34950 fast-jwt: Incomplete Fix for CVE-2023-48223 — endorlabs.com
  63. CVE-2026-22817: JWT Algorithm Confusion in Hono — dev.to
  64. CVE-2026-29000: pac4j-jwt Authentication Bypass — penligent.ai
  65. CVE-2026-23993: JWT Authentication Bypass in HarbourJwt via Unknown alg — pentesterlab.com
  66. Python-JOSE Security Risk: CVE-2024-33663 Explained — ethicalhacking.uk
  67. CVE-2024-33663: Python-jose Algorithm Confusion — sentinelone.com
  68. JWT Signature Bypass via kid SQL injection — invicti.com
  69. Where to Store the JSON Web Token (JWT)? — medium.com
  70. Hacker Tools: JWT_Tool — intigriti.com
  71. HackTricks: JWT vulnerabilities — book.hacktricks.xyz
  72. jwt-hack: JSON Web Token Hack Toolkit (GitHub) — github.com
  73. Working with JWTs in Burp Suite — portswigger.net
  74. JSON Web Token Attacker Burp extension — portswigger.net
  75. PortSwigger jwt-editor: Burp Suite extension for editing and signing JWTs — github.com
  76. Introducing CookieMonster: a tool for breaking stateless authentication — ian.sh
  77. RFC 8725: JSON Web Token Best Current Practices — ietf.org
📚 This guide is synthesized from the full text of resources curated in the JWT library, and refreshed as new material is added.