Skip to content

harden: reject shell=True in run_command#3132

Open
PascalThuet wants to merge 1 commit into
github:mainfrom
PascalThuet:split/reject-shell-true
Open

harden: reject shell=True in run_command#3132
PascalThuet wants to merge 1 commit into
github:mainfrom
PascalThuet:split/reject-shell-true

Conversation

@PascalThuet

Copy link
Copy Markdown
Contributor

Part of splitting #2442 into smaller, dedicated PRs. Re-derived against current main (the #2442 branch is ~20 commits behind).

What

  • run_command() now rejects shell=True with ValueError instead of forwarding it to subprocess.run. The shell parameter is kept (default False) for signature / keyword-caller compatibility.
  • Enable ruff S602/S604/S605 so any future shell=True (or os.system/popen) must be acknowledged with an explicit # noqa.
  • Annotate the one intentional shell sink (the workflow ShellStep) with # noqa: S602.
  • Document the shell-step arbitrary-code-execution risk in workflows/PUBLISHING.md.

Why

run_command(shell=True) would run its argv through a shell (word-splitting, globbing, injection surface). No call site needs that mode; failing loudly prevents a future caller from silently enabling it.

Validation

  • tests/test_utils.py::test_run_command_rejects_shell_execution_compatibly passes.
  • ruff check --select S602,S604,S605 src tests/test_utils.py is clean.

Independent of the other split PRs.

run_command() forwarded shell= straight to subprocess.run, so a caller
passing shell=True would invoke a shell. Reject shell=True with ValueError
(keeping the parameter for signature compatibility) and drop shell= from
both subprocess.run calls.

Enable ruff S602/S604/S605 to flag any future shell=True reintroduction,
annotate the one intentional workflow shell sink with # noqa: S602, and
document the shell-step execution risk in workflows/PUBLISHING.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant