ci/no-pull-request-target
pull_request_target never runs untrusted code
| Severity | error |
| Tiers | all |
| Stacks | any |
| Scope | root |
| Kind | expr |
| Source | library v0.6.0 |
| Selected by | fleetlint-recommended@v0.6.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.
Sources
- https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions (guidance, Mitigating the risks of untrusted code checkout)
- https://github.com/ossf/scorecard/blob/main/docs/checks.md (standard, Dangerous-Workflow)
- https://docs.zizmor.sh/audits/ (check, dangerous-triggers)
- https://fleetlint.org/baseline/#security
Generated by fleetlint docs from catalog v0.6.0.