Join our Newsletter — 33% off our NHI Course
Home› Guides› GitHub Actions Script Injection Guide: Finding and Fixing…
Guide Software & AI Supply Chain

GitHub Actions Script Injection Guide: Finding and Fixing Untrusted Input in run Steps

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 14 min read
On this page

GitHub Actions script injection happens when attacker-controlled text from an event, such as a pull request title or a branch name, is pasted into a shell script by a ${{ }} expression and then runs on the runner with the workflow's token and secrets. It is one of the most common vulnerability classes reported in public workflows, and it is usually fixable with a one-line change once you know where to look.

This guide is narrow by design. It covers how the injection works, which inputs to distrust, how to detect vulnerable workflows with CodeQL and review, and how to fix and prevent them. For the wider picture of tokens, runners, OIDC and organisation controls, read the GitHub and GitHub Actions Security Guide. For the closely related privileged trigger problem, see How to Find GitHub Workflows Exposed to pull_request_target Abuse. Examples here are framed for detection and prevention and contain no working payloads.

This is an independent guide from NHI Mgmt Group, based on GitHub's public documentation as of November 2026. It is not sponsored or reviewed by GitHub. Product features change, so confirm settings against GitHub's current documentation.

Key takeaways

  • GitHub describes script injection as a case where an attacker adds commands to a context and, when the workflow runs, "those strings might be interpreted as code which is then executed on the runner".
  • The root cause is template substitution: ${{ }} expressions are expanded before the shell sees the script, so quoting inside the script does not protect you.
  • The preferred fix for inline scripts is to move the untrusted value into an intermediate environment variable and reference it as a quoted shell variable.
  • Impact is set by what the job holds: the GITHUB_TOKEN scope, repository and environment secrets, cloud OIDC trust and the runner itself. Reduce those and an injection becomes a nuisance rather than a supply chain compromise.
  • CodeQL now ships built-in Actions queries for code injection, environment variable injection, untrusted checkout and artifact poisoning. Turn them on for every repository that contains workflows.
  • Treat every workflow as privileged code: review it like a deployment script, pin its dependencies and limit who can change it.

How expression substitution creates the bug

A GitHub Actions run step is a shell script that GitHub assembles from the workflow file. Before the runner executes it, every ${{ ... }} expression is evaluated and its result is written into the script text. The shell then parses the finished script. The value is not passed as data; it becomes part of the program.

GitHub's own documentation gives the canonical pattern: a step that checks whether a pull request title starts with a word by assigning title="${{ github.event.pull_request.title }}" inside run. Because the substitution happens first, a title containing a closing quote and a shell separator ends the string early and the rest of the title runs as a command. GitHub's example shows the injected command's output appearing in the job log. The same logic applies to PowerShell, Python or any other shell value: the interpreter receives code that the attacker wrote.

Three properties make this worse than ordinary command injection in an application:

  • The attacker often needs no account privileges. Anyone who can open an issue, comment, or open a pull request from a fork may be able to set the text that is substituted.
  • The runner holds credentials. The job may have a write-scoped GITHUB_TOKEN, repository secrets, package registry tokens or an OIDC trust to a cloud account.
  • The output is software. A compromised release or publish job can push code that downstream users install, which is why the Ultralytics PyPI compromise combined a GitHub Actions injection with a leftover publishing token.

The general class is covered in the Command Injection Guide. What is specific to Actions is that the template engine, not the developer's code, performs the unsafe concatenation.

Which inputs to treat as untrusted

GitHub says the github context "should be treated as potentially untrusted input" and lists the field suffixes that most often carry attacker-controlled text: body, default_branch, email, head_ref, label, message, name, page_name, ref and title.

The GitHub Security Lab article on untrusted input in GitHub Actions gives a fuller list of fields that an outside party can influence:

SourceExample fields
Issuesgithub.event.issue.title, github.event.issue.body
Pull requestsgithub.event.pull_request.title, github.event.pull_request.body, github.event.pull_request.head.ref, github.event.pull_request.head.label, github.event.pull_request.head.repo.default_branch
Comments and reviewsgithub.event.comment.body, github.event.review.body
Commitsgithub.event.commits.*.message, github.event.head_commit.message, author name and email fields
Wikigithub.event.pages.*.page_name
Branch namegithub.head_ref

Two points catch reviewers out. First, branch names and email addresses look structured but can contain shell metacharacters; both GitHub and the Security Lab warn that a valid branch name can be an attack vector. Second, the list is not complete. Any value that originates outside your control should be treated the same way, including:

  • inputs.* on workflow_dispatch and reusable workflows when callers are not fully trusted.
  • Step outputs (steps.*.outputs.*) and job outputs that were derived from untrusted data earlier in the run.
  • Content of files checked out from a pull request head, including artifacts produced by an untrusted run and consumed by a later privileged one.
  • Values fetched from external APIs, issue trackers or package metadata.

As a working rule, the only values that are safe to substitute directly into a script are ones you set yourself in the workflow file, numeric identifiers, and secrets (which carry their own exposure risk but are not attacker-chosen).

Triggers that raise the impact

The same vulnerable step is low impact or critical depending on which event runs it. The Security Lab notes that pull_request workflows from forks run with "read-only permissions and no access to secrets", while triggers such as issue_comment, issues and push can run with different permissions.

TriggerWho controls the textTypical privilegeReview priority
pull_request from a forkExternal contributorRead-only token, no secretsMedium: still review, especially on self-hosted runners
pull_request_targetExternal contributorBase repository token and secretsCritical
issues, issue_comment, pull_request_review_commentAnyone who can commentBase repository token and secretsCritical
workflow_runWhoever controlled the triggering runBase repository token and secretsHigh, especially when it downloads artifacts
push, workflow_dispatchUsers with write accessConfigured permissionsLower, but matters for insider and compromised account cases

Comment-driven automation, such as bots that react to a slash command, is a frequent source of findings because it combines a privileged trigger with free text in github.event.comment.body. Labelling and triage workflows that echo issue titles into scripts are another.

Fixing vulnerable steps

GitHub's secure use reference gives two fixes. Use both depending on the step.

Use an intermediate environment variable

For inline scripts, GitHub says the preferred approach is to set the value of the expression to an environment variable and read it from the shell. The expression is still evaluated, but its result lands in the process environment rather than in the script text, so the shell never parses it as code. Double-quote the variable to prevent word splitting.

The safe shape looks like this:

env:
  PR_TITLE: ${{ github.event.pull_request.title }}
run: |
  if [[ "$PR_TITLE" == octocat* ]]; then echo "match"; fi

Apply the same pattern in every shell: $env:PR_TITLE in PowerShell, os.environ["PR_TITLE"] in Python. The rule is that no ${{ }} expression containing untrusted data appears inside the body of run.

Pass values to an action as inputs

GitHub also recommends using a JavaScript action that takes the context value as an argument, because "the context value is not used to generate a shell script". This moves the problem rather than removing it: the Security Lab points out that some actions are themselves vulnerable if they build commands from their inputs. Review the action's source or choose well-maintained actions, and pin them to a full commit SHA as described in How to Pin GitHub Actions to Commit SHAs.

Do not hand untrusted text to other interpreters

Script injection is not limited to bash. Watch for the same substitution into:

  • Inline JavaScript in script-running actions, where an expression inside the script body becomes JavaScript source. Pass the value through env and read it from process.env.
  • Writes to environment files such as GITHUB_ENV and GITHUB_PATH. If untrusted text can add new lines to these files it can set variables or path entries for later steps. CodeQL has dedicated queries for this case, covered below.
  • API calls and CLI arguments that are later evaluated, such as gh commands assembled as strings or eval on a value.

Validate where you must branch on content

If logic genuinely depends on user text, for example parsing a slash command, match against an allowlist of exact values in a step that has no secrets and a read-only token, then pass only the validated result onward. Keep the parsing job separate from the job that holds credentials.

Limiting the blast radius

Fixing every expression is the goal, but containment means a missed one does not become a breach.

Each of these reduces what the workflow's non-human identities can do, which is the part of the attack that matters to an identity programme. The token, the secrets and the federated role are the prize; the injected shell is just the delivery route.

Detecting vulnerable workflows with CodeQL and Scorecard

GitHub states that "CodeQL can scan and detect potentially vulnerable GitHub Actions workflows", and code scanning default setup can include Actions analysis. The built-in Actions query list includes the queries most relevant here:

QueryIDWhat it finds
Code injection (critical and medium)actions-code-injection-critical, actions-code-injection-mediumUntrusted data flowing into script bodies
Environment variable built from user-controlled sourcesactions-envvar-injection-critical, actions-envvar-injection-mediumUntrusted data written into environment files
PATH environment variable built from user-controlled sourcesactions-envpath-injection-critical, actions-envpath-injection-mediumUntrusted data altering the executable search path
Checkout of untrusted code in a privileged contextactions-untrusted-checkout-critical, actions-untrusted-checkout-highPrivileged triggers that check out pull request code
Artifact poisoningactions-artifact-poisoning-critical, actions-artifact-poisoning-mediumPrivileged runs consuming artifacts from untrusted runs
Excessive secrets exposureactions-excessive-secrets-exposureJobs that expose more secrets than they use

The critical and medium split broadly reflects whether the vulnerable workflow runs with privilege. Triage critical findings first. The CodeQL Guide covers enabling default and advanced setup.

The Security Lab's earlier standalone queries noted that their script injection query "doesn't do data flow tracking between workflow steps". When reviewing results, remember that taint can cross steps and jobs through outputs and artifacts, so a clean result for one step is not proof that the workflow is safe.

OpenSSF Scorecard is a second signal. GitHub describes it as a tool that "runs a number of checks, including script injection attacks, token permissions, and pinned actions". Running it across an organisation gives a quick inventory of repositories with dangerous workflow patterns.

Fast manual triage

Where tools are not yet deployed, a reviewer can find most candidates quickly:

  1. List workflows triggered by pull_request_target, issues, issue_comment, pull_request_review, pull_request_review_comment, discussion and workflow_run.
  2. In those files, search run: blocks and script inputs for ${{ github.event., ${{ github.head_ref, ${{ inputs. and ${{ steps..
  3. For each hit, check whether the field is on the untrusted list. If it is, the step needs the environment variable fix.
  4. Record the job's token permissions and secrets so you can rank the finding by impact.

Prevention as an engineering practice

  • Make the safe pattern the template. Starter workflows, internal reusable workflows and code review checklists should all show the env pattern, so new code copies the right shape.
  • Gate workflow changes. Use CODEOWNERS on .github/workflows/ so a security-aware reviewer approves changes, and require the CodeQL check to pass on pull requests that touch workflows.
  • Prefer reusable workflows for privileged tasks. Centralising publish and deploy logic means one reviewed implementation instead of many copies.
  • Restrict allowed actions. Organisation policy can limit which actions run, which reduces the chance of a vulnerable third-party action processing untrusted input.
  • Log and alert. Watch the audit log for workflow file changes and unexpected runs of comment-triggered workflows, as described in the GitHub Audit Log Detection Guide.

Responding to a confirmed injection

If a vulnerable workflow ran on attacker input with privileges, treat every credential the job could reach as exposed:

  1. Disable the workflow and fix the step before re-enabling it.
  2. Review run logs for the affected workflow over the exposure window, looking for unexpected commands, network calls and long run times.
  3. Rotate repository, organisation and environment secrets the job could read. The GITHUB_TOKEN expires at the end of the job, but anything it pushed, tagged or published during the run must be reviewed.
  4. Check releases, packages, caches and branches for changes made during the run, and revoke any published artefacts you cannot verify.
  5. Review cloud logs for sessions issued to the workflow's OIDC identity.
  6. If a self-hosted runner executed the job, rebuild it.

For broader steps, see the GitHub Organisation Compromise Playbook.

Common failure patterns

  • Quoting the expression inside the script ("${{ ... }}") and assuming that makes it safe. Substitution happens before quoting is parsed.
  • Fixing the obvious title and body fields but leaving github.head_ref or commit author fields substituted directly.
  • Moving the value into an action input and not checking whether the action itself builds a shell command from it.
  • Running comment bots with a write-scoped token and all repository secrets available to the parsing step.
  • Treating step outputs as trusted because they were produced by the same workflow, when they were derived from untrusted text.
  • Enabling CodeQL for application languages but not for Actions, so workflow findings never appear.
  • Using self-hosted runners for public repositories or for jobs triggered by outside contributors.

Practitioner checklist

  • Enable CodeQL Actions analysis on every repository that contains workflows and triage critical injection findings first.
  • Inventory workflows on privileged triggers and review every ${{ }} expression in their scripts.
  • Replace direct substitution of untrusted fields with intermediate environment variables, double-quoted in the shell.
  • Set the organisation default GITHUB_TOKEN to read-only and declare permissions per job.
  • Separate jobs that read user text from jobs that hold secrets or write scopes.
  • Move publish and deploy secrets into protected environments, and use OIDC with narrow trust conditions for cloud access.
  • Pin third-party actions to full commit SHAs and review those that process untrusted input.
  • Protect .github/workflows/ with CODEOWNERS and required checks.
  • Keep untrusted triggers off self-hosted runners, or use ephemeral runners.
  • Write a response runbook that lists which secrets each privileged workflow can reach.

Standards and references

Related NHI Mgmt Group resources: GitHub and GitHub Actions Security Guide · How to Find GitHub Workflows Exposed to pull_request_target Abuse · CodeQL Guide · Command Injection Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.