Skip to content

fix: use env var indirection for inputs.components (CMD_EXEC) - #179

Closed
nbuckwalt wants to merge 2 commits into
dtolnay:masterfrom
nbuckwalt:fix/cmd-exec-inputs-components
Closed

nbuckwalt wants to merge 2 commits into
dtolnay:masterfrom
nbuckwalt:fix/cmd-exec-inputs-components

Conversation

@nbuckwalt

Copy link
Copy Markdown

Security Fix: CMD_EXEC via inputs.components

Summary

`inputs.components` is directly interpolated into a `run:` shell command via a GitHub Actions expression:
```
echo "downgrade=${{steps.parse.outputs.toolchain == 'nightly' && inputs.components && ' --allow-downgrade' || ''}}" >> $GITHUB_OUTPUT
```
A caller passing a malicious value such as `'; arbitrary_command; echo '` as `components` would execute arbitrary shell code in any job using this action.

Fix

Replace the inline expression with equivalent shell logic using `env:` variables (`TOOLCHAIN`, `COMPONENTS`). Output behavior is identical: ` --allow-downgrade` (with leading space) when toolchain is `nightly` and components is non-empty, empty string otherwise.

References

🤖 Generated with Claude Code

@nbuckwalt nbuckwalt closed this Mar 26, 2026
@nbuckwalt nbuckwalt reopened this Mar 26, 2026
@nbuckwalt nbuckwalt closed this Mar 26, 2026
@nbuckwalt nbuckwalt reopened this Mar 26, 2026

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think this addresses the issue that you describe. For example components: $(arbitrary_command) would behave identically before and after this PR.

@dtolnay dtolnay closed this in #187 Oct 9, 2026
danczw added a commit to danczw/sandbx that referenced this pull request Oct 9, 2026
zizmor's ref-version-mismatch fails the audit job: the four pins carry a
`# v1` comment and upstream moved that tag off 7e38f4b to e2a55d2.

The two commits in between fix a shell injection in the action's own
action.yml, where `inputs.components` was interpolated into a `run:`
expression (dtolnay/rust-toolchain#179). No call site here was exposed —
every value passed is a workflow literal or a `steps.floor` output this
repo computes — so this takes the fix rather than removing an exposure.
epompeii added a commit to bencherdev/bencher that referenced this pull request Oct 12, 2026
## Problem

`Lint / Zizmor Online` fails on every pull request (for example run
37884500334 on #1153) with one medium finding, exit 13:

```
warning[ref-version-mismatch]: action's hash pin has mismatched or missing version comment
  --> ./.github/workflows/update_sandbox.yml:18:81
18 |       - uses: dtolnay/rust-toolchain@7e38f4b # v1
   |                                                                                 ^^ points to commit e2a55d2ffb04
```

The upstream `v1` tag of `dtolnay/rust-toolchain` moved to
`e2a55d2ffb04f378e9626c28d38b36d230d1e12f` on 2026-10-09 when
dtolnay/rust-toolchain#187 merged. The job is `continue-on-error: true`,
so it does not block a merge, but it is red on every open pull request.

## Change

Repin `update_sandbox.yml` to the commit `v1` points at today and keep
the `# v1` comment. This follows #987, #1045, and #1088, which tracked
`v1` for this same pin, and `v1` is the only tag upstream publishes. The
hash was resolved from the GitHub refs API.

## Upstream range

`7e38f4b4...e2a55d2f` is three commits, all in `action.yml`, fixing the
command injection reported in dtolnay/rust-toolchain#179:

- Every input and the parsed toolchain move out of inline `${{ }}`
expressions in `run:` scripts and into `env:` variables, quoted at each
use.
- The parsed `toolchain` output is written with a heredoc delimiter
instead of `key=value`.
- The separate step that built `--target`, `--component`, and
`--allow-downgrade` strings is folded into the install step as a bash
array.

This call site passes only `toolchain: stable`, no targets or
components, so it was never exposed, and it still runs `rustup toolchain
install stable --profile minimal --no-self-update --force-non-host`
followed by `rustup default stable --force-non-host`. No other workflow
or composite action uses this action.

## Other moving refs

Every other pin whose comment names a moving ref still matches it today:
`rui314/setup-mold@10ca16bf # v1` (14 sites),
`dawidd6/action-download-artifact@b6e2e706 # v21` (2 sites), and
`superfly/flyctl-actions/setup-flyctl@ed8efb33 # master` (3 sites, the
current `master` head). Nothing else needs a change.

## Verification

zizmor 1.25.2, the version CI pins, from the same digest-pinned image
`zizmor-action` runs
(`ghcr.io/zizmorcore/zizmor:1.25.2@sha256:14ea7f5c...`), with the
action's arguments (`--persona=regular --format=github`, plus
`--no-online-audits` for the offline job):

| Tree | Offline | Online |
| --- | --- | --- |
| `devel` | exit 0 | exit 13, `1 medium` (the finding above) |
| this branch | exit 0 | exit 0, `No findings to report` |

CI on this pull request is the final check.
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.

2 participants