GHSL-2024-030: Potential secrets exfiltration from a Pull Request in docfx
The docfx repository's CI workflow used the pull_request_target trigger but explicitly checked out and ran code from the pull request's head, which could be controlled by an attacker. An attacker could open a pull request with a modified package.json script to execute arbitrary commands and exfiltrate the PERCY_TOKEN secret.
Originally disclosed on GitHub Security Lab
Insecure usage of pullrequesttarget makes docfx repository vulnerable to secrets exfiltration.
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The workflow used pull_request_target but checked out the pull request's head commit, so untrusted code ran in a privileged context with access to secrets.
Impact
Running untrusted code with a privileged repository token and access to secrets may lead to unauthorised repository modification or exfiltration of the secrets, specifically the PERCY_TOKEN.
What the attacker needed
Ability to open a pull request; attacker-controlled server
The fix
The workflow should not check out and run code from pull request heads under pull_request_target; instead use pull_request or separate privileged and unprivileged workflows.
How it was found
- Clone the repository.
- Edit templates/package.json to change the lint script to run a command that contacts an attacker-controlled server.
- Create a new branch and commit the change.
- Open a pull request.
- The ci.yml workflow triggers and runs npm run lint, executing the payload and sending a request to the attacker's server.
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 report has not been written yet. The Original tab links to the source.
A GitHub Actions workflow can be set to run when someone opens a pull request. The pull_request_target trigger is meant to run in the context of the base repository, with access to secrets, but here the workflow also checked out the code from the pull request itself. That meant an attacker could change a file in their pull request so that when the workflow ran, it executed the attacker's commands and sent secrets to them.
What is Leaked secrets?
Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.