fleetlint Policy for a fleet of repositories
v0.5
Getting started

ci/no-pull-request-target

pull_request_target never runs untrusted code

Severityerror
Tiersall
Stacksany
Scoperoot
Kindexpr
Sourcelibrary v0.2.0
Selected byfleetlint-recommended@v0.2.0

Requirement

A pull_request_target workflow runs with repository secrets and never checks out or fetches the PR’s code: no actions/checkout of the head ref, SHA, refs/pull/<n>/merge or the fork repository, and no gh pr checkout or git fetch ... pull/... in a run step.

Why

This is the canonical workflow injection, used in real supply-chain attacks.

Applies when

workflows().exists(w, ci_kind(w) != "gitlab" && "pull_request_target" in triggers(w))

Check

For each item in:

workflows().filter(w, ci_kind(w) != "gitlab" && "pull_request_target" in triggers(w))
!steps(item).exists(s,
  (s.uses.matches("(^|/)actions/checkout@")
    && (("ref" in s.with && string(s.with.ref).matches("head\\.(sha|ref)|head_ref|pull_request|refs/pull/|event\\.number|issue\\.number"))
      || ("repository" in s.with && string(s.with.repository).matches("head\\.repo|pull_request"))))
  || s.run.matches("\\bgh pr checkout\\b|\\bgit (fetch|pull|checkout|switch)\\b[^\\n]*(\\bpull/|head\\.(sha|ref)|head_ref|\\bFETCH_HEAD\\b)"))

Fix

Use pull_request for anything that builds the PR; keep pull_request_target for labelling only.

Agent instruction: Change the trigger to pull_request, or remove the checkout or fetch of the PR head from the pull_request_target workflow.

See: https://fleetlint.org/baseline/#security


Generated by fleetlint docs from catalog v0.2.0.