CVE-2026-32274 Overview
CVE-2026-32274 is a path traversal vulnerability in Black, the popular uncompromising Python code formatter. Prior to version 26.3.1, Black improperly handled the --python-cell-magics option when computing cache file names. The value of this argument was placed directly into the filename without sanitization, enabling an attacker who controls this argument to write cache files to arbitrary file system locations.
Critical Impact
Attackers who can control the --python-cell-magics argument value can write cache files to arbitrary locations on the file system, potentially leading to arbitrary file write conditions that could compromise system integrity.
Affected Products
- Black Python Formatter versions prior to 26.3.1
- Python projects using Black with IPython/Jupyter notebook integration
- CI/CD pipelines and development environments utilizing Black's caching mechanism
Discovery Timeline
- 2026-03-12 - CVE-2026-32274 published to NVD
- 2026-03-12 - Last updated in NVD database
Technical Details for CVE-2026-32274
Vulnerability Analysis
This vulnerability is classified as CWE-22 (Path Traversal), affecting how Black constructs cache file names from user-supplied configuration options. The --python-cell-magics option, designed to specify additional cell magic syntax for IPython/Jupyter notebooks, was concatenated directly into cache file paths without proper sanitization.
The flaw exists in the cache key computation logic within src/black/mode.py. When Black processes formatting options to generate a unique cache filename, it incorporates the python_cell_magics values directly into the path construction. An attacker could supply path traversal sequences (such as ../) within the magic cell names to escape the intended cache directory.
Root Cause
The root cause is insufficient input validation when constructing cache file paths. The features_and_magics string, which includes unsanitized user-controlled data from --python-cell-magics, was conditionally hashed only if it exceeded a certain length threshold. This conditional approach allowed shorter, malicious inputs containing path traversal characters to pass through unhashed and be used directly in file path construction.
Attack Vector
The vulnerability is exploitable over the network in scenarios where Black is invoked with attacker-controlled arguments, such as in shared CI/CD environments, code formatting services, or when processing untrusted configuration files. An attacker would craft a malicious --python-cell-magics value containing directory traversal sequences to write files outside the intended cache directory.
The attack requires no authentication and can be executed with low complexity. While the vulnerability does not directly expose confidential data, it allows high-impact integrity violations through arbitrary file writes.
# Security patch in src/black/mode.py
# Before: Conditional hashing allowed malicious input to bypass sanitization
+ "@"
+ ",".join(sorted(self.python_cell_magics))
)
- if len(features_and_magics) > _MAX_CACHE_KEY_PART_LENGTH:
- features_and_magics = sha256(features_and_magics.encode()).hexdigest()[
- :_MAX_CACHE_KEY_PART_LENGTH
- ]
+ features_and_magics = sha256(features_and_magics.encode()).hexdigest()[
+ :_MAX_CACHE_KEY_PART_LENGTH
+ ]
parts = [
version_str,
str(self.line_length),
Source: GitHub Commit Changes
Detection Methods for CVE-2026-32274
Indicators of Compromise
- Unexpected files appearing outside Black's designated cache directories
- Cache files with unusual naming patterns containing path traversal sequences (../)
- Black process activity with suspicious --python-cell-magics arguments containing special characters
- Anomalous file write operations in sensitive system directories originating from Black processes
Detection Strategies
- Monitor command-line arguments passed to Black for path traversal patterns in --python-cell-magics values
- Implement file integrity monitoring on critical system directories to detect unexpected writes
- Audit CI/CD pipeline configurations for untrusted input being passed to Black formatting commands
- Review pyproject.toml and other Black configuration files for suspicious python_cell_magics entries
Monitoring Recommendations
- Enable logging for Black execution in automated environments to capture full command-line arguments
- Set up alerts for file creation events outside designated cache directories associated with Python processes
- Monitor for unusual patterns in Black's cache directory indicating potential exploitation attempts
- Implement SentinelOne's behavioral AI detection to identify anomalous file system activity from development tools
How to Mitigate CVE-2026-32274
Immediate Actions Required
- Upgrade Black to version 26.3.1 or later immediately across all development environments
- Audit existing configurations and CI/CD pipelines for potentially malicious --python-cell-magics values
- Review file system integrity in environments where Black has been executed with untrusted input
- Implement input validation on any systems that pass user-controlled values to Black arguments
Patch Information
The vulnerability has been fixed in Black version 26.3.1. The patch modifies the cache key computation to always hash the features_and_magics string, regardless of length, ensuring that path traversal sequences cannot be injected into file paths. The fix was implemented in commit 4937fe6cf241139ddbfc16b0bdbb5b422798909d.
For detailed patch information, refer to:
Workarounds
- Avoid passing untrusted or user-controlled input to the --python-cell-magics argument
- Run Black in isolated environments with restricted file system permissions
- Implement allowlisting for python_cell_magics values in automated pipelines
- Use container isolation or sandboxing when executing Black on untrusted code
# Configuration example - Upgrade Black to patched version
pip install --upgrade black>=26.3.1
# Verify installed version
black --version
# For pipenv environments
pipenv install black>=26.3.1
# For poetry environments
poetry add black@^26.3.1
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


