Skip to content

Commit 0a2560b

Browse files
Harden Black action version parsing (#5031)
1 parent deab5d6 commit 0a2560b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868

6969
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->
7070

71+
- Harden parsing of `black` requirements in the GitHub Action when `use_pyproject` is
72+
enabled so that only version specifiers are accepted and direct references such as
73+
`black @ https://...` are rejected. Users should upgrade to the latest version of the
74+
action as soon as possible. This update is received automatically when using
75+
`psf/black@stable`, and is independent of the version of Black installed by the
76+
action. (#5031)
77+
7178
### Documentation
7279

7380
<!-- Major changes to documentation and policies. Small docs changes

action/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
USE_PYPROJECT = os.getenv("INPUT_USE_PYPROJECT") == "true"
1818
OUTPUT_FILE = os.getenv("OUTPUT_FILE", default="")
1919

20-
BLACK_VERSION_RE = re.compile(r"^black([^A-Z0-9._-]+.*)$", re.IGNORECASE)
20+
BLACK_VERSION_RE = re.compile(
21+
r"^black((?:\s*(?:~=|==|!=|<=|>=|<|>|===)\s*[A-Za-z0-9*+._-]+)"
22+
r"(?:\s*,\s*(?:~=|==|!=|<=|>=|<|>|===)\s*[A-Za-z0-9*+._-]+)*)\s*$",
23+
re.IGNORECASE,
24+
)
2125
EXTRAS_RE = re.compile(r"\[.*\]")
2226
EXPORT_SUBST_FAIL_RE = re.compile(r"\$Format:.*\$")
2327

docs/integrations/github_actions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ To read the version from the `pyproject.toml` file instead, set `use_pyproject`
5959
`project.optional-dependencies` table. Note that this requires Python >= 3.11, so using
6060
the setup-python action may be required, for example:
6161

62+
**Security note:** `use_pyproject` only accepts standard version specifiers for `black`
63+
(for example `==`, `~=`, `>=` and ranges like `>=25,<26`). Direct references such as
64+
`black @ https://...` are not supported. If your workflow runs on untrusted pull
65+
requests (for example from forks), prefer setting `with.version` explicitly.
66+
6267
```yaml
6368
- uses: actions/setup-python@v6
6469
with:

0 commit comments

Comments
 (0)