AI pentesting guides / Vulnerability classes

Token security

JWT vulnerability testing

JWT vulnerability testing checks whether an application correctly verifies JSON Web Tokens, so that an attacker cannot forge or alter a token to impersonate another user or raise their privileges. The core weakness is CWE-347 (Improper Verification of Cryptographic Signature), and findings are classified under OWASP Top 10 2021 A07 and OWASP API Security Top 10 2023 API2 (Broken Authentication).

JWTs are self-contained: if the server trusts a token's claims without a correct signature check, the client controls its own identity. Most JWT flaws come from libraries used with permissive defaults or from code that reads a token before verifying it.

Classification

  • CWE-347 Improper Verification of Cryptographic Signature; CWE-345 Insufficient Verification of Data Authenticity; CWE-321 or CWE-798 for hard-coded keys.
  • OWASP Top 10 2021: A07 Identification and Authentication Failures (A02 Cryptographic Failures for weak keys).
  • OWASP API Security Top 10 2023: API2 Broken Authentication.

Common JWT flaws

  • Signature not verified at all, or verified only on some routes.
  • The 'none' algorithm accepted.
  • Algorithm confusion: an RS256 public key accepted as an HS256 secret.
  • Weak HMAC secrets that can be cracked offline from a captured token.
  • Untrusted key headers (jku, x5u, jwk, kid) letting the attacker supply or point to the verification key; kid values reaching file paths or SQL.
  • Missing exp, aud or iss checks; tokens that stay valid after logout or password change.

How it is found and proven

Capture a valid token, decode it (it is only base64url-encoded), and note the algorithm and claims. Then send modified tokens: an unchanged payload with a broken signature, alg set to none, a re-signed token with a guessed or cracked key, or one signed with the RSA public key as an HMAC secret. Proof is the server accepting a forged or tampered token, for example a token whose sub claim names another test user returning that user's data, while a token with a corrupted signature in the control request is rejected.

Remediation

Verify every token with a library configured for one expected algorithm and key; never let the token choose. Use long random secrets or asymmetric keys, and keep keys out of source code. Ignore or allow-list jku, x5u and jwk headers and sanitise kid. Validate exp, nbf, aud and iss. Keep tokens short-lived and support revocation for logout and compromise.

With Pentest-Swarm

How Pentest-Swarm tests JWTs

JWT flaws are part of the broken-authentication class Pentest-Swarm reports, using jwt_tool from its integrated arsenal.

  • Captures tokens issued to test accounts during recon and passes them to jwt_tool for tampering and algorithm checks.
  • Uses forged-token access as an exploit-chain step toward BOLA or privilege escalation, which the swarm then tries to prove.
  • Secrets scanning with gitleaks and trufflehog can surface hard-coded signing keys in repositories you provide.
  • Reports carry the original and forged tokens, the response evidence, severity and CVSS.

Where it falls short

JWT findings are not one of the classes with a dedicated oracle producer today, so review the evidence for each one rather than relying on a VERIFIED badge. Offline cracking of strong secrets is out of scope for an automated run. Token revocation and lifetime policy are design questions better assessed in a code or architecture review.

Questions

Is a JWT encrypted?

Usually not. A standard signed JWT (JWS) is only encoded, so anyone can read its claims. Do not put secrets in it.

What is JWT algorithm confusion?

A flaw where a server expecting RS256 accepts an HS256 token and uses the public key as the HMAC secret, letting an attacker sign tokens with a key they already have.

Should I store JWTs in localStorage?

Any script on the page can read localStorage, so an XSS flaw exposes the token. HttpOnly cookies limit that exposure.

Sources

  1. CWE-347
  2. RFC 8725: JWT Best Current Practices
  3. OWASP JSON Web Token Cheat Sheet