pull_request_target + checkout (pwn request)
High severityA pull_request_target workflow runs with the base repo's secrets and a read/write token, but can be triggered from any fork. Checking out and running the PR head executes untrusted code with your secrets.
Risky
# DANGEROUS — runs fork code with base-repo secrets
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 ci && npm run build # attacker's code, your token Fixed
# SAFE — untrusted code runs with no secrets
on: pull_request # not pull_request_target
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # checks out the PR safely
- run: npm ci && npm run build