კითხვაIs pull_request_target OK for labeling and linting PRs from forks?

SL Sara L. წევრი რეგისტრაცია: 17 ივლ. 2026
პოსტები: 80
#1

I want a workflow that labels PRs from forks and comments the lint result. With pull_request the token from a fork is read-only, so the comment fails. pull_request_target gives a write token, but the docs are full of scary warnings.

Is it fine if I check out the PR code in pull_request_target and just run lint on it?

YS Yury Slinkin თანამშრომელი · ადმინი რეგისტრაცია: 6 ივნ. 2026
პოსტები: 94
#2

No, that is exactly the combination the warnings are about. pull_request_target runs in the context of your repository: with your secrets, a write token and access to your Actions cache. If it then checks out the PR head and runs anything from it, the attacker's code runs with all of that. "Just lint" counts: npm install runs lifecycle scripts, and lint configs are JavaScript too.

A real chain from this year: the TanStack attack (Orca, 12.05.2026) went through pull_request_target, poisoned the Actions cache, stole an OIDC token and published malicious versions, and their provenance was valid. Write-up: https://orca.security/resources/blog/tanstack-npm-supply-chain-worm/

Split it in two workflows:

# .github/workflows/pr-check.yml: untrusted code, read-only token, no secrets
on: pull_request

permissions:
  contents: read

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        with:
          persist-credentials: false
      - run: npm ci --ignore-scripts
      - run: npm run lint
# .github/workflows/pr-label.yml: trusted context, never checks out PR code
on: pull_request_target

permissions:
  contents: read
  pull-requests: write

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/labeler@v5

The labeler only reads the changed file list and its config from the base branch, so nothing from the fork is executed.

ER Evgeny Rudenko წევრი რეგისტრაცია: 14 აგვ. 2026
პოსტები: 86
#3

If you need the lint result in a comment, use a third workflow on workflow_run: the first one uploads the result as an artifact, the second one (trusted, with a write token) downloads it and posts it. Treat that artifact as untrusted data: parse it, never execute it, never put it into a shell command as is.

Same for anything from the event. Do not interpolate it straight into run:

      # don't: a PR title like "; curl ... | sh" becomes part of the script
      - run: echo "${{ github.event.pull_request.title }}"

      # do: pass it through an environment variable
      - run: echo "Title: $TITLE"
        env:
          TITLE: ${{ github.event.pull_request.title }}
SL Sara L. წევრი რეგისტრაცია: 17 ივლ. 2026
პოსტები: 80
#4

Wait, the malicious TanStack versions had valid provenance? Then what is provenance even for?

YS Yury Slinkin თანამშრომელი · ადმინი რეგისტრაცია: 6 ივნ. 2026
პოსტები: 94
#5

Provenance answers "which repository, workflow and commit built this package", signed through Sigstore. The npm docs say it plainly: it does not guarantee the code is not malicious. If the attacker runs inside the legitimate workflow, the attestation is genuine.

It is still useful: a package published from someone's laptop with a stolen token will have no provenance, or one pointing to the wrong repository. Checking it is one command after install:

npm ci
npm audit signatures

Docs: https://docs.npmjs.com/generating-provenance-statements

The SLSA folks wrote up where these guarantees end in "Mini Shai-Hulud: Where SLSA's Boundaries Fall" (15.05.2026), worth reading: https://slsa.dev/

TP Tomasz P. წევრი რეგისტრაცია: 30 ივნ. 2026
პოსტები: 84
#6

Question: my repo is private, no forks from outside. Does this matter for me?

ER Evgeny Rudenko წევრი რეგისტრაცია: 14 აგვ. 2026
პოსტები: 86
#7

Less, but it does. Private repositories can still be forked inside the organisation if that setting is on, and "untrusted input" is not only forks: branch names, PR titles, issue texts, artifacts. A colleague's account can be compromised too. The same rules work everywhere: minimal permissions per job, no event data straight in run, no untrusted code next to secrets.

სწრაფი პასუხი

წერა შეუძლიათ მხოლოდ შესულ წევრებს. შესვლა