Github Actions Exploitation: Dependabot
GitHub Actions workflows that auto-merge Dependabot pull requests used the github.actor context to check that the last actor was Dependabot, but an attacker could make Dependabot the last actor by triggering a force push on a PR from a fork, bypassing the check and allowing arbitrary code to be merged.
Published on synacktiv.com
Rédigé par Hugo Vincent - 06/08/2024 - dans Pentest - Téléchargement
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The workflow used github.actor (the last actor) instead of github.event.pull_request.user.login (the PR author) to verify that the PR came from Dependabot, allowing an attacker to become the last actor via a force push.
Impact
An attacker could push arbitrary code to the repository, as demonstrated on a cloned version of spring-security; the attack was not performed against the real repository.
What the attacker needed
A GitHub account; Ability to fork the target repository; Dependabot enabled on the fork; Workflow uses github.actor check
The fix
The workflows were fixed by changing the condition to check the PR author instead of the last actor.
How it was found
- Fork the vulnerable repository and add a malicious file and a vulnerable package to trigger Dependabot.
- Dependabot creates a branch and a pull request on the fork.
- Open a pull request from the Dependabot branch on the fork to the vulnerable repository.
- Trigger a force push by Dependabot on the pull request from the fork with a specific comment.
- The vulnerable workflow runs and merges the malicious file into the main branch.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
GitHub Actions are automated tasks that run when something happens in a repository, like a pull request. Dependabot is a bot that suggests dependency updates. Some workflows automatically merge Dependabot's pull requests, but they check who last acted on the PR using github.actor. An attacker can make Dependabot the last actor by causing a force push, so the check passes and the attacker's code gets merged.