Public research

PyJWT

CVE-2026-102273 · GHSA-w2cx-738m-mc7w
Public JWK containers accepted as HMAC verification secrets

High, 7.4 · Public source snapshot: November 12, 2026

Original portfolio report · Upstream commit · Source reference · Public advisory

Shared credits and the scope of my investigation are documented below.

CVE-2026-102273 · GHSA-w2cx-738m-mc7w · PyJWT · High

Public security research credited to Charles Vosburgh (the-vibe-dev).

Field Value
Package PyJWT (PyPI)
Severity High
CVSS 7.4 — CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N
Affected version 2.13.0 only
Fixed version 2.14.0
Weakness CWE-347 — Improper Verification of Cryptographic Signature
CVE CVE-2026-102273
Credit Charles Vosburgh (the-vibe-dev) — reporter

Mallory can start with an application's public RSA, EC, or OKP JWK container and use those public bytes as an HMAC key to sign attacker-selected JWT claims. In PyJWT 2.13.0, an application that accepts both HS* and asymmetric algorithms and passes the raw JWK/JWKS JSON through key= can then accept that forged token. The boundary crossed is the application's signature-verification policy: Mallory does not recover a private key, steal Alice's token, or break RSA, EC, or EdDSA; PyJWT misclassifies a public-key container as a symmetric secret.

The published affected range is exactly PyJWT 2.13.0, and the first fixed release is 2.14.0. I reviewed both release snapshots, the vulnerable key-preparation path, the public fixing commit, and its regression tests directly. I did not execute a reproduction, so the runtime result described below is an expected result derived from the inspected source and public advisory rather than a locally observed run.

PyJWT supports both symmetric HMAC JWT algorithms (HS256, HS384, and HS512) and asymmetric algorithms such as RSA, ECDSA, and EdDSA. Those families have different trust models. An HMAC verifier must possess a secret that can also create a valid signature; an asymmetric verifier can safely publish its verification key while keeping the signing key private.

In the affected topology:

  • Alice's application uses PyJWT 2.13.0;
  • the verification call allows at least one HS* algorithm and at least one asymmetric algorithm;
  • the application supplies raw serialized public JWK/JWKS JSON as key= rather than loading it through PyJWK; and
  • Mallory knows the exact serialized bytes, including any meaningful ordering and whitespace.

The expected behavior is to reject public asymmetric key material whenever the selected JWT algorithm is HMAC. PyJWT's own guidance is to keep symmetric and asymmetric algorithm choices separate and not derive the algorithm allowlist from attacker-controlled token data. Applications that follow that separation are not affected by the demonstrated path.

Mallory controls the token's alg header and selects an allowed HMAC algorithm. PyJWT therefore routes verification to HMACAlgorithm, passing the application's configured raw JSON value into HMACAlgorithm.prepare_key.

In PyJWT 2.13.0, jwt/algorithms.py rejects recognizable PEM and SSH keys, then applies an additional JWK check only when the byte string begins with { and the decoded top-level object directly contains kty:

stripped = key_bytes.lstrip()
if stripped.startswith(b"{"):
    try:
        jwk_obj = json.loads(key_bytes)
    except ValueError:
        jwk_obj = None
    if isinstance(jwk_obj, dict) and "kty" in jwk_obj:
        raise InvalidKeyError(
            "The specified key looks like a JWK and should not be "
            "used directly as an HMAC secret. Load it via "
            "PyJWK / HMACAlgorithm.from_jwk first."
        )

return key_bytes

This catches a bare object such as {"kty":"RSA", ...}. It does not catch a JWKS object such as {"keys":[{"kty":"RSA", ...}]}, because kty belongs to a nested object. A top-level array also bypasses the branch because its first non-whitespace byte is [. The unchanged container bytes are returned as the HMAC key.

The same file then performs HMAC signing and verification with those bytes:

def sign(self, msg: bytes, key: bytes) -> bytes:
    return hmac.new(key, msg, self.hash_alg).digest()

def verify(self, msg: bytes, key: bytes, sig: bytes) -> bool:
    return hmac.compare_digest(sig, self.sign(msg, key))

Mallory can calculate the same MAC because the supposed secret is the public JWK container. A matching token is therefore accepted under the application's vulnerable mixed-algorithm policy.

The incomplete container handling entered in 2.13.0 as part of a broader defense against algorithm confusion: that release rejected top-level raw JWK objects but did not recursively recognize JWK members. The advisory deliberately identifies only 2.13.0 as affected, so this report does not extend the range to earlier releases.

The narrow primitive is forgery of an HMAC JWT under a verifier that intended the supplied bytes to represent public asymmetric verification material. If the application trusts JWT identity, role, or authorization claims, Mallory can submit claims chosen by her without the corresponding asymmetric private key. The resulting business impact depends on what that application authorizes from those claims; the source does not establish a universal administrative role or a particular downstream data set.

Exploitation requires all of the following conditions:

  • PyJWT 2.13.0 is in use;
  • the verifier permits an HS* algorithm on the same path as an asymmetric algorithm;
  • the raw key value is a container form that hides kty from the vulnerable top-level check; and
  • Mallory can reproduce the exact raw bytes passed as key=.

An asymmetric-only allowlist is a meaningful negative control: an HS256 token is rejected before this HMAC key path can authenticate it. Likewise, loading JWK data through PyJWK preserves the key's semantic type instead of treating the serialized document as secret bytes. These controls follow from the inspected source and public advisory, but I did not perform runtime validation against a disposable application.

The following source-derived test shape is sufficient for an authorized maintainer to confirm the boundary without targeting a real service:

  1. Generate an ephemeral RSA key pair and export only the public key as JWK.
  2. Serialize it inside a JWKS object, for example {"keys":[public_jwk]}, retaining the exact serialized bytes.
  3. With PyJWT 2.13.0, sign benign local claims using HS256 and those serialized bytes as the HMAC key.
  4. Decode the token using the same raw bytes as key= and a deliberately mixed allowlist such as ['HS256', 'RS256'].
  5. Repeat with PyJWT 2.14.0 and with an RS256-only allowlist.

The expected vulnerable result is that step 4 accepts the claims in 2.13.0. The expected fixed and negative-control results are rejection in 2.14.0 and rejection when HS256 is absent from the allowlist. These are expected outcomes, not captured output from this review.

Use only ephemeral keys and non-production claims. The test does not need network access, a live identity provider, or another user's token.

Upgrade to PyJWT 2.14.0 or later. The public fix, commit 801cd12, changes HMACAlgorithm.prepare_key so it parses the JSON value and iteratively traverses nested dictionaries and arrays. If any member is named kty, PyJWT rejects the entire raw value and tells the caller to load it through PyJWK or HMACAlgorithm.from_jwk.

The shipped fix also handles container variations that could otherwise undermine a simple recursive parse: BOM and supported UTF encodings, deeply nested inputs that reach Python's recursion limit, escaped kty member names, and oversized JSON integers. Its tests preserve compatibility by confirming that an ordinary JSON-shaped secret with no JWK member remains accepted byte-for-byte.

Applications should also enforce the trust boundary at configuration level:

  • keep symmetric and asymmetric verification paths separate;
  • use a fixed algorithm allowlist chosen by the application, never one derived from the token header;
  • load JWK/JWKS material through PyJWT's structured key APIs; and
  • reject a key whose semantic type conflicts with the requested algorithm family.

Regression coverage should include bare JWK objects, JWKS objects, top-level and nested arrays, BOM/UTF variants, escaped member names, deeply nested documents, ordinary JSON secrets, and an asymmetric-only negative control.

GHSA-w2cx-738m-mc7w is an algorithm/key-type confusion flaw limited by the public advisory to PyJWT 2.13.0. Under a mixed symmetric/asymmetric verification policy, raw public JWK container bytes can pass the incomplete top-level check and become an HMAC secret, allowing someone who knows those public bytes to forge accepted JWT claims. PyJWT 2.14.0 fixes the issue by detecting JWK members throughout container structures and rejecting the raw value.

The most useful remaining validation is a disposable end-to-end application test that records the 2.13.0 acceptance, the 2.14.0 rejection, and an asymmetric-only negative control using the same ephemeral key material.

GitHub credits me (the-vibe-dev) as the reporter. The advisory also identifies my Trilobyte handle.

This write-up documents a publicly disclosed vulnerability for remediation, regression testing, and authorized assessment. Test only with keys and applications you own or are explicitly authorized to assess.