CVE-2026-62995
Improper padding validation in joserfc leads to JWT token malleability.
- CVSS 2.3
- 345
- Input Validation and Sanitization
- Remote
joserfc is a Python library that provides an implementation of several JSON Object Signing and Encryption (JOSE) standards. in versions 1.7.1 and prior, joserfc accepts JWTs with trailing padding (==) which are not conforming to the JOSE specifications. This leads to malleability of the JWTs when consumed by joserfc. Depending on this application this might or not be an issue. This could lead to bypass of token revocation or anti-replay protection when implemented as a deny list of tokens or a deny list of token hashes. Note that ECDSA JWS are always malleable because of the malleability of ECDSA signatures (first test case in the code bellow). This makes a scheme which assumes that JWTs are not malleable brittle. However for other signatures (or MAC) schemes it might make sense to assume non malleability of the token. This issue has been fixed in version 1.7.2.
- CWE
- 345
- CVSS base score
- 2.3
- Published
- 2026-07-29
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Check
- Category
- Input Validation and Sanitization
- Subcategory
- Cryptographic Implementation Error
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Affected component
- joserfc
- Fixed by upgrading
- Yes
Solution
Upgrade `joserfc` to version 1.7.2 or later.
Vulnerable code sample
import base64
import binascii
from typing import Union
def to_bytes(s: Union[str, bytes], encoding: str = 'utf-8') -> bytes:
if isinstance(s, bytes):
return s
return s.encode(encoding)
def urlsafe_b64encode(s: bytes) -> bytes:
return base64.urlsafe_b64encode(s).rstrip(b'=')
# VULNERABLE: Padding is added to the input, allowing non-conformant base64url values.
def urlsafe_b64decode(s: bytes) -> bytes:
return base64.urlsafe_b64decode(s + b'=' * (-len(s) % 4))
def json_b64encode(data: bytes) -> str:
return urlsafe_b64encode(data).decode('utf-8')
def json_b64decode(s: str) -> bytes:
return urlsafe_b64decode(to_bytes(s))Patched code sample
import base64
import binascii
from typing import Union
def to_bytes(s: Union[str, bytes], encoding: str = 'utf-8') -> bytes:
if isinstance(s, bytes):
return s
return s.encode(encoding)
def urlsafe_b64encode(s: bytes) -> bytes:
return base64.urlsafe_b64encode(s).rstrip(b'=')
# FIX: Validate that the base64url input has no padding, rejecting non-conformant values.
def urlsafe_b64decode(s: bytes) -> bytes:
"""Decodes a base64 string, raising an error if it is incorrectly
padded.
"""
rem = len(s) % 4
if rem > 0:
# The input is not padded correctly.
raise binascii.Error('Incorrect padding')
return base64.urlsafe_b64decode(s)
def json_b64encode(data: bytes) -> str:
return urlsafe_b64encode(data).decode('utf-8')
def json_b64decode(s: str) -> bytes:
return urlsafe_b64decode(to_bytes(s))Payload
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c==
Cite this entry
@misc{vaitp:cve202662995,
title = {{Improper padding validation in joserfc leads to JWT token malleability.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-62995},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-62995/}}
}
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 ::
