Comment-triggered CI can build a commit nobody reviewed
In a bug reported in November 2024, a /gcbrun comment approved one commit and Google Cloud Build ran a later one; it earned a $30,000 bounty. The same time-of-check to time-of-use race affects GitHub Actions ChatOps: /ok-to-test, .deploy and label gates that look up the pull request head after a maintainer approves. Four public cases, the checks that fail, and a workflow that binds the approval to a SHA.
By The Xalgorix Team
On 13 November 2024 Adnan Khan reported a bug in Google Cloud Build's comment control, the feature that holds builds for outside pull requests until a maintainer with write access comments /gcbrun. In his test the maintainer approved a harmless commit, 731f64a. The build that the comment started ran on b8ee164, a commit pushed after the comment, carrying an attacker-written cloudbuild.yaml. Google paid $30,000 for it.
Nothing in that chain was exotic. A person approved one thing, and the system later looked up “the latest commit on this pull request” and built that instead. The same time-of-check to time-of-use (TOCTOU) gap sits in a lot of GitHub Actions ChatOps: the /ok-to-test, /benchmark and .deploy comments that let maintainers run privileged jobs on contributors' code. This article walks through why the gap exists, four public cases, the checks that look like fixes and fail, and a workflow pattern that binds the approval to the commit it was given for.
Why a comment cannot name a commit
An issue_comment event fires for comments on issues and pull requests alike. The workflow that runs comes from the default branch, with GITHUB_SHA set to the last commit on that branch, so it gets the repository's secrets and whatever token permissions the workflow declares, even when the pull request comes from a fork. That is the point: maintainers want a privileged run, but only after a human has looked at the code.
The catch is in the payload. The event tells the workflow which issue or pull request was commented on and who wrote the comment. It does not say which commit the commenter was looking at. To build anything, the workflow has to ask GitHub for the pull request's current head, or check out refs/pull/N/head, which is the same question. Whatever the contributor pushed between the comment and that lookup is what runs.
A typical vulnerable workflow looks reasonable on review. It even checks that the commenter can write to the repository:
on:
issue_comment:
types: [created]
jobs:
integration:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/ok-to-test')
runs-on: ubuntu-latest
steps:
- name: Require write access
uses: actions/github-script@v7
with:
script: |
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo, username: context.payload.comment.user.login });
if (!['admin', 'write'].includes(data.permission)) core.setFailed('not allowed');
- uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head # mutable
- run: make integration-test
env:
STAGING_API_KEY: ${{ secrets.STAGING_API_KEY }}The permission check is correct and beside the point. It answers “may this person approve?”, not “is this the code they approved?”. The window is the job queue plus runner start-up plus every step before checkout: seconds, which is plenty for a script that polls the pull request's comments and pushes the moment an approval lands. Khan's ActionsTOCTOU tool automates that: it watches for a comment, label or environment approval and then replaces a file on the pull request head. Its README covers comment-triggered (“IssueOps”), label-gated and environment-approval variants.
Four public cases
Google Cloud Build: /gcbrun
Cloud Build received the comment and only then fetched the latest head SHA from GitHub, because the comment event carries no SHA. Khan's proof-of-concept polled for the comment every 200 milliseconds and pushed as soon as it appeared. The timeline in his write-up: reported 13 November 2024, bounty awarded 28 January 2025, marked fixed by Google on 18 June 2025, published 21 July 2025. Google's fix has two parts. A new commit cannot be triggered until it is at least five seconds old, and if a commit arrived after the last check, the maintainer has to give the full SHA. Khan reports that his attempts to beat the fix, including forged commit timestamps, failed.
dependabot-core: approval in one job, checkout in another
The same bug does not need a comment. In “Watch your Dispatch” (2 May 2025), Khan describes a workflow_dispatch workflow in dependabot/dependabot-core that took a pull request number as input, checked the pull request's approval in one job, and ran gh pr checkout in a later job. He measured about 19 seconds between the two. The building job's token had packages: write and id-token: write, so a winning push could have published signed, backdoored updater images. The fix (PR #11223, “Ensure additional commits after approval are rejected”) records the head SHA together with the approval and compares it with git rev-parse HEAD after checkout.
NVIDIA CUDA Quantum: a bot copies the code first
Boost Security's François Proulx calls the next variant bot-delegated TOCTOU (12 November 2025). In CUDA Quantum, an /ok to test comment made copy-pr-bot copy the pull request head into an in-repository branch such as pull-request/123, promoting fork code into the repository itself. The bot held contents: write and workflow: write, so what it copied could include changes to workflow files. NVIDIA moved to /ok to test <COMMIT_SHA>; Boost reports the fix confirmed on 1 May 2025.
github/branch-deploy: a TOCTOU check that trusted the attacker's clock
GitHub Security Lab's GHSL-2025-038 (Jaroslav Lobačevski) covers the IssueOps Branch Deploy action, where a .deploy comment starts a deployment. The action already checked the commenter's permission and rejected commits newer than the comment. But it compared the comment's created_at with the commit's author date, and, in the advisory's words, “the commit date is information the attacker controls.” The advisory lists the tested version as v10 and possibly earlier, with fork deployments allowed by default, and notes that an issue_comment job running on the default branch can also poison the Actions cache. It was reported on 30 January 2025; v10.4.0, released on 14 March 2025, added a deployment_confirmation feature, and the advisory was published on 22 April 2025. Branch protection that requires pull request approvals blocks the attack, the advisory says, because a new push dismisses the approval and the action then refuses to deploy.
Checks that look like fixes
Each of these shows up in real workflows, and GitHub Security Lab's fourth Actions security post (Alvaro Muñoz, 16 January 2025) explains why the first two fail:
- Comparing commit time with comment time. Git author and committer dates are whatever the pusher writes. The post says GitHub “has no reliable way to figure out the date when a commit was pushed” and calls date checks unreliable. Boost found a worse version in Jupyter Notebook's
playwright-update.yml: the check read the wrong JSON path,date -dreceived the stringnull, the comparison errored, and the job carried on. A security check that fails open protects nothing. - Checking
github.actor. The actor is the maintainer who commented. The post calls actor checks ineffective here because “the actor triggering the workflow might not be the same one trying to exploit it.” The same applies toauthor_associationor permission checks on the commenter: necessary, but they authenticate the approver, not the code. - Re-reading the head after checkout. This only helps if you compare it with a SHA captured at approval time. Comparing it with another live lookup of the head just re-runs the race.
- Separating check and build into jobs. The dependabot-core case shows that this widens the window rather than closing it.
Bind the approval to a SHA
The fixes in the Cloud Build, dependabot-core and CUDA Quantum cases share one idea: the approval carries an immutable commit ID, and the job refuses to run anything else. For a comment trigger the commenter has to supply that ID, because the event will not. This version accepts /ok-to-test <40-character SHA>, rejects the request if the head has moved, and checks again after checkout:
permissions:
contents: read # widen per job only where a job needs it
pull-requests: read # lets the gate read the PR head on private repos
jobs:
gate:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/ok-to-test ')
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.check.outputs.sha }}
repo: ${{ steps.check.outputs.repo }}
steps:
- id: check
uses: actions/github-script@v7
with:
script: |
const m = context.payload.comment.body.trim().match(/^\/ok-to-test ([0-9a-f]{40})$/);
if (!m) return core.setFailed('usage: /ok-to-test <full commit sha>');
const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo, username: context.payload.comment.user.login });
if (!['admin', 'write'].includes(perm.permission)) return core.setFailed('not allowed');
const { data: pr } = await github.rest.pulls.get({
...context.repo, pull_number: context.issue.number });
if (pr.head.sha !== m[1]) return core.setFailed('head moved since approval; re-review');
core.setOutput('sha', m[1]);
core.setOutput('repo', pr.head.repo.full_name);
integration:
needs: gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ needs.gate.outputs.repo }}
ref: ${{ needs.gate.outputs.sha }} # immutable
persist-credentials: false
- name: Refuse anything but the approved commit
env:
APPROVED: ${{ needs.gate.outputs.sha }}
run: test "$(git rev-parse HEAD)" = "$APPROVED"
- run: make integration-testNotice what the job checks: that the comment matches a strict pattern, that the commenter has write access, that the head still equals the named SHA, and, after checkout, that the commit on disk equals it too. A contributor can still push after the comment, but the new commit is not the one that runs. The SHA travels through environment variables, not ${{ }} inside a shell line, so even a gate bug does not become script injection. Every failure stops the job. Requiring the SHA to equal the current head also rejects a stale approval: approving an older commit after new pushes is a request to re-review.
If you would rather not type SHAs, two other designs bind the approval to a commit:
- Label gates on
pull_request_target. Thelabeledevent payload includes the pull request's head SHA at the time of labelling, which is why GitHub Security Lab recommends moving comment triggers to label gates. Check outgithub.event.pull_request.head.sha, neverhead.ref; the CodeQL queries below flag thehead.refversion. - Review-based approval. Boost suggests keying on
pull_request_reviewand usinggithub.event.review.commit_id, which records the commit the reviewer approved. For pull requests from forks, that event runs without secrets and with a read-only token, so it works as the record of the approval rather than as the privileged job itself.
Makefile, test fixtures, lockfiles and anything else the job executes. Keep the token at contents: read, keep deploy keys and publishing credentials in an environment with required reviewers rather than in the test job, and do not let an untrusted run write caches that privileged jobs restore.Auditing your repositories
Start by listing every workflow that a comment, label, dispatch or approval can trigger, and follow each one to the step where it gets pull request code:
grep -rnE 'issue_comment|pull_request_target|workflow_dispatch|workflow_run' .github/workflows grep -rnE 'refs/pull/|head\.ref|gh pr checkout|git fetch origin pull/' .github/workflows
Any hit in the second list inside a job from the first list deserves a close look. Then check the things grep misses:
- Run CodeQL's Actions queries
actions/untrusted-checkout-toctou/highand/critical(CWE-367). They flag checkouts that are guarded by a check but use a mutable reference, and recommend “ashainstead of aref”. - Inventory bots and GitHub Apps that react to comments. If a bot copies contributor code into your repository, as
copy-pr-botdid, the approval has to carry a SHA there too, and the bot should not holdworkflow: writeunless it needs it. - Read any homegrown TOCTOU check for fail-open paths: missing fields,
null, empty strings, a failing command whose exit code is ignored. - Check whether reusable actions in the chain resolve the head themselves. In branch-deploy the race lived inside a third-party action, not the calling workflow.
If you test for this in a bug bounty program, run the race against a repository you own that reproduces the target's workflow, not against the target. A winning run executes your code with the target's secrets, which is past most programs' rules of engagement; the workflow file plus a reproduction in your own fork is normally enough for triage. We covered the wider family of privileged Actions triggers in our pull_request_target piece; the comment trigger differs in one way that matters for review: the YAML can look careful, with a permission check and a maintainer in the loop, and still run code nobody read.
Ready to see it prove a bug?
Start scanning on Cloud →