CVE-2026-102271: PyJWT Vulnerability Allows Public Keys in DER Form as HMAC Secrets
Summary
CVE-2026-102271: PyJWT: Public keys in DER form are accepted as HMAC secrets, bypassing the CVE-2022-29217 guard. Affects pyjwt versions >= 2.4.0, < 2.14.0. Fixed in 2.14.0. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
PyJWT is a Python library used for encoding and decoding JSON Web Tokens (JWT). It supports various algorithms for signing and verifying tokens, including HMAC and asymmetric algorithms like RSA and EC. The library is widely used in applications for secure token-based authentication. However, it has a vulnerability that allows public keys in DER format to be incorrectly accepted as HMAC secrets, leading to potential security risks.
Vulnerability Detail
The vulnerability arises from the HMACAlgorithm.prepare_key method, which incorrectly allows DER-encoded public keys to be used as HMAC secrets. This occurs because the method only checks for specific text markers to identify PEM and SSH keys, failing to account for binary DER format. An attacker can exploit this by signing a forged token with a public key, allowing them to impersonate users and gain unauthorized access. This issue is a variant of the key confusion problem identified in CVE-2022-29217, where improper verification of cryptographic signatures can lead to serious security breaches.
How To Fix
Latest published version: 2.15.1 as of 23 Oct 2026
pip install --upgrade "pyjwt==2.15.1"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
2.14.0
This is the first release that contains the fix.
pip install --upgrade "pyjwt==2.14.0"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, ensure that your application does not mix HS* and RS* algorithms and avoid passing public keys as DER bytes to the jwt.decode method. Instead, use PEM-encoded keys or ensure proper key management practices are in place.
Conclusion
The PyJWT vulnerability CVE-2026-102271 poses a significant risk by allowing public keys in DER format to be used as HMAC secrets. It is crucial for developers to update to the patched version 2.14.0 or later and to follow best practices for key management to mitigate this risk.
See every vulnerability recorded for pyjwt →
FAQ
The vulnerability allows attackers to forge tokens using public keys, potentially granting them unauthorized access to user accounts.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.
The CVSS score of this vulnerability is 7.4, indicating a high severity level.
Yes, the application must be misconfigured to allow HS* algorithms with an asymmetric public key passed as DER bytes.
If immediate updates are not possible, implement the suggested workaround by avoiding the use of DER public keys as HMAC secrets.
References
Related vulnerabilities
Recent vulnerabilities recorded for pyjwt.