Untrusted pull request code runs with a privileged token
The workflow is triggered by pull_request_target or workflow_run, which run with write access and secrets, and then checks out the pull request's own code. Anything in that fork (a build script, a package.json hook, a Makefile) now runs with your token. This is the classic "pwn request".
How to fix it. Use the plain pull_request trigger for anything that builds or tests contributor code. If you need a privileged follow-up (labelling, commenting), split it into a second workflow that never checks out the PR head.
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 install && npm teston: pull_request
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test