/

CVE-2026-32274

Severity:

HIGH RISK

(7.5)

Path Traversal in Black Python Formatter

CVE-2026-32274

Modified

Vulnerability type

Category:

Path Traversal / Directory Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write via Cache File Path Manipulation

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A path traversal issue in Black's cache file handling allows the value of the --python-cell-magics option to be written directly into cache filenames without sanitization.

When an attacker can control this argument, they may cause Black to create or overwrite cache files in arbitrary locations on the filesystem, potentially impacting system integrity and other applications.

Affected context

This vulnerability affects environments where Black is used as a formatter and the --python-cell-magics option can be influenced by untrusted input.

It is most relevant in:

  • Shared development platforms or CI/CD pipelines that invoke Black with user-provided options
  • Editor/IDE integrations that derive formatter arguments from project or workspace configuration
  • Automation scripts or hooks (e.g., pre-commit, Git hooks) that allow contributors to affect Black's CLI options

Exploit preconditions

  • Attack surface: Command-line invocation of Black, particularly the --python-cell-magics option.
  • Required access: Ability to control or influence the arguments passed to Black (e.g., via configuration files, environment variables, or wrapper scripts).
  • Trigger point: Execution of Black with a specially crafted --python-cell-magics value, causing the cache filename computation to include attacker-controlled path elements.
  • Why exploitation is possible: The value of --python-cell-magics was used directly in constructing the cache file path without validation or normalization, enabling traversal outside the intended cache directory.

Why this happens

The core issue is the lack of input validation on a user-controllable parameter that is incorporated into filesystem paths.

By embedding the value of --python-cell-magics directly into the cache filename, Black allowed path components such as directory separators or traversal sequences to influence where cache files were written.

This maps to CWE-22: Path Traversal, where unvalidated external input is used in file and directory paths, allowing access to file system locations outside the intended scope.

Potential impact

  • Creation of arbitrary files in locations writable by the Black process
  • Overwriting of existing cache or temporary files used by other tools, potentially disrupting builds or tests
  • Assistance in multi-step attacks where crafted files (e.g., configuration, lock, or state files) can modify the behavior of other tools or services
  • Interference with CI/CD pipelines by corrupting or polluting cache directories and artifacts

General mitigation guidance

Effective mitigation centers on constraining how user-controlled values influence filesystem paths.

Common defensive patterns include:

  • Normalizing and validating all inputs that may appear in filenames, rejecting path separators and traversal sequences
  • Restricting cache and temporary files to a fixed, internal directory and using generated, non-user-derived identifiers for filenames
  • Applying allowlists for parameters that influence paths, or mapping user options to safe, canonical tokens
  • Running formatting tools in environments with least-privilege filesystem access, limiting the damage of any unintended file writes

How teams detect issues like this

Organizations can detect similar issues by:

  • Using static analysis or linters to flag concatenation of user-controllable inputs into filesystem paths
  • Reviewing CLI argument handling and configuration parsing logic for any direct use of options in filenames
  • Implementing policy checks in CI that scan for unsafe path construction patterns (e.g., use of raw user input with OS path APIs)
  • Instrumenting logging around cache or temporary file creation to highlight unexpected directories or filenames for further investigation

Sources

SourceLink
access.redhat.comaccess.redhat.com/errata/RHSA-2026:10184
access.redhat.comaccess.redhat.com/errata/RHSA-2026:13545
access.redhat.comaccess.redhat.com/errata/RHSA-2026:13553
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-32274
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2447111
github.comgithub.com/psf/black/commit/4937fe6cf241139ddbfc16b0bdbb5b422798909d
github.comgithub.com/psf/black/commit/ed770ba4dd50c419148a0fca2b43937a7447e1f9
github.comgithub.com/psf/black/pull/4176
github.comgithub.com/psf/black/pull/5038
github.comgithub.com/psf/black/releases/tag/26.3.1
github.comgithub.com/psf/black/security/advisories/GHSA-3936-cmfr-pm3m
github.comgithub.com/pypa/advisory-database/tree/main/vulns/black/PYSEC-2026-2121.yaml
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-32274.json

Frequently asked

questions

It can be, depending on how Black is integrated. If a remote user can influence the arguments or configuration used to invoke Black (for example through pull requests, notebooks, or platform settings), then exploitation may be possible remotely via that integration.

An attacker needs the ability to control or meaningfully influence the --python-cell-magics option passed to Black. This might occur through project configuration files, editor settings, or scripts that derive arguments from user-controlled content.

The safest approach is to ensure that user-controllable options are never used directly in filesystem paths. Inputs that must influence filenames should be sanitized, mapped to safe identifiers, or hashed, and cache-writing should always be constrained to a dedicated, internal directory.

Establish a development practice where all path construction passes through a validation layer, avoid embedding raw user input into filenames, enforce least-privilege file access for tooling, and use automated checks (code review guidelines and static analysis) to flag path usage that depends on external input.

Find out what's already
exploitable in your codebase.