Skip to content

ci: sanitize target input to prevent template injection in build build-matrix action - #12259

Open
stu10887 wants to merge 2 commits into
fluent:masterfrom
stu10887:fix/ci-template-injection-build-matrix
Open

ci: sanitize target input to prevent template injection in build build-matrix action#12259
stu10887 wants to merge 2 commits into
fluent:masterfrom
stu10887:fix/ci-template-injection-build-matrix

Conversation

@stu10887

@stu10887 stu10887 commented Aug 10, 2026

Copy link
Copy Markdown

Summary

This PR remediates a high-confidence GitHub Actions template injection risk (template-injection) in .github/actions/generate-package-build-matrix/action.yaml.

Security Impact

Direct inline expansion of ${{ inputs.target }} inside run: shell blocks allows potential code execution if user inputs contain shell metacharacters.

By mapping ${{ inputs.target }} to an intermediate environment variable (TARGET_INPUT) under an env: block, GitHub Actions safely escapes the input string prior to shell execution.

Changes Made

  • Added env: TARGET_INPUT: ${{ inputs.target }} to the Manual override of target step.
  • Replaced inline ${{ inputs.target }} expansions in the run: script with safe environment variable references ($TARGET_INPUT).
  • Verified locally using zizmor; error[template-injection] findings are resolved.

Testing & Validation

  • Verified YAML formatting and syntax.
  • Audited with zizmor locally against .github/actions/generate-package-build-matrix/action.yaml.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of manually specified build targets.
    • Added clearer logging and validation when a target override is provided.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f890fd8-4769-4dfc-8dbe-af3cd5d70ca3

📥 Commits

Reviewing files that changed from the base of the PR and between 85a357c and 45af50a.

📒 Files selected for processing (1)
  • .github/actions/generate-package-build-matrix/action.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/actions/generate-package-build-matrix/action.yaml

📝 Walkthrough

Walkthrough

The package build matrix action passes the manual target through TARGET_INPUT. The shell step uses jq --arg to construct the single-target JSON matrix.

Changes

Package build matrix

Layer / File(s) Summary
Manual target input handling
.github/actions/generate-package-build-matrix/action.yaml
The manual target uses TARGET_INPUT for validation and logging. The step uses jq --arg to generate the single-target matrix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: docs-required

Suggested reviewers: celalettin1286

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main security change in the GitHub Actions build-matrix action, despite the duplicated word "build".
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/actions/generate-package-build-matrix/action.yaml:
- Around line 102-106: Update the matrix construction around TARGET_INPUT to
pass the value through jq --arg and generate the distro array from that
argument, rather than interpolating raw shell text into JSON. Preserve the
existing compact matrix output and ensure quotes, backslashes, newlines, and
delimiter-like content remain a single valid distro entry.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f39a64c5-753b-40e8-8f35-8d641524255d

📥 Commits

Reviewing files that changed from the base of the PR and between a1d6fb1 and 85a357c.

📒 Files selected for processing (1)
  • .github/actions/generate-package-build-matrix/action.yaml

Comment thread .github/actions/generate-package-build-matrix/action.yaml Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85a357c567

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

matrix=$((
echo '{ "distro" : ['
echo '"${{ inputs.target }}"'
echo "\"$TARGET_INPUT\""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate target before exporting it to the matrix

In the manual staging-build dispatch path, this still serializes raw TARGET_INPUT into the matrix instead of JSON-encoding or validating it. For example, a target containing a JSON delimiter such as ubuntu/20.04", "centos/7 makes the override expand into multiple matrix.distro entries before call-build-linux-packages.yaml consumes it with fromJSON, so the input is not constrained to the single build target described by the action; build the matrix with jq --arg and reject values outside the known target set.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied the jq --arg refactor to safely handle string encoding and JSON generation. Thanks for the suggestion!

@stu10887
stu10887 marked this pull request as draft August 11, 2026 11:38
…ON matrix generation for target input

Signed-off-by: Stuart Rodgers <stu10887@gmail.com>

Signed-off-by: Stu <stu10887@gmail.com>
@stu10887
stu10887 marked this pull request as ready for review August 11, 2026 22:12
@stu10887

Copy link
Copy Markdown
Author

Applied the jq --arg refactor to safely handle string encoding and JSON generation. And marked the PR as ready for review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant