Skip to content

harden: reject shell=True in run_command#3132

Merged
mnriem merged 1 commit into
github:mainfrom
PascalThuet:split/reject-shell-true
Jun 24, 2026
Merged

harden: reject shell=True in run_command#3132
mnriem merged 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the command-execution utility surface by preventing run_command() from ever invoking a shell, and adds linting + documentation guardrails to keep that posture intact going forward.

Changes:

  • Update run_command() to reject shell=True with a ValueError while preserving the keyword parameter for compatibility.
  • Enable Ruff security rules (S602/S604/S605) and explicitly annotate the one intentional shell=True usage in the workflow ShellStep.
  • Add targeted test coverage and document the security implications of workflow shell steps.
Show a summary per file
File Description
src/specify_cli/_utils.py Rejects shell=True in run_command() and removes forwarding of shell into subprocess.run.
tests/test_utils.py Adds regression test ensuring shell kw remains present/defaults False, and shell=True raises ValueError.
pyproject.toml Enables Ruff security rules to prevent reintroducing shell execution without explicit acknowledgement.
src/specify_cli/workflows/steps/shell/__init__.py Adds an explicit # noqa on the intentional shell execution sink (ShellStep).
workflows/PUBLISHING.md Documents that workflow shell steps are arbitrary code execution and provides review guidance before install.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 0

@mnriem mnriem merged commit 8e76ff3 into github:main Jun 24, 2026
11 checks passed
@mnriem

mnriem commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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.

3 participants