Security rules

NGB091: Untrusted code in a privileged workflow

Reads GitHub Actions workflows (.github/workflows/*.yml) triggered by pull_request_target, workflow_run, issue_comment or pull_request_review_comment and reports jobs that check out the contributor's code (the pull request head, merge ref or the triggering run's head) — critical when a later step in the same job runs commands or a local action, because that executes attacker-controlled code with the base repository's secrets and write token..

Property Value
Rule ID NGB091
Category Supply chain
Default severity critical
CWE CWE-829, CWE-94
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reads GitHub Actions workflows (.github/workflows/*.yml) triggered by pull_request_target, workflow_run, issue_comment or pull_request_review_comment and reports jobs that check out the contributor's code (the pull request head, merge ref or the triggering run's head) — critical when a later step in the same job runs commands or a local action, because that executes attacker-controlled code with the base repository's secrets and write token.

Why it matters

These triggers exist so that workflows can label, comment on or deploy previews for pull requests from forks; they therefore run in the context of the base repository with secrets and a token that can write to it. Checking out the pull request and then running npm install, a build or tests runs the fork's package.json scripts, build config and tests — a "pwn request" that has been used to steal publishing tokens and push to default branches.

Detection behavior and supported patterns

  • actions/checkout with ref: / repository: set from github.event.pull_request.head.sha|ref|repo.full_name, github.head_ref, github.event.pull_request.number|merge_commit_sha, github.event.workflow_run.head_sha|head_branch|head_repository.full_name, github.event.issue.number or a literal refs/pull/…
  • run: steps with gh pr checkout, git fetch … pull/…, or git checkout ${{ github.event.pull_request… }}
  • Critical (high confidence) when a later step of the same job has run: or uses a local ./ action; otherwise high severity with medium confidence
  • Jobs whose if: limits them to the same repository (github.event.pull_request.head.repo.full_name == github.repository, head.repo.fork == false) are not reported

Example

TypeScript
on: pull_request_targetjobs:  test:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v4        with:          ref: ${{ github.event.pull_request.head.sha }}      - run: npm ci && npm test

Safer alternative

TypeScript
on: pull_requestjobs:  test:    runs-on: ubuntu-latest    permissions: { contents: read }    steps:      - uses: actions/checkout@v4      - run: npm ci && npm test

Remediation

Use the pull_request trigger for building and testing contributor code (no secrets, read-only token). If a privileged follow-up is needed, split it: an unprivileged pull_request workflow uploads results, and a workflow_run workflow only consumes them as data (NGB095). Never run the checked-out PR code in a job that has secrets or a write token.

False-positive considerations

  • Label-gated jobs (if: contains(github.event.pull_request.labels.*.name, 'safe to test')) are reported: a maintainer reviews one commit, but the contributor can push a new one before the job checks it out.
  • Jobs that only read files of the checkout (no run: step) are reported with medium confidence.

Known limitations

  • Code executed in a different job via uploaded artifacts is NGB095; reusable workflows called with uses: are not followed.
  • Environment protection rules (required reviewers) and repository settings that require approval for fork workflows are not visible.
  • YAML anchors / aliases and composite actions are not expanded.

References

Run it

Shell
ngbastion explain NGB091