Cloudanix VulnDB

CVE-2024-21503

Medium · 5.3

CVSS

5.3

EPSS

1.0%

Published

Mar 19, 2024

CISA due date

—

Cloudanix analysis

Next patch cycle SSVC: Track

A flaw in a widely-used code formatting tool can be exploited by an attacker using a specially crafted file to crash automated software development and deployment systems.

Exploitation
Remote Unauthenticated
Attacker needs
None
Complexity
Low
Impact
Denial Of Service
Component
Application
Class
Denial of service
Remediation
Upgrade
Effort
Medium
Patch risk
Low

What it actually does

A specially crafted string, particularly one with a large number of leading tab characters, can cause a regular expression in the `black` code formatter to exhibit catastrophic backtracking. This leads to excessive CPU consumption, effectively causing the process to hang and become unresponsive, resulting in a Regular Expression Denial of Service (ReDoS).

Why it matters to the business

Systems that automatically run the `black` formatter on untrusted code, such as CI/CD pipelines or web services, are susceptible to a denial-of-service attack. An attacker can trigger this vulnerability to disrupt development workflows, block code deployments, and consume significant compute resources, leading to operational delays and potential service outages.

How an attack unfolds

An attacker identifies a target that uses a vulnerable version of the `black` Python formatter on externally supplied code, such as a CI pipeline that checks pull requests. The attacker crafts a Python file containing a string with thousands of leading tab characters. When this file is submitted, the `black` formatter is invoked. The vulnerable regular expression in the `lines_with_leading_tabs_expanded` function enters a state of catastrophic backtracking, causing the process's CPU usage to spike to 100% and stay there. This freezes the formatting step, which in turn halts the CI/CD pipeline, preventing further builds or merges until the job is manually terminated or times out.

How to fix it

Upgrade the `black` package to version 24.3.0 or later. You can update it using pip: `pip install --upgrade black>=24.3.0`. For systems where `black` is installed via a distribution package manager (e.g., AlmaLinux), apply the corresponding vendor-supplied security updates, such as upgrading `389-ds-base` to version `1.4.3.28-6.module_el8.6.0+2734+1efaf02b` or newer. As a temporary mitigation, avoid running `black` on untrusted input or run it within a container with strict CPU and memory resource limits to contain the impact of a potential DoS.

How to confirm the fix worked

Verify that the installed version of `black` is 24.3.0 or newer by running `pip show black` or `black --version`. To test for the vulnerability, create a Python file containing a docstring with several thousand tab characters (e.g., `"""` + `\t`*5000 + `x` + `"""`) and run the installed `black` formatter on it while monitoring system CPU. A vulnerable version will exhibit sustained 100% CPU usage, while a patched version will complete quickly.

Typical attack path

  1. Attacker identifies a target system running a vulnerable version of 'black' on untrusted input, like a CI/CD pipeline.
  2. Attacker crafts a malicious Python file containing a string with an excessive number of leading tab characters.
  3. Attacker submits the malicious file to the target system (e.g., via a pull request).
  4. The automated system invokes the vulnerable 'black' process on the file.
  5. The 'black' process consumes 100% CPU, causing a denial of service for the automated task and blocking the pipeline.

How to detect it

Look for `black` processes with abnormally high and sustained CPU utilization in system monitoring tools or Application Performance Monitoring (APM) platforms. Investigate CI/CD jobs that are timing out or failing on code formatting steps. Examine the source code associated with the failed job for files containing strings with an unusually large number of consecutive tab characters, which is the trigger for this vulnerability.

  • Process name 'black' with sustained CPU usage near 100%
  • Input files containing strings with thousands of consecutive tab characters, e.g., matching regex '\t{1000,}'

What your security team should do

  • Immediately upgrade the 'black' package to version 24.3.0 or later in all CI/CD pipelines and other automated systems.
  • Audit all development and production environments to identify and upgrade any remaining vulnerable instances of 'black'.
  • Implement resource limits (CPU and memory) for tools that process untrusted input in automated pipelines as a defense-in-depth measure against future DoS vulnerabilities.

The record

Versions of the package black before 24.3.0 are vulnerable to Regular Expression Denial of Service (ReDoS) via the lines_with_leading_tabs_expanded function in the strings.py file. An attacker could exploit this vulnerability by crafting a malicious input that causes a denial of service. Exploiting this vulnerability is possible when running Black on untrusted input, or if you habitually put thousands of leading tab characters in your docstrings.

Affected packages

Ecosystem Package Introduced Fixed
PyPI black 0 24.3.0
PyPI black 0 f00093672628d212b8965a8993cee8bedf5fe9b8
Chainguard nemo 0 1.23.0-r12
Debian:11 black 0 No fix
Debian:12 black 0 No fix
Debian:13 black 0 24.4.0-1
Red Hat:ansible_automation_platform:2.4::el8 automation-controller-venv-tower 0 0:4.5.7-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 automation-hub 0 0:4.9.2-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-aiohttp 0 0:3.9.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-aiohttp-debuginfo 0 0:3.9.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-black 0 0:22.8.0-2.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-cryptography 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-cryptography-debuginfo 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-galaxy-ng 0 0:4.9.2-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-gunicorn 0 0:22.0.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-idna 0 0:3.7-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-jinja2 0 0:3.1.4-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-pillow 0 0:10.3.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-pillow-debuginfo 0 0:10.3.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-pydantic 0 0:1.10.15-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-requests 0 0:2.32.2-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-social-auth-app-django 0 0:5.4.1-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python39-sqlparse 0 0:0.5.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-aiohttp 0 0:3.9.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-aiohttp-debugsource 0 0:3.9.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-black 0 0:22.8.0-2.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-cryptography 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-cryptography-debugsource 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-galaxy-ng 0 0:4.9.2-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-gunicorn 0 0:22.0.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-idna 0 0:3.7-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-jinja2 0 0:3.1.4-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-pillow 0 0:10.3.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-pillow-debugsource 0 0:10.3.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-pydantic 0 0:1.10.15-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-requests 0 0:2.32.2-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-social-auth-app-django 0 0:5.4.1-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 python3x-sqlparse 0 0:0.5.0-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 receptor 0 0:1.4.8-1.el8ap
Red Hat:ansible_automation_platform:2.4::el8 receptorctl 0 0:1.4.8-1.el8ap
Red Hat:ansible_automation_platform:2.4::el9 automation-controller-venv-tower 0 0:4.5.7-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 automation-hub 0 0:4.9.2-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-aiohttp 0 0:3.9.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-aiohttp-debugsource 0 0:3.9.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-black 0 0:22.8.0-2.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-cryptography 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-cryptography-debugsource 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-galaxy-ng 0 0:4.9.2-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-gunicorn 0 0:22.0.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-idna 0 0:3.7-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-jinja2 0 0:3.1.4-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-pillow 0 0:10.3.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-pillow-debugsource 0 0:10.3.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-pydantic 0 0:1.10.15-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-requests 0 0:2.32.2-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-social-auth-app-django 0 0:5.4.1-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python-sqlparse 0 0:0.5.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-aiohttp 0 0:3.9.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-aiohttp-debuginfo 0 0:3.9.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-black 0 0:22.8.0-2.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-cryptography 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-cryptography-debuginfo 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-galaxy-ng 0 0:4.9.2-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-gunicorn 0 0:22.0.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-idna 0 0:3.7-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-jinja2 0 0:3.1.4-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-pillow 0 0:10.3.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-pillow-debuginfo 0 0:10.3.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-pydantic 0 0:1.10.15-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-requests 0 0:2.32.2-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-social-auth-app-django 0 0:5.4.1-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 python3-sqlparse 0 0:0.5.0-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 receptor 0 0:1.4.8-1.el9ap
Red Hat:ansible_automation_platform:2.4::el9 receptorctl 0 0:1.4.8-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el8 automation-controller-venv-tower 0 0:4.5.7-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python39-black 0 0:22.8.0-2.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python39-cryptography 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python39-cryptography-debuginfo 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python39-idna 0 0:3.7-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python39-jinja2 0 0:3.1.4-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python39-requests 0 0:2.32.2-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python3x-black 0 0:22.8.0-2.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python3x-cryptography 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python3x-cryptography-debugsource 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python3x-idna 0 0:3.7-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python3x-jinja2 0 0:3.1.4-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 python3x-requests 0 0:2.32.2-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 receptor 0 0:1.4.8-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el8 receptorctl 0 0:1.4.8-1.el8ap
Red Hat:ansible_automation_platform_developer:2.4::el9 automation-controller-venv-tower 0 0:4.5.7-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python-black 0 0:22.8.0-2.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python-cryptography 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python-cryptography-debugsource 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python-idna 0 0:3.7-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python-jinja2 0 0:3.1.4-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python-requests 0 0:2.32.2-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python3-black 0 0:22.8.0-2.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python3-cryptography 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python3-cryptography-debuginfo 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python3-idna 0 0:3.7-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python3-jinja2 0 0:3.1.4-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 python3-requests 0 0:2.32.2-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 receptor 0 0:1.4.8-1.el9ap
Red Hat:ansible_automation_platform_developer:2.4::el9 receptorctl 0 0:1.4.8-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python39-black 0 0:22.8.0-2.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python39-cryptography 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python39-cryptography-debuginfo 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python39-jinja2 0 0:3.1.4-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python3x-black 0 0:22.8.0-2.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python3x-cryptography 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python3x-cryptography-debugsource 0 0:42.0.5-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 python3x-jinja2 0 0:3.1.4-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 receptor 0 0:1.4.8-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el8 receptorctl 0 0:1.4.8-1.el8ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python-black 0 0:22.8.0-2.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python-cryptography 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python-cryptography-debugsource 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python-jinja2 0 0:3.1.4-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python3-black 0 0:22.8.0-2.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python3-cryptography 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python3-cryptography-debuginfo 0 0:42.0.5-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 python3-jinja2 0 0:3.1.4-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 receptor 0 0:1.4.8-1.el9ap
Red Hat:ansible_automation_platform_inside:2.4::el9 receptorctl 0 0:1.4.8-1.el9ap
Ubuntu:20.04:LTS black 0 No fix
Ubuntu:22.04:LTS black 0 No fix
Ubuntu:24.04:LTS black 0 No fix
Ubuntu:24.10 black 0 No fix
Ubuntu:25.04 black 0 No fix
Ubuntu:25.10 black 0 No fix
Ubuntu:Pro:20.04:LTS black 0 No fix
openSUSE:Leap 15.6 python-black 0 24.3.0-150400.9.8.1

Related vulnerabilities