CI/CD injection: CVE-2023-49291, pull_request_target, and the branch name that ran as your pipeline
A pull request title, a branch name, a commit message: all attacker-controlled, all substituted into a shell script before it runs. Combine that with a trigger that hands out write access and secrets, and a stranger's fork owns your pipeline. How the tj-actions bugs worked and how to find the pattern in your own workflows.
By Ahmed PingerPublished
9 min read5 views
- run: echo "Building PR: ${{ github.event.pull_request.title }}"
That line looks like logging. It is a shell injection. The title of a pull request is chosen by whoever opened the pull request, the ${{ }} expression is replaced with its literal text before the shell ever sees it, and if the title contains shell metacharacters they run as commands on your runner. The reason this matters more in CI than almost anywhere else is what the runner is holding: a token, your secrets, and the ability to publish.
The bug in one distinction
There are two separate mistakes here and they compound.
The first is script injection: putting attacker-controlled text into a run: step through ${{ }} interpolation. GitHub generates a temporary shell script by substituting the expression's value into the script text, so the value is code, not data. This is CWE-94, improper control of generated code, and it is the same class as SQL injection with a different interpreter.
The second is an over-privileged trigger. A workflow that only ever sees your own code can afford a scripting mistake. A workflow that runs attacker-supplied content while holding write access and secrets cannot. pull_request_target is the trigger that creates the second situation, and most of the serious incidents are the two mistakes together.
Why the trigger matters
GitHub's own reference is blunt about pull_request_target. Workflows using it "are privileged, which means they share the same cache of the main branch with other privileged workflow triggers, and may have repository write access and access to referenced secrets." It runs in the context of the base repository's default branch, not the merge commit, and its GITHUB_TOKEN keeps the repository's normal permissions rather than the read-only token a forked pull_request gets.
That combination exists for a reason: labelling or commenting on pull requests from forks needs write access, and a plain pull_request from a fork cannot do it. The danger is the step teams add next. GitHub's guidance says these workflows "must not explicitly check out untrusted code, including from pull request forks." Check out the fork's head in a pull_request_target workflow and you are now running a stranger's code with your token and your secrets in the environment. GitHub Security Lab named this a "pwn request" in 2021, and Jaroslav Lobačevski's write-up spelled out the vectors: the attacker does not need to touch your YAML, they change a build script, a package.json install hook, or a test file in their fork.
The real CVE
CVE-2023-49291 is tj-actions/branch-names, a widely used action that returns the current branch or tag name. Rated 9.3 and classed CWE-20, improper input validation, patched in version 7.0.7, published December 2023, reported by AdnaneKhan and R3x. The action's own run step interpolated github.event.pull_request.head.ref and github.head_ref, which is the branch name, directly into shell. A branch name is a string the attacker picks. A branch named to include shell metacharacters turned the action into a command executor, and because the action ran inside its callers' workflows, every workflow that used it inherited the flaw. The advisory notes the payload could steal secrets or abuse GITHUB_TOKEN permissions.
The same author's tj-actions/changed-files had the neighbouring bug, CVE-2023-51664, patched in 41.0.0. There the attacker-controlled string was a filename. A file added in a pull request, named with backticks or $( ), became a command when the list of changed files was expanded into a run: block unescaped. Two actions, two different untrusted inputs, one class.
Then the story turned around. In March 2025, tj-actions/changed-files itself was compromised: an attacker retagged many released versions to point at a malicious commit that dumped secrets into the workflow logs of everyone using it. That is CVE-2025-30066, added to CISA's Known Exploited Vulnerabilities catalog on 2025-03-18 with a due date of 2025-04-08. The lesson is not about that one action. It is that an action reference is code you run on every push, and a tag is a mutable pointer.
The consequences are not theoretical. In December 2024 the ultralytics PyPI package was published containing a cryptocurrency miner that was not in its GitHub source. The maintainers confirmed in their own issue thread that the malicious pull requests carried "code injection in the branch names," and the researcher who had reported the underlying bug identified it as a regression of GHSA-7x29-qqmq-v6qc in the project's own ultralytics/actions composite action: a run step that echoed github.head_ref and github.event.pull_request.head.ref through ${{ }}, reachable from a fork's draft pull request wherever a caller ran the action under pull_request_target. That is the CVE-2023-49291 pattern in a different action, not the tj-actions bug itself. Researchers in the same thread concluded the injected code then reached the release build through the shared Actions cache, and the output was a package on PyPI that ran on every machine that installed it.
A lab you can build
No Docker. You need act (a Go binary that runs GitHub Actions workflows locally), or, if you would rather not install anything, a plain shell that mimics how the runner substitutes expressions. The point of the lab is to see substitution happen before execution.
Create a workflow and a tiny harness that stands in for the runner's templating:
mkdir gha-lab && cd gha-lab
cat > render.sh <<'SH'
#!/usr/bin/env bash
# Stand-in for the runner: substitute the "expression", then run the script.
TITLE="$1" # attacker-controlled PR title
SCRIPT="echo \"Building PR: ${TITLE}\"" # value pasted into script text
echo "--- generated script ---"; echo "$SCRIPT"
echo "--- output ---"; bash -c "$SCRIPT"
SH
chmod +x render.sh
./render.sh 'normal title'
./render.sh 'x"; id; echo "'
The second run prints the output of id. The value was never data; it was spliced into the script and then interpreted. Now fix it the way GitHub recommends and watch the same input become inert:
cat > render_safe.sh <<'SH'
#!/usr/bin/env bash
TITLE="$1"
export TITLE # value goes into the environment, not the script text
bash -c 'echo "Building PR: $TITLE"' # shell reads it as a variable
SH
chmod +x render_safe.sh
./render_safe.sh 'x"; id; echo "'
The metacharacters print literally. The difference is the whole mitigation: the untrusted value reaches the shell as a variable, never as part of the program.
Finding it in source
Two greps and a read.
# Untrusted context fields interpolated into run: steps.
grep -rnE '\$\{\{[^}]*(github\.event\.(issue|pull_request|comment)\.(title|body)|github\.head_ref|github\.event\.pull_request\.head\.(ref|label)|github\.event\.(commits|head_commit)\.|github\.event\.review\.body|github\.event\.pages)' .github/workflows/
# Dangerous triggers, to review by hand.
grep -rnE 'pull_request_target|workflow_run|issue_comment' .github/workflows/
# Actions pinned to a tag or branch rather than a full commit SHA.
grep -rnE 'uses:.*@(v?[0-9]|main|master)' .github/workflows/
GitHub Security Lab's list of untrusted fields is the checklist: issue and pull request titles, bodies and comments, commit messages, author names and emails, branch and label names, and page names. Any of those inside a ${{ }} in a run: step is the bug. A pull_request_target block is not automatically a vulnerability, but every one is worth reading for a checkout of the PR head.
The single highest-value question for a whole organisation: is the default GITHUB_TOKEN permission read-only? GitHub's guidance is to set it so, and it turns many write-capable injections into read-only ones.
Fixing it
Move untrusted values into the environment. GitHub's documented fix is to bind the expression to an env: variable and reference the variable in the script:
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
echo "Building PR: $TITLE"
Their reference explains why it works: the expression's value "is stored in memory and used as a variable, and doesn't interact with the script generation process."
Do not check out untrusted code under a privileged trigger. If a fork's contents must be built, use the two-workflow pattern: a pull_request workflow builds the untrusted code with no secrets and a read-only token, uploads results as an artifact, and a separate workflow_run workflow does the privileged work with the artifact. GitHub Security Lab describes this pattern directly.
Pin actions to a full commit SHA. GitHub's reference states that pinning to a full-length commit SHA "is currently the only way to use an action as an immutable release." A SHA cannot be retagged under you, which is precisely the CVE-2025-30066 failure. Combine it with Dependabot so pins still get updated deliberately.
Least-privilege the token. Set permissions: explicitly per workflow and per job, defaulting to contents: read, and grant write only where a step needs it.
Detection
Static analysis in the pipeline. zizmor audits workflow files for exactly these patterns: template-injection for expressions in run steps, dangerous-triggers for pull_request_target and friends, unpinned-uses for tag-pinned actions, and excessive-permissions for broad tokens. GitHub's CodeQL ships queries for script injection and pull_request_target misuse. Run one of them on every change to .github/workflows/.
Watch the logs for what a pwn request produces. The 2025 tj-actions compromise dumped secrets into workflow logs, so a job that suddenly prints base64 blobs, environment dumps, or curl/wget to an unfamiliar host is the signal. Secret scanning on your own action logs is not paranoia here; it is the detection that fired first in that incident.
Alert on retagged actions. If you have not moved to SHA pins, monitor for an action's tag pointing at a new commit. A version you already use changing underneath you is the whole of a retagging attack.
Take this away
Every field a stranger can type into, a title, a branch name, a filename, a commit message, is untrusted input, and a ${{ }} expression in a run: step turns input into code. The trigger decides the blast radius: pull_request_target with a checkout of the fork hands your token and secrets to that code. Put untrusted values in the environment, never build untrusted code under a privileged trigger, and pin your actions to commits you have seen.
Further reading
- NVD: CVE-2023-49291 and the tj-actions/branch-names advisory GHSA-8v8w-v8xg-79rf
- NVD: CVE-2023-51664 and the tj-actions/changed-files advisory GHSA-mcph-m25j-8j63
- NVD: CVE-2025-30066 and the CISA Known Exploited Vulnerabilities Catalog
- GitHub Security Lab: Keeping your GitHub Actions and workflows secure, part 1: Preventing pwn requests
- GitHub Security Lab: part 2: Untrusted input
- GitHub Docs: Secure use reference
- GitHub Docs: Events that trigger workflows (pull_request_target)
- zizmor: static analysis for GitHub Actions
- Ultralytics issue #18027: discrepancy between GitHub and PyPI for v8.3.41
- ultralytics/actions advisory GHSA-7x29-qqmq-v6qc: the branch-name injection behind the December 2024 PyPI compromise
- CWE-94: Improper Control of Generation of Code
Was this useful?
Get the next write-up by email
New technical write-ups by email when we publish. No sales sequence, and every email has an unsubscribe link.
Prefer a feed? RSS. How we handle your address: privacy notice.
Comments
Loading comments…