Summary
PyJWT, a popular Python library for handling JSON Web Tokens (JWTs), previously failed to validate the crit (Critical) header parameter as required by RFC 7515.
When tokens included unknown critical extensions in the crit header, PyJWT would still accept them, potentially allowing attackers to bypass security logic that assumes strict standards compliance.
Affected context
This vulnerability affects applications that:
- Use PyJWT for verifying JWS/JWT tokens, and
- Rely on standards-compliant handling of JOSE/JWT headers, including
crit, and - Operate in environments where other services, identity providers, or intermediaries may issue tokens with extensions or critical claims.
The risk is most pronounced in distributed or federated authentication scenarios where different components may interpret token headers differently but assume that unknown critical extensions are rejected.
Exploit preconditions
- Attack surface: Any API endpoint, service, or component that accepts and verifies JWTs using vulnerable versions of PyJWT.
- Required access: Ability to supply or influence JWTs consumed by the application (e.g., as an Authorization header, cookie, or request parameter).
- Trigger point: Submission of a token that includes a
critheader listing extensions that PyJWT does not support or understand. - Why exploitation is possible: Instead of rejecting tokens with unknown critical extensions as mandated by RFC 7515 §4.1.11, PyJWT treats them as valid, allowing tokens that relying systems may have intended to be rejected or handled differently.
Why this happens
The underlying issue is an incomplete implementation of JWT/JWS header validation logic.
RFC 7515 requires that when the crit parameter is present, the recipient must understand and process all listed extensions, rejecting the token otherwise.
PyJWT did not enforce this requirement and would accept tokens even when the crit array referenced unsupported extensions.
This maps primarily to CWE-345: Insufficient Verification of Data Authenticity, because the library signaled successful verification without fully validating all security-relevant metadata, and is related to CWE-863: Incorrect Authorization where trust decisions can be made based on incompletely validated tokens.
Potential impact
- Tokens with unrecognized critical extensions may be treated as fully valid.
- Security controls that depend on strict JWT processing semantics can be bypassed.
- Authorization decisions may be made on the basis of tokens that should have been rejected.
- In multi-service ecosystems, differences in how components treat
critcan allow protocol-level confusion and potential privilege escalation.
General mitigation guidance
Mitigation focuses on enforcing strict token header validation and minimizing assumptions about partially validated tokens:
- Ensure JWT libraries validate all critical header parameters and reject tokens containing unknown or unsupported
critentries. - Favor configurations and parsing modes that fail closed when encountering unexpected headers, algorithms, or extensions.
- Limit reliance on opaque or custom token extensions unless all validating components explicitly support and correctly process them.
- Apply defense-in-depth by combining token verification with explicit, server-side authorization checks rather than trusting token structure alone.
- Reduce token lifetime and scope to limit the blast radius of any misvalidated token.
How teams detect issues like this
Effective detection strategies generally include:
- Static analysis & library review: Flag use of JWT libraries with known gaps in standards compliance, especially around header handling (
crit,alg,kid). - Code review practices: Verify that authentication middleware and token verification paths explicitly validate headers and reject unexpected metadata instead of ignoring it.
- Security testing: Incorporate tests that send JWTs with malformed or unexpected headers (including
critwith unsupported values) to confirm that they are rejected. - Runtime monitoring: Log and inspect token verification errors and unusual header patterns; enforce policies that treat acceptance of unknown critical extensions as a misconfiguration.
- Automated application security testing tools that understand JWT semantics can help highlight non-compliant verification behavior.

