CVE-2026-33054
Mesop path traversal allows file manipulation and DoS via a crafted state_token.
- CVSS 9.8
- CWE-22
- Input Validation and Sanitization
- Remote
Mesop is a Python-based UI framework that allows users to build web applications. Versions 1.2.2 and below contain a Path Traversal vulnerability that allows any user supplying an untrusted state_token through the UI stream payload to arbitrarily target files on the disk under the standard file-based runtime backend. This can result in application denial of service (via crash loops when reading non-msgpack target files as configurations), or arbitrary file manipulation. This vulnerability heavily exposes systems hosted utilizing FileStateSessionBackend. Unauthorized malicious actors could interact with arbitrary payloads overwriting or explicitly removing underlying service resources natively outside the application bounds. This issue has been fixed in version 1.2.3.
- CWE
- CWE-22
- CVSS base score
- 9.8
- Published
- 2026-03-20
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Affected component
- Mesop
- Fixed by upgrading
- Yes
Solution
Upgrade Mesop to version 1.2.3 or later.
Vulnerable code sample
import os
import msgpack
from typing import Any
# This code is a representation of the vulnerable `FileStateSessionBackend`
# class from Mesop version 1.2.2 (CVE-2026-33054). The original class
# inherits from a base class and uses specific types from the Mesop framework.
# These have been simplified here to focus on the core vulnerability.
# In the actual Mesop framework, this path is defined in `mesop.server.constants`.
SESSIONS_PATH = "mesop_sessions"
def get_session_id_from_request() -> str:
"""
A placeholder function. In the real application, this function would
retrieve the `state_token` from the incoming UI stream payload.
This token is untrusted and can be controlled by an attacker.
"""
# In a real exploit, the web framework would populate the context that this
# function reads from. For example, an attacker could send a `state_token`
# with the value "../../../../../etc/passwd".
raise NotImplementedError(
"In a real server, this would be implemented to get the untrusted state_token."
)
class FileStateSessionBackend:
"""
Vulnerable class demonstrating path traversal.
This is based on mesop/backend/file_state_session_backend.py in v1.2.2.
"""
def __init__(self):
# In the real application, this would ensure the session directory exists.
if not os.path.exists(SESSIONS_PATH):
os.makedirs(SESSIONS_PATH)
def _get_state_file_path(self, session_id: str) -> str:
# THE VULNERABILITY:
# The `session_id` (derived from the user-supplied `state_token`) is used
# to construct a file path without any sanitization or validation.
# `os.path.join` will resolve path traversal sequences like "../",
# allowing an attacker to navigate outside of the intended `SESSIONS_PATH` directory.
return os.path.join(SESSIONS_PATH, session_id + ".msgpack")
def get_state(self, session_id: str) -> Any:
"""
This method is used to load session state. An attacker can exploit
it to read arbitrary files by supplying a malicious `session_id`.
"""
state_file_path = self._get_state_file_path(session_id)
if not os.path.exists(state_file_path):
# In the real app, this returns a special `InitialState` object.
return None
# The application will attempt to open and read the file at the
# attacker-controlled path.
with open(state_file_path, "rb") as f:
# If the targeted file (e.g., a system file like /etc/passwd) is not a valid
# msgpack object, this line will raise an exception. This can lead to
# an application crash and a denial-of-service.
state = msgpack.unpackb(f.read(), raw=False)
return state
def save_state(self, state: Any) -> None:
"""
This method is used to save session state. An attacker can exploit
it to write to or overwrite arbitrary files.
"""
# The session_id is retrieved from the request context, which is untrusted
# because it comes from the `state_token` sent by the client.
session_id = get_session_id_from_request()
state_file_path = self._get_state_file_path(session_id)
# The application will open the file at the attacker-controlled path in
# write-binary mode. This allows an attacker to overwrite existing files
# (e.g., source code, configuration) or create new ones in arbitrary
# locations, limited only by the file permissions of the web server process.
with open(state_file_path, "wb") as f:
f.write(msgpack.packb(state))Patched code sample
import os
import pathlib
class FixedFileStateSessionBackend:
"""
A simplified class representing the fix for the path traversal vulnerability
described in CVE-2024-33054 (miscategorized as CVE-2026-33054 in the prompt).
The vulnerability existed in Mesop versions 1.2.2 and below.
"""
def __init__(self, state_dir: str):
"""Initializes the backend with a base directory for storing state."""
# Ensure the base directory is an absolute path to use for validation.
self.state_dir = os.path.abspath(state_dir)
pathlib.Path(self.state_dir).mkdir(exist_ok=True)
def _get_state_path(self, state_token: str) -> str:
"""
Returns a safe file path for a given state token, preventing path traversal.
This method contains the core logic that fixes the vulnerability.
It validates that the `state_token` is a simple, non-empty filename
and does not contain any characters that could be used to traverse
the directory structure (e.g., '/', '\\', '..').
"""
# 1. THE FIX: Validate the input token.
# It must not be empty and must not contain any path separators. This
# ensures the token can only ever be a filename within the state_dir.
if not state_token or "/" in state_token or "\\" in state_token:
raise ValueError(f"Invalid state_token: '{state_token}' contains path characters.")
# 2. Construct the path only *after* successful validation.
# Since the token is now guaranteed to be a simple filename,
# os.path.join can be used safely without risk of directory traversal.
return os.path.join(self.state_dir, state_token)
def write_state(self, state_token: str, data: str):
"""
A helper method to demonstrate writing to a state file using the
fixed path resolution logic.
"""
try:
# Get the sanitized, safe path.
safe_path = self._get_state_path(state_token)
# A secondary check could be to resolve the path and ensure it's
# still within the intended directory, as a defense-in-depth measure.
if not os.path.abspath(safe_path).startswith(self.state_dir):
raise SecurityException("Resolved path is outside the state directory.")
# Proceed with the file operation.
with open(safe_path, "w", encoding="utf-8") as f:
f.write(data)
except ValueError as e:
# The validation in _get_state_path would raise this error for a
# malicious token, preventing the file operation.
print(f"Blocked write attempt due to invalid token. Reason: {e}")
# In a real application, this would be logged as a security event.
class SecurityException(Exception):
passPayload
{
"state_token": "../../../../../../../../../etc/passwd"
}
Cite this entry
@misc{vaitp:cve202633054,
title = {{Mesop path traversal allows file manipulation and DoS via a crafted state_token.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-33054},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-33054/}}
}
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 ::
