Skip to content

[automated] Prevent template injection in handwritten GitHub workflows - #21033

Open
Ankit Jain (radical) wants to merge 6 commits into
microsoft:mainfrom
radical:template-injection-fixes
Open

Ankit Jain (radical) wants to merge 6 commits into
microsoft:mainfrom
radical:template-injection-fixes

Conversation

@radical

@radical Ankit Jain (radical) commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 86505c0cd58cc13f08baa1d93b5b8bdea08b78db

Dimension Assessment Rationale
Change confidence 9/10 Selected reviews and CI/native/reproducer receipts support the changes; durable argument regression tests and fallback/failure-path execution remain missing.
Diagnosis confidence 9.5/10 Workflow interpolation and Windows batch-wrapper reparsing explain the findings and argument risk; bypassing those boundaries preserves three tested literal input classes.
Evidence fit 9.5/10 Matched Zizmor scans and hosted SARIF confirm 105 handwritten findings removed; 148 findings remain, including 21 generated-lock template findings.

Description

Zizmor flags workflow values embedded in executable shell or JavaScript; on Windows, quoted argument arrays can also regain command meaning downstream. build.cmd forwards through powershell -Command, and dotnet.cmd through CALL, allowing values such as $() or & to be reinterpreted.

This change transports workflow values through environment variables instead of executable interpolation and parses extra argument strings without evaluation. Windows test/reproducer builds use child pwsh -NoProfile -File eng/build.ps1; SDK calls invoke the repository-selected executable directly. The child boundary also preserves native build output in logs. Matrix contents pass through files rather than executable source or environment variables.

Argument strings use POSIX-style tokenization on every OS: no variable expansion, command substitution or glob expansion; malformed quoting fails explicitly. This removes the interpolation and batch-wrapper boundaries, not all downstream interpretation.

Relates to #21888.

Validation

The final diff adds the SharedArgumentParserSelectsAllConsumers routing regression test; 188 targeted selector tests passed. Argument/scenario checks below are execution evidence, not permanent forwarding tests in this PR.

  • Zizmor 1.30.1: matched scans of the integrated base and assessed head show 253 → 148 findings, with template-injection 126 → 21: 105 handwritten findings removed and zero new semantic findings. Hosted SARIF confirms the result; remaining template findings are generated locks.
  • Full CI: passed at the assessed head, including Windows x64/ARM64 Bundle builds, both Windows test-build paths and matrix execution.
  • Native Windows arguments: two named tests and the artifact/TRX verifier passed. Final test-host argv and compiled build properties preserve literal $(whoami), x&whoami and spaced values through the ordinary no-package Windows x64 path.
  • Windows reproducer: one runner built the existing Infrastructure test project and completed two iterations of four exit-code cases, all passing.

The native/reproducer runs are isolated fork validation atop the assessed revision, not source-head CI runs; production run blocks and build scripts were unchanged. Both selected reviewers accepted their bounded evidence.

Limits: both receiver receipts come from the same final test host. Three literal input classes do not prove arbitrary quoting/Unicode safety; no-.NET/empty-matrix fallbacks and failed-child/failing-iteration negative controls remain unexecuted. Scanner findings remain, and local parser/ShellCheck limitations are not a clean-scan claim.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Workflow inputs and outputs were interpolated into executable shell and
JavaScript source. Quotes or shell substitutions in those values could
change the commands being run instead of remaining literal data.

Pass values through environment variables and parse argument strings into
literal arrays without evaluating shell syntax. Transport the expanded
test matrix through files so it stays out of executable here-strings and
per-variable OS size limits.

Exercise argument parsing, enumeration, large-matrix transport, and CI
routing behavior through standalone scripts. Zizmor 1.31.0 reports 127
fewer template-injection findings; the remaining 18 generated-workflow
findings are deferred to microsoft#21031.

Refs microsoft#21031

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bc572840-cb86-4d09-829a-68af89cdce3e
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21033

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21033"

@github-actions github-actions Bot added the area-engineering-systems infrastructure helix infra engineering repo stuff label Oct 15, 2026
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 15, 2026 19:13

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.

🟡 Changes recommended

Windows batch wrappers still reinterpret parsed arguments, and the extension version override reads an unset PowerShell variable.

3 open findings
What changed in this PR

Hardens Aspire’s handwritten GitHub workflows against template injection. Generated agentic workflows remain deferred to #21031.

Changes:

  • Passes dynamic values through environment variables and parses argument strings as data.
  • Moves large test matrices through files.
  • Adds behavioral regression tests and CI selection rules.
File Description
tests/​Infrastructure.Tests/​WorkflowScripts/​TemplateInjectionTests.cs Tests argument parsing and matrix transport.
tests/​Infrastructure.Tests/​TestTriggerMap/​TestTriggerMapTests.cs Verifies shared-script CI routing.
eng/​github-ci/​test-trigger-map.yml Routes shared scripts to all consumers.
.github/​workflows/​write-test-matrix.ps1 Copies matrices with an empty fallback.
.github/​workflows/​update-nix-cli-flake.yml Passes release inputs through environment variables.
.github/​workflows/​tests.yml Uses file-based matrix transport.
.github/​workflows/​specialized-test-runner.yml Parses arguments and isolates dynamic values.
.github/​workflows/​run-tests.yml Revises build and test argument forwarding.
.github/​workflows/​reproduce-flaky-tests.yml Parses filters and isolates reproduction inputs.
.github/​workflows/​release-github-tasks.yml Isolates release inputs from shell source.
.github/​workflows/​README.md Documents input handling and matrix transport.
.github/​workflows/​polyglot-validation.yml Quotes dynamic Docker arguments.
.github/​workflows/​parse-command-line.py Adds literal argument parsing.
.github/​workflows/​labeler-predict-pulls.yml Reads workflow names from the environment.
.github/​workflows/​homebrew-validate-release.yml Isolates version and cask-path values.
.github/​workflows/​extension-unit-tests.yml Moves version overrides into the environment.
.github/​workflows/​extension-e2e-tests.yml Reads artifact URLs from the environment.
.github/​workflows/​enumerate-test-metadata.sh Extracts metadata enumeration with argument arrays.
.github/​workflows/​deployment-tests.yml Parses test arguments and isolates matrix values.
.github/​workflows/​build-packages.yml Parses version override arguments.
.github/​workflows/​build-cli-native-archives.yml Revises native build argument forwarding.
.github/​workflows/​backport.yml Reads target branches through process.env.
.github/​workflows/​backmerge-release.yml Isolates commit counts from executable source.
.github/​actions/​unlock-macos-keychain/​action.yml Quotes environment-backed keychain inputs.
.github/​actions/​enumerate-tests/​action.yml Parses build arguments and writes matrix files.
.github/​actions/​check-changed-files/​action.yml Reads the patterns path from the environment.

🧠 Review effort: Balanced

Comment thread .github/workflows/run-tests.yml Resolved
Comment thread .github/workflows/run-tests.yml Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Reusable workflow inputs were expanded into executable shell and
JavaScript source. Parsing extra arguments did not close the Windows
boundary: build.cmd reparsed them in powershell -Command, and dotnet.cmd
forwarded them through CALL.

Transport workflow values through environment variables, parse argument
strings without evaluation, and invoke eng/build.ps1 or the selected SDK
executable directly instead of forwarding parsed arguments through batch
wrappers. Transport generated test matrices through files to avoid
environment variable size limits.

Exercise production build steps through their PowerShell forwarding
boundary and add native Windows SDK argument-capture coverage. Route the
shared workflow helpers to their test consumers.

Run only the five Windows forwarding cases in the existing x64 native
archive job and require five fresh passed results. Admit reproducer
changes to CI so those inputs cannot bypass the regression.

Refs microsoft#18036

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot November 6, 2026 22:31
@radical Ankit Jain (radical) changed the title Fix template injection in handwritten GitHub workflows [automated] Prevent template injection in handwritten GitHub workflows Nov 6, 2026

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.

🟡 Changes recommended

Workflow-script tests can pass despite broken environment mappings, and missing platform-specific Python prerequisites can cause eligible tests to fail unexpectedly.

4 open issues
1 resolved since last review

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Windows archive dependencies can build successfully without producing
BuildBundleDeps.log, causing the subsequent copy and warning check to
fail. In-process PowerShell invocation does not pipe Arcade's inherited
native console handles through Tee-Object; redirecting PowerShell's
other streams alone still loses native warnings.

Run Windows builds through pwsh -NoProfile -File so the child process
output reaches the existing log pipeline. Preserve literal argument
arrays, explicit exit handling and the native warning verification.

Remove the reconstructed workflow-fragment forwarding, receipt and
admission fixtures and their dedicated Windows lane. Keep the direct
parser, enumeration and matrix-script tests, actual security-helper
routing, and existing native archive builds. The removed fixtures
reconstruct YAML bodies rather than execute complete production entries.

Refs microsoft#18036

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.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.

🟡 Changes recommended

The Windows-only tests are excluded from normal CI and cover only Python parsing, leaving the new PowerShell and dotnet argument-forwarding boundaries without regression coverage.

3 open issues
2 resolved since last review

Review effort: Balanced

Keep test metadata enumeration and matrix-file transport in their
existing action and workflow consumers. Retain the shared argument
parser because multiple entry points use its literal argument arrays.

Preserve environment-backed inputs, file-backed matrix outputs, and the
Windows child-process logging boundary. Limit runtime-input routing to
the shared parser rather than single-consumer script files.

Refs microsoft#18036

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.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.

🔵 Needs a closer look

Security-sensitive changes to Windows process boundaries and native-output capture need confirmation from pending CI that archive builds preserve dependency logs and execute the native-warning gate.

2 open issues
1 resolved since last review

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Integrate the shared Bundle.proj packaging flow without reintroducing
Windows batch-wrapper reparsing. Parse version overrides into literal
argument arrays and invoke the SDK selected by InitializeDotNetCli
through dotnet.exe.

Preserve MSBuild-owned Dashboard warning verification and update the
workflow documentation for the remaining test-build log capture.

Refs microsoft#21888

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.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.

🔵 Needs a closer look

Security-sensitive Windows argument-forwarding changes need human validation because passing CI does not establish literal native argument preservation or execution of the archive and reproducer branches.

2 open issues
1 resolved since last review

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

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.

🔵 Needs a closer look

Cross-platform security changes span shell, JavaScript, and native-process boundaries, with crafted-argument forwarding, reproducer execution, and matrix fallback paths still unverified and requiring human review.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Restore the existing explanation and documentation link for why release
checks use the App token. A read-only token cannot see drafts, so using
it would make release retries miss an existing draft.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.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.

🔵 Needs a closer look

Human assessment is needed because parser-only changes skip the independent quarantine and outerloop workflows, leaving their runsheet-argument handling unvalidated.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-engineering-systems infrastructure helix infra engineering repo stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants