Skip to content

fix(ci): prevent command injection via github.head_ref (H26-91) - #256

Merged
Harry-Hayes-HX merged 7 commits into
masterfrom
fix/h26-91-head-ref-injection
Aug 4, 2026
Merged

fix(ci): prevent command injection via github.head_ref (H26-91)#256
Harry-Hayes-HX merged 7 commits into
masterfrom
fix/h26-91-head-ref-injection

Conversation

@Harry-Hayes-HX

Copy link
Copy Markdown
Contributor

What

The Commit generated pages step in .github/workflows/ruby.yml interpolated ${{ github.head_ref }} directly into a shell run: block:

git push origin HEAD:${{ github.head_ref }} --force

github.head_ref is the source-branch name of the incoming PR and is attacker-controlled. Git allows branch names containing shell metacharacters, so a PR opened from a crafted branch name executed arbitrary commands on the runner (the job holds permissions: contents: write). Tracked as H26-91.

Fix

Bind the untrusted value to an env: var and reference it as a quoted shell variable, so it is passed as data rather than parsed as shell source:

env:
  HEAD_REF: ${{ github.head_ref }}
run: |
  ...
  git push origin "HEAD:$HEAD_REF" --force

This is the pattern recommended in GitHub's "Security hardening for GitHub Actions" guidance. Behaviour is unchanged for legitimate branch names.

Validation

The injection was reproduced against this workflow prior to the fix (benign id/marker payload, authorised test); with this change the branch name is no longer interpreted by the shell.

🤖 Generated with Claude Code

Harry-Hayes-HX and others added 7 commits August 4, 2026 12:16
The "Commit generated pages" step interpolated ${{ github.head_ref }}
directly into a shell run: block. Branch names may contain shell
metacharacters, so a crafted PR head branch achieved arbitrary command
execution on the runner. Bind head_ref to an env var and reference it as
a quoted shell variable so it is treated as data, not code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Harry-Hayes-HX
Harry-Hayes-HX merged commit 2773a17 into master Aug 4, 2026
4 checks passed
@Harry-Hayes-HX
Harry-Hayes-HX deleted the fix/h26-91-head-ref-injection branch August 4, 2026 13: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.

2 participants