Issue
A JSON Web Token (JWT) carries claims—statements such as a user ID, issuer, or expiration time. In common signed JWTs, the header and claims are Base64URL-encoded, which makes them readable; encoding does not encrypt them. A signature can detect unauthorized changes, but it does not hide the claims. JWTs can also be encrypted, though that is a different token form. RFC 7519, OWASP JWT Cheat Sheet
A JWT’s claims should be trusted only after the application has verified the token according to its own policy. Common weaknesses include:
- Algorithm confusion: The application lets the token’s alg header determine how it is verified, or allows algorithms that should not be valid for that key. For example, a flawed verifier might treat a public key as an HMAC secret. Secure implementations configure an explicit algorithm allowlist and use each key only with its intended algorithm. RFC 8725, OWASP JWT Cheat Sheet
- Unsecured tokens: A verifier accepts a token using alg: "none" in a context that requires a signature. The JWT standard defines this form, but an application that relies on signed tokens must reject it.
- Insufficient claim checks: A valid signature alone does not establish that a token is meant for this service, is current, or represents an authorized user. Where applicable, validate the issuer (iss), audience (aud), expiration (exp), not-before time (nbf), subject (sub), and application-specific authorization claims. RFC 7519 makes many registered claims optional; the application must define which claims it requires. RFC 7519, RFC 8725
- Untrusted key selection: A verifier may misuse header fields such as jku, x5u, or jwk to select or fetch a verification key from an untrusted source. A kid value can also become dangerous if application code uses it unsafely, such as in a filesystem path or database query. Key selection must resolve only to keys trusted for the expected issuer and algorithm. OWASP JWT Cheat Sheet
- Weak HMAC secrets or unsafe defaults: If a symmetric signing secret is guessable or exposed, someone who obtains it may be able to create tokens that pass signature verification. This requires evidence of a weak or compromised key; token readability alone does not show that the key is weak.
A three-part compact token is commonly a signed JWT (JWS); encrypted compact JWTs (JWE) have five parts. Do not assume every JWT has the same structure.
Examples
Hypothetical request using an issued token:
GET /api/profile HTTP/1.1
Host: api.example
Authorization: Bearer <issued-test-token>
Tampering check: Change a claim such as "role":"user" to "role":"admin" but leave the signature unchanged. A correctly verifying service should reject the modified token if the signature no longer matches. This test checks whether that particular mutation is detected; it does not prove issuer, audience, expiration, or authorization checks are correct.
Validation policy:
Accept only the configured signing algorithm.
Resolve the verification key from the trusted issuer's configured key set.
Reject invalid signatures.
Require the claims this application depends on.
Check issuer, audience, and time claims against configured values.
Apply authorization checks to the requested action.
A typical failure response might be 401 Unauthorized, but the exact status and body are application-specific. The important observation is whether the protected operation is denied.
Impact
The impact depends on what the application accepts and what its claims authorize. If a forged or improperly validated token is accepted for a protected action, an attacker may gain access under the identity or permissions represented by that token. The extent could range from access to one user’s data to elevated privileges, depending on the affected endpoint and authorization checks.
A changed token being rejected is useful evidence for that specific test, but does not prove that all algorithms, keys, claims, token types, or endpoints are handled correctly. Conversely, a readable payload, a permissive-looking header, or a successful request to a public endpoint is not by itself proof of a validation vulnerability.
Testing
1. Check whether modified tokens authorize an action
Capture a valid token for a test account and a protected request. Change one claim without updating the signature, then check whether the protected action is actually allowed.
Example: Changing a role while retaining the original signature tests signature enforcement. A 200 response on a public endpoint is not enough.
GET /api/profile HTTP/1.1
Host: api.example.test
Authorization: Bearer MODIFIED_TEST_TOKEN
2. Check algorithm, key, and claim policy
Compare valid and invalid signatures, permitted algorithms, issuer, audience, and time claims according to the application’s token policy. Use one change per request.
Example: An expired token is relevant when expiration is required by the application. A readable payload does not mean the signature is invalid.
GET /api/profile HTTP/1.1
Host: api.example.test
Authorization: Bearer EXPIRED_TEST_TOKEN
3. Check how the verification key is selected
Review whether token headers can choose a verification key or key URL, and compare those values with the issuer’s configured trusted keys. Verify any suspected acceptance against a protected operation.
Example: A key URL or identifier in a token is untrusted input. Its presence alone does not prove the server fetched or trusted an unapproved key.
4. Rule out cached sessions and alternate paths
Repeat on relevant protected endpoints and inspect browser requests for valid cookies, refreshed tokens, or cached responses. Verify the operation and account identity rather than relying on the status alone.
Example: A browser may still hold a valid session cookie. That session can explain why a page appears signed in.
False positives and limits: A 200 response may come from a public or cached resource. A 401 or 403 does not explain which check failed. A rejected modified token demonstrates rejection for that input and path, not necessarily correct validation everywhere. A token’s exp or aud claim may be optional under a particular application’s design, so verify the documented policy before classifying its absence as a defect. RFC 7519 permits small clock-skew leeway when checking time claims. RFC 7519
Mitigation
Primary fixes
- Configure the verifier with a short, explicit allowlist of algorithms. Bind each key to its intended algorithm and reject none where signatures are required. Do not let the token header choose an arbitrary verification method. RFC 8725
- Obtain verification keys from a trusted configuration or issuer metadata. Treat token header values as untrusted hints, not as authority to load arbitrary keys or fetch arbitrary URLs. Validate that the key belongs to the expected issuer.
- Define the required claims for each token type and endpoint. Validate the issuer and audience against expected values, check expiration and not-before times where required, and validate that the subject is recognized. Do not treat a valid signature as authorization by itself. RFC 8725
- For HMAC-based signing, use a high-entropy secret, store it securely, and rotate it if exposure is suspected. Prefer a maintained JWT library and keep it updated.
Additional defenses
- Keep sensitive information out of readable signed-token claims unless the token is encrypted or the data is otherwise protected.
- Use short token lifetimes where appropriate and implement a revocation or session invalidation mechanism if the application needs immediate logout or credential-change invalidation.
- Keep authorization checks server-side and specific to the requested resource and action.
Retest: Repeat the same controlled checks after the change. Confirm that altered signatures, disallowed algorithms, wrong issuer or audience values, and invalid time claims are rejected according to policy—and that valid tokens still work for the intended user and endpoint.