CVE-2022-29217: Key confusion through non-blocklisted public key formats
(updated )
What kind of vulnerability is it? Who is impacted?
Disclosed by Aapo Oksman (Senior Security Specialist, Nixu Corporation).
PyJWT supports multiple different JWT signing algorithms. With JWT, an attacker submitting the JWT token can choose the used signing algorithm.
The PyJWT library requires that the application chooses what algorithms are supported. The application can specify “jwt.algorithms.get_default_algorithms()” to get support for all algorithms. They can also specify a single one of them (which is the usual use case if calling jwt.decode directly. However, if calling jwt.decode in a helper function, all algorithms might be enabled.)
For example, if the user chooses “none” algorithm and the JWT checker supports that, there will be no signature checking. This is a common security issue with some JWT implementations.
PyJWT combats this by requiring that the if the “none” algorithm is used, the key has to be empty. As the key is given by the application running the checker, attacker cannot force “none” cipher to be used.
Similarly with HMAC (symmetric) algorithm, PyJWT checks that the key is not a public key meant for asymmetric algorithm i.e. HMAC cannot be used if the key begins with “ssh-rsa”. If HMAC is used with a public key, the attacker can just use the publicly known public key to sign the token and the checker would use the same key to verify.
From PyJWT 2.0.0 onwards, PyJWT supports ed25519 asymmetric algorithm. With ed25519, PyJWT supports public keys that start with “ssh-”, for example “ssh-ed25519”.
import jwt
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import ed25519
References
- github.com/advisories/GHSA-ffqj-6fqr-9h24
- github.com/jpadilla/pyjwt
- github.com/jpadilla/pyjwt/commit/9c528670c455b8d948aff95ed50e22940d1ad3fc
- github.com/jpadilla/pyjwt/releases/tag/2.4.0
- github.com/jpadilla/pyjwt/security/advisories/GHSA-ffqj-6fqr-9h24
- github.com/pypa/advisory-database/tree/main/vulns/pyjwt/PYSEC-2022-202.yaml
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/5PK7IQCBVNLYJEFTPHBBPFP72H4WUFNX
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/6HIYEYZRQEP6QTHT3EHH3RGFYJIHIMAO
- nvd.nist.gov/vuln/detail/CVE-2022-29217
Detect and mitigate CVE-2022-29217 with GitLab Dependency Scanning
Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →