GitHub advisory · PyPI
PyJWT accepts inconsistent OKP x/d JWKs, causing public/private key identity confusion
Description
PyJWT accepts internally inconsistent OKP private JWKs where the declared public key x does not correspond to the supplied private key d.
When d is present, OKPAlgorithm.from_jwk() constructs the Ed25519/Ed448 private key from d without verifying that the public key derived from d matches x. As a result, the original JWK can contain one public key identity while PyJWT performs cryptographic operations using a different key.
In affected DPoP integrations, this can allow a stolen sender-constrained access token to be used without possession of the legitimate holder's private key.
The vulnerable logic is in jwt/algorithms.py:
if "x" not in obj:
raise InvalidKeyError('OKP should have "x" parameter')
x = base64url_decode(obj.get("x"))
if "d" not in obj:
if curve == "Ed25519":
return Ed25519PublicKey.from_public_bytes(x)
return Ed448PublicKey.from_public_bytes(x)
d = base64url_decode(obj.get("d"))
if curve == "Ed25519":
return Ed25519PrivateKey.from_private_bytes(d)
return Ed448PrivateKey.from_private_bytes(d)
When d is present, x is parsed but never compared with the public key derived from d.
For example, PyJWT accepts:
{
"kty": "OKP",
"crv": "Ed25519",
"x": "<legitimate-user-public-key>",
"d": "<attacker-private-key>"
}
even though x and d belong to different key pairs.
The behavior has existed since OKP private-JWK import was introduced:
A correct import should derive the public key from d and reject the JWK when it does not equal the supplied x.
The reproducer creates two Ed25519 keypairs:
It then:
cnf.jkt is bound to the legitimate public key.x together with the attacker's d.
3.…Manual fix · PyPI
pip install --upgrade "PyJWT>=2.15.0"Sources