Sub topic 3
Pwn Requests in GitHub Actions
Assume you know basic YAML, pull requests, forks, and shell commands. A pwn request is an attack where a workflow triggered by pull_request_target runs code from an untrusted pull request with the base repository's privileges.
Checking Out PR Code in `pull_request_target`
pull_request_target runs the workflow from the base branch. It can access repository secrets and a write-capable GITHUB_TOKEN. This becomes dangerous when the workflow checks out the pull request and runs its scripts:
name: unsafe-test
on: pull_request_target
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm testThe pull request can change package.json, test files, or install scripts. Those commands then run with the target repository's privileges.
Safer Workflow Design
Use pull_request for building and testing fork code. It normally provides a read-only token and no base-repository secrets. Grant only the permissions each job needs.
name: test
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm testPut privileged actions, such as labeling or publishing, in a separate workflow. Make that workflow validate the event and avoid executing files from the pull request.
flowchart TD
A[Untrusted pull request] --> B[ pull_request: build and test]
B --> C[Trusted workflow: review result]
C --> D[Privileged action with minimal permissions]`workflow_run` and Artifacts
A privileged workflow_run workflow can react after an unprivileged workflow finishes. Treat every artifact from that workflow as attacker-controlled data. Do not execute artifact scripts, load them as code, or trust paths and filenames inside them. Validate file types, extract into a safe directory, and pass only expected values to privileged steps.
Environment Files
GITHUB_ENV and GITHUB_OUTPUT are command files. Writing raw issue titles, branch names, or PR text into them can let newline characters create additional commands or outputs. Validate and encode untrusted values before writing them. Prefer passing values through env: and reading them as data.
Approvals and Actions
Fork approval settings can require a maintainer to approve the first run, but approval is a control, not a code-safety boundary. Protected environments can require reviewers before secrets become available.
Pin third-party actions to reviewed full commit SHAs instead of mutable tags such as @main. Review changes when updating the SHA.
Auditing
Run actionlint for workflow syntax and zizmor for security patterns:
actionlint .github/workflows/*.yml
zizmor .github/workflowsSearch manually for pull_request_target, checkout of head.sha, GITHUB_ENV, and scripts that interpolate ${{ }} values.
Exercise
What makes checking out github.event.pull_request.head.sha dangerous in a pull_request_target job?
Show answer
It executes attacker-controlled repository code in a workflow that may have base-repository secrets or a write-capable token.