CVE-2026–31900: How a Permissive Regex Led to RCE in psf/black�
A permissive regular expression in Black's GitHub Action allowed a version specifier from a pull request's pyproject.toml to be passed to pip install, enabling an attacker to install a malicious package and execute arbitrary code on the CI runner.
Published on medium.com
During a routine OSS security research session, I identified CVE-2026–31900, a High severity (CVSS: 8.7) Remote Code Execution vulnerability in black’s official GitHub Action. The vulnerability allows an attacker to execute arbitrary code on a victim repository’s CI runner, by simply opening a Pull Request, no…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The regular expression used to extract the Black version from pyproject.toml was too permissive and allowed characters such as spaces, @, and slashes, so a PEP 508 direct URL reference could be passed to pip install.
Impact
An attacker could execute arbitrary code on the victim's CI runner, potentially stealing secrets such as cloud credentials and API keys, and the GITHUB_TOKEN from a fork pull_request is read-only, which limits direct repository modification.
What the attacker needed
Use_pyproject: true in the workflow; pull_request trigger; attacker can open a PR from a fork
How it was found
- Create a fork of the victim repository.
- Add a malicious pyproject.toml with a direct URL reference in the dependencies array.
- Open a pull request from the fork.
- The pull_request trigger runs the Black action, which reads the attacker-controlled pyproject.toml.
- The action passes the URL reference to pip install, which downloads and builds the malicious package.
- The package's build backend executes arbitrary code on the runner.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Black is a tool that automatically formats Python code. Its GitHub Action can read the required Black version from a file called pyproject.toml. Because that file comes from the pull request, an attacker could put a web address there instead of a version number, and the action would download and run the attacker's code on the project's build server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.