CCyberwiki

Script injection in GitHub Actions

Script injection in GitHub Actions
ClassInjection, Software supply chain
Also known asExpression injection, template injection
CWECWE-94: Improper Control of Generation of Code
OWASP Top 10A03:2025 Software Supply Chain Failures, A05:2025 Injection
Typical severityCritical when the job holds secrets or a write token
Affectsrun: steps and actions/github-script scripts that expand text from issues, comments, commits or pull requests

A workflow step written as run: echo "${{ github.event.issue.title }}" looks as if it prints a title. GitHub pastes the text of the title into the step's script before the shell starts, and the shell then runs whatever the script says. Script injection is the abuse of that order. Someone who can open an issue, name a branch or write a pull request title puts shell syntax in it, and the runner executes it with the job's token and secrets.12 It is a form of Command injection whose vulnerable line sits in the CI/CD configuration.

Expansion before execution

A run: step becomes a temporary shell script on the runner. Before that script starts, GitHub evaluates every expression inside ${{ }} and writes the result into the text.1 The substitution has no notion of shell quoting, so the value lands verbatim wherever the expression stood.3 This title check is open to it:

- name: Check PR title
  run: |
    title="${{ github.event.pull_request.title }}"
    if [[ $title =~ ^octocat ]]; then
      echo "PR title starts with octocat"
    fi

A pull request titled a"; ls $GITHUB_WORKSPACE" closes the quoted string early. The shell receives a script that assigns a to title and then runs ls, whose output appears in the job log.1 Any other command fits in the same place.2

Fields outsiders control

Some fields of the github context are unlikely to be under the control of whoever triggers an event, such as the base repository name, a commit hash or a pull request number.2 The fields to treat as hostile usually end in title, body, message, name, email, label, ref, head_ref, default_branch or page_name. Examples are github.event.issue.title, github.event.comment.body, github.event.head_commit.message and github.head_ref.12

Branch names and email addresses look constrained, yet both carry commands. A branch name may not contain a space or a colon, and zzz";echo${IFS}"hello";# is still a valid one. An address such as `echo${IFS}hello`@example.com satisfies the email standards and runs echo when expanded into a shell.2

What the commands reach

How far an injected command gets depends on the trigger. A workflow started by pull_request gets a read-only token and no secrets. issues, issue_comment and push follow other rules, and a workflow on them can hold the repository's secrets and a token with write access.2 On pull_request_target, which runs with the target repository's permissions and secrets, an injected title from a fork reaches the repository's secrets and its token; the Pwn request article covers that trigger.4

Injected commands can read secrets passed to the step, the token that actions/checkout writes to .git/config unless persist-credentials: false is set, and values left in memory. GitHub masks secrets in the log, but masking stops nobody who prints a secret in two halves or posts it to a server.2 The repository token expires when the run ends, so an automated attack sends it out during the run and uses it through the API to change files or releases.25

The Nx compromise

On 21 August 2025 the Nx build system merged a workflow that checked pull request titles against its commit format. It ran on pull_request_target and contained this line:6

- name: Validate PR title
  run: |
    echo "Validating PR title: ${{ github.event.pull_request.title }}"

A post on X pointed out the injection that night. The team reverted the workflow on the main branch the next day, without seeing how it could expose secrets, since that workflow had none.6 A pull_request_target run uses the workflow file from the pull request's target branch, and Nx believes the attacker targeted an older branch that still carried the vulnerable version.6 The repository still used the old Actions default of read and write permissions for the token, which GitHub had changed to read-only for new repositories in February 2023 without touching existing ones. The publishing workflow also accepted workflow_dispatch, so the API could start it.4

On 24 August a pull request title carrying shell commands took the write token, pushed a branch with a replaced CI script, started the publish workflow on that branch, then deleted the branches and runs. The publish job sent the npm token to a webhook.46 On 26 August malicious versions of nx and several @nx packages stayed on npm for four hours; a postinstall script searched each machine for sensitive data and uploaded the results to public GitHub repositories. Nx spotted them because they lacked npm provenance. Afterwards it moved publishing to trusted publishing over OpenID Connect, put each release behind a manual two-factor authentication approval, and required approval for every outside contributor's workflow run.4

Safe patterns

For an inline script, the expression moves to env: and the shell reads the variable. The value is held as data and never becomes part of the generated script.27

- name: Check PR title
  env:
    TITLE: ${{ github.event.pull_request.title }}
  run: |
    if [[ "$TITLE" =~ ^octocat ]]; then
      echo "PR title starts with octocat"
    fi

The script must read "$TITLE" with shell syntax. Writing ${{ env.TITLE }} inside run: is another expansion and injectable in the same way.53 On Windows runners the default shell is PowerShell, which reads the variable as ${env:TITLE}; shell: bash keeps one syntax across runners.3

JavaScript in actions/github-script is open to the same injection through its script: input, and the fix has the same shape: pass the value in env: and read it from process.env.5 A JavaScript action that takes the value as a with: input is not affected, because no script is generated from it.7 A top-level permissions: contents: read block, raised per job only where a step needs more, limits what injected commands can do with the token; this is Principle of least privilege applied to the workflow.7

Detection

A search of .github/workflows for ${{ github.event. and ${{ github.head_ref inside run: or script: blocks lists the candidates for a manual review. CodeQL code scanning has a query for the pattern, actions/code-injection/critical, with a security severity of 9, and runs it when Actions analysis is on in default setup.57 The linter zizmor reports it as template-injection; its stricter personas flag every expansion in a code context, on the view that picking out the safe ones is more error-prone than forbidding all of them.3 OpenSSF Scorecard also checks workflows for script injection.7

Prompt for a coding agent

Review every file in .github/workflows and every composite action in this repository. Find each ${{ }} expression inside a run: block or an actions/github-script script: input whose value can come from an issue, comment, review, commit message, author name or email, branch name or pull request. Move each one into an env: entry on that step and read it with the shell variable in double quotes ("$NAME"), or process.env.NAME in github-script. Do not use ${{ env.NAME }} inside the script. Add a top-level permissions block with contents: read and raise it only in jobs that need more. List every file and line you changed.

In SecFlash

SecFlash reports outside text expanded into a workflow script as SF-SEC-801 on the Security page. A workflow on pull_request_target or workflow_run shows as SF-SEC-802, and a token with more access than its job needs as SF-SEC-804.

See also

References

  1. a b c d GitHub (2026). "Script injections". GitHub Docs.
  2. a b c d e f g h i GitHub Security Lab (n.d.). "Keeping your GitHub Actions and workflows secure Part 2: Untrusted input". GitHub Security Lab.
  3. a b c d zizmor (n.d.). "Audit Rules": template-injection. zizmor documentation.
  4. a b c d Strumpflohner, Juri (5 September 2025). "S1ngularity: What Happened, How We Responded, What We Learned". Nx blog.
  5. a b c d GitHub (n.d.). "Code injection" (actions/code-injection/critical). CodeQL query help.
  6. a b c d Nx (27 August 2025). "Malicious versions of Nx and some supporting plugins were published" (GHSA-cxm3-wv7p-598c). GitHub.
  7. a b c d e GitHub (2026). "Secure use reference". GitHub Docs.