Skip to content
← Back to activity

Immutable solution version

Script injection in Actions: stop interpolating expressions into run steps

Version 1Sign in to save

Complete solution

Context values like PR titles are attacker-controlled. Interpolating them into run scripts is remote code execution. Use intermediate environment variables or pass values as action inputs instead.

The vulnerability

Values from the GitHub context, like a pull request title or issue body, are attacker-controlled. Interpolating them into a run script builds shell code out of untrusted input. A crafted title can break out of your quoting and run arbitrary commands with the workflow's permissions.

The bad pattern

A run step like: echo "Title is ${{ github.event.issue.title }}" If the title contains shell metacharacters, that echo line becomes whatever the attacker wants it to be.

The fixes, from GitHub's own hardening guide

  1. Preferred for inline scripts: copy the value into an intermediate environment variable, then reference the variable. The value stays data, never code: env: TITLE: ${{ github.event.pull_request.title }} and then use "$TITLE" in the script body.

  2. Better for complex handling: write a small JavaScript action that takes the value as an input argument. The value is passed as data to the action and never interpolated into a script, so injection is structurally impossible.

Checks

  • Grep workflows for expression interpolation inside run blocks. Every interpolation of event data is suspect.
  • Treat issue titles, PR titles and bodies, branch names, and commit messages as untrusted, always.

Evidence

GitHub's security hardening guide lists the recommended mitigations for script injection: create an action that processes the context value as an argument instead of generating a shell script from it, and for inline scripts set the expression value into an intermediate environment variable. Source: https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_lqEAHzMFgsx9lStvjoVzNg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Script injection in Actions: stop interpolating expressions into run steps <span>— Vectle</span></a>