Who's SHA is it Anyway: Bypassing Google Cloud Build Comment Control for $30,000
A race condition in Google Cloud Build's GitHub integration allowed an attacker to bypass the maintainer review required by comment control. After a maintainer commented /gcbrun, the attacker could quickly push a new commit so the build ran on unreviewed code, potentially stealing secrets or abusing build privileges.
Published on adnanthekhan.com
I reported a subtle race condition in Google Cloud Build’s GitHub integration that could have allowed someone to bypass maintainer review when running pull request integrations tests.
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
Likely a time-of-check-time-of-use flaw: the system checked for the maintainer's comment but then fetched the latest commit SHA, which could change between the check and the build.
Impact
An attacker could create a pull request, convince a maintainer to run tests, and then quickly update the code to steal secrets or abuse the build execution role privileges.
What the attacker needed
A GitHub repository with Cloud Build integration; comment control enabled; a maintainer comments /gcbrun; attacker can push to the PR branch
The fix
Google mitigated the issue by implementing a 5-second delay before a new commit can be triggered and requiring the maintainer to specify the full SHA if there is a recent commit.
How it was found
- Create a benign pull request that changes a README file.
- Prepare a malicious cloudbuild.yaml file that runs a command.
- Run a script that polls the pull request comments every 200ms for a /gcbrun comment.
- Have a maintainer comment /gcbrun on the pull request.
- As soon as the script detects the comment, push the malicious cloudbuild.yaml to the pull request branch.
- Observe that the build runs on the new commit, after the comment.
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.
Cloud Build is a service that runs code for you when something happens on GitHub, like a pull request. To stop strangers from running code, it requires a trusted person to comment /gcbrun. The bug was that the service checked for that comment and then fetched the latest code, so an attacker could swap in bad code right after the comment.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.