Skip to content

fix(workflows): shell step validate() rejects non-string run#3348

Merged
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/shell-step-validate-run-type
Jul 7, 2026
Merged

fix(workflows): shell step validate() rejects non-string run#3348
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/shell-step-validate-run-type

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

Description

ShellStep.validate() only checks that run is present:

if "run" not in config:
    errors.append("...missing 'run' field.")

So run: (null) or a GitHub-Actions-style list validates clean. execute() then does:

run_cmd = config.get("run", "")
...
run_cmd = str(run_cmd)   # -> 'None'  or  "['echo', 'hi']"

and invokes that under shell=True — literally running the Python repr as a command. Reproduced on main @ bba473c: validate({'id':'s','run':None}) and validate({'id':'s','run':['echo','hi']}) both return [], and execute then runs 'None' / ['echo'... (shell error "'None' is not recognized").

Fix

Add a type check after the presence check, mirroring the command-step (#3262) and gate-options validation patterns. An expression like {{ steps.x.output }} is still a str, so expression configs stay valid.

Testing

  • test_validate_rejects_non_string_run parametrized over None, a list, and an int → all now report 'run' must be a string. Fails before (validate returns [] — verified by source-stash), passes after.
  • test_validate_accepts_string_and_expression_run: plain and {{ ... }} strings return [].
  • Full TestShellStep: 11 passed. uvx ruff check clean.

Note: open PR #3328 also edits this validate() (adds timeout validation) and the TestShellStep region — I placed the new checks/tests in distinct spots to minimize any textual conflict; the two changes are independent.

AI Disclosure

  • I did use AI assistance (describe below)

Found and fixed with Claude Code (Claude Fable 5) under my direction. AI flagged the validate-vs-execute type gap; I reproduced the shell-injection of the repr, verified fail-before/pass-after, and reviewed the diff.

ShellStep.validate() only checked that 'run' was present, so run: (null)
or a GitHub-Actions-style list validated clean; execute() then
str()-coerces the value and invokes it under shell=True, literally
running 'None' or "['echo', 'hi']" as a command. Add a type check after
the presence check, mirroring the command-step (github#3262) and gate options
validation. Expression strings ('{{ ... }}') are strings, so they stay
valid.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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 tightens workflow shell-step validation to prevent non-string run values (e.g., null, lists, ints) from passing validation and later being coerced to a Python repr that gets executed under shell=True.

Changes:

  • Add a type check in ShellStep.validate() to reject non-str run values with a clear validation error.
  • Add tests to assert non-string run is rejected and that normal strings / expression strings are accepted.
Show a summary per file
File Description
src/specify_cli/workflows/steps/shell/__init__.py Enforces run must be a string during validation to prevent executing coerced repr values.
tests/test_workflows.py Adds regression tests covering rejection of non-string run values and acceptance of valid string forms.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@mnriem mnriem merged commit fb796c2 into github:main Jul 7, 2026
12 checks passed
@mnriem

mnriem commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

kanfil added a commit to tikalk/agentic-sdlc-spec-kit that referenced this pull request Jul 8, 2026
Upstream commits merged (9):

- 0151d23 agy honors SPECKIT_INTEGRATION_AGY_EXTRA_ARGS (github#3347)

- fb796c2 shell step validate() rejects non-string run (github#3348)

- 220e6fc fan-in validate() rejects non-mapping output (github#3349)

- 12faf7b workflow run/resume errors to stderr under --json (github#3352)

- d5ba062 bundle update uninstalls dropped components (github#3353)

- f1a8d8f release 0.12.7, begin 0.12.8.dev0 (github#3398)

- 10d4bca guard _sha256 against unreadable managed files (github#3376)

- a307894 return None on malformed GHES port (github#3379)

- 882e1e9 exit cleanly on malformed IPv6 URLs in add commands (github#3369)

Conflict: presets/_commands.py — combined IPv6 try/except + _esc()

with fork accent() theming.

Assisted-by: OpenCode (model: glm-5.2, autonomous)
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