Skip to content

Prevent script injection in GitHub Actions workflows - #2355

Merged
ShubhamChaturvedi7 merged 3 commits into
mainfrom
fix/gha-script-injection
Jul 21, 2026
Merged

Prevent script injection in GitHub Actions workflows#2355
ShubhamChaturvedi7 merged 3 commits into
mainfrom
fix/gha-script-injection

Conversation

@ShubhamChaturvedi7

@ShubhamChaturvedi7 ShubhamChaturvedi7 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the Script Injection in GitHub Actions workflows (V2263112241).

Untrusted GitHub context values were interpolated directly into inline run: shell scripts, which allows an attacker-controlled value to be evaluated as shell code on the runner. This change binds those values to env: variables and references them as quoted shell variables, so they are treated as data rather than executable script.

Changes

.github/workflows/go-release.yml

  • Get release directory nameproject-name / version inputs moved to env ($PROJECT_NAME, $VERSION).
  • Run Go release automation script — same, and arguments quoted.
  • print diff...project-name and releaseDirName moved to env; paths quoted.

.github/workflows/smithy-diff.yml

  • Check if FILES is not emptypull_request.user.login, github.actor, and github.repository moved to env ($PR_USER, $ACTOR, $REPO) and referenced as shell variables in the comment/curl body.

Testing

  • Both workflow files validated as parseable YAML.
  • Verified no ${{ github.event* }}, ${{ github.actor }}, or ${{ steps.* }} interpolations remain inside any run: block — all such values are now in env: blocks (the recommended safe pattern).

Notes

  • Behavior is unchanged; only how untrusted values reach the shell.
  • The Generate a changelog step uses releaseDirName in a with: args: (an action input, not a run: shell body) and is workflow-generated, so it was not part of the finding and is left unchanged.

sim: https://t.corp.amazon.com/V2263112241

Untrusted GitHub context (workflow_dispatch inputs, PR author login,
github.actor) was interpolated directly into inline run: scripts,
allowing shell script injection into the runner.

Bind these values to env: variables and reference them as quoted shell
variables so they are never evaluated as shell code. Fixes ACAT finding
for go-release.yml and smithy-diff.yml.

sim: https://t.corp.amazon.com/V2263112241
@ShubhamChaturvedi7
ShubhamChaturvedi7 requested a review from a team as a code owner July 15, 2026 23:02
@github-actions

Copy link
Copy Markdown

Detected changes to the release files or to the check-files action

@github-actions

Copy link
Copy Markdown

Changes to the release files or the check-files action requires 2 approvals from CODEOWNERS

lucasmcdonald3
lucasmcdonald3 previously approved these changes Jul 20, 2026

@lucasmcdonald3 lucasmcdonald3 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.

LGTM

Style note, I'd appreciate it if you could add a prompt to your agents to follow our PR templates and ideally limit the amount of content they write there, I'm not reading all of that (https://noslopgrenade.com/)

Copilot AI 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.

Pull request overview

This PR mitigates script-injection risks in GitHub Actions workflows by preventing untrusted GitHub context values from being interpolated directly into shell run: blocks, instead routing them through env: and quoted shell variable references.

Changes:

  • Refactors smithy-diff.yml to bind PR/user/repo identifiers via env: and use them in the run: script via shell variables.
  • Refactors go-release.yml to bind project-name/version inputs via env: and quote their usage in shell commands.
  • Quotes certain shell arguments/paths to reduce unintended shell parsing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
.github/workflows/smithy-diff.yml Moves GitHub context fields into env: and references them as shell variables in the comment/curl step.
.github/workflows/go-release.yml Moves workflow_dispatch inputs into env: and quotes their usage in release automation steps.

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

Comment thread .github/workflows/go-release.yml Outdated
Comment on lines 75 to 77
chmod +x ./submodules/MaterialProviders/scripts/go-release-automation.sh
RELEASE_DIR_NAME=$(./submodules/MaterialProviders/scripts/go-release-automation.sh get_release_dir_name "${{ github.event.inputs.project-name }}" "${{ github.event.inputs.version }}")
RELEASE_DIR_NAME=$(./submodules/MaterialProviders/scripts/go-release-automation.sh get_release_dir_name "$PROJECT_NAME" "$VERSION")
echo "releaseDirName=$RELEASE_DIR_NAME" >> $GITHUB_OUTPUT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 804dd51: releaseDirName is now written using the documented heredoc-delimiter form and $GITHUB_OUTPUT is quoted.

Comment thread .github/workflows/smithy-diff.yml Outdated
Comment on lines +42 to +44
COMMENT="@${PR_USER} and @${ACTOR}, I noticed you are updating the smithy model files.\nDoes this update need new or updated javadoc trait documentation?\n Are you adding constraints inside list, map or union? Do you know about this issue: https://github.com/smithy-lang/smithy-dafny/issues/491?"
COMMENT_URL="https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/comments"
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST "$COMMENT_URL" -d "{\"body\":\"$COMMENT\"}"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 804dd51: the JSON body is now built with jq -nc --arg body "$COMMENT" '{body: $body}', which safely encodes quotes, backslashes, and newlines.

Address PR review feedback:
- Write releaseDirName via heredoc delimiter and quote $GITHUB_OUTPUT to
  avoid step-output injection.
- Build the PR comment JSON body with jq so special characters are
  safely encoded.

sim: https://t.corp.amazon.com/V2263112241
@github-actions

Copy link
Copy Markdown

Detected changes to the release files or to the check-files action

@github-actions

Copy link
Copy Markdown

Changes to the release files or the check-files action requires 2 approvals from CODEOWNERS

aws-lc-rs 1.17.3 now resolves aws-lc-sys to 0.43.0, while the direct
dependency was pinned to 0.42, causing two copies of AWS-LC to resolve
and failing the duplicate-aws-lc CI check. Align the direct pin to 0.43.
The fips profile (aws-lc-fips-sys 0.13.1) is unaffected.

sim: https://t.corp.amazon.com/V2263112241
@ShubhamChaturvedi7

Copy link
Copy Markdown
Contributor Author

Added commit eb6ffdd: bumped direct aws-lc-sys 0.42→0.43 to fix the duplicate-aws-lc check. aws-lc-rs 1.17.3 started resolving aws-lc-sys to 0.43.0 (unrelated to the workflow changes; would fail on main too). fips profile unaffected.

@github-actions

Copy link
Copy Markdown

Detected changes to the release files or to the check-files action

@github-actions

Copy link
Copy Markdown

Changes to the release files or the check-files action requires 2 approvals from CODEOWNERS

@github-actions

Copy link
Copy Markdown

Detected changes to the release files or to the check-files action

@ShubhamChaturvedi7
ShubhamChaturvedi7 merged commit a82094c into main Jul 21, 2026
129 of 132 checks passed
@ShubhamChaturvedi7
ShubhamChaturvedi7 deleted the fix/gha-script-injection branch July 21, 2026 00:25
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.

4 participants