Skip to content
Hidden Logic Lab

Review GitHub Actions pull_request_target before merge

Cursor or Claude Code applies a SKILL.md on workflow PRs that add or widen pull_request_target: untrusted PR head checkout, label gates, script injection from PR metadata, and persist-credentials — with merge-blocking findings.

Copy prompt

Cursor, Claude Code, GitHub · Coding · 40 min · Deep

Outcome

A pull_request_target SKILL.md linked from CI docs, a PR comment mapping each workflow trigger to trust boundaries and secret access, and no workflow merged that runs fork-supplied code with GITHUB_TOKEN or repository secrets.

Steps

  1. 1

    Run the skill on a fork-style pull_request_target PR

    Use a diff that checks out head.sha and runs npm test with GITHUB_TOKEN available. The skill should Block before merge.

  2. 2

    Publish trusted-SHA and label policy beside the skill

    Document which labels may trigger deploy workflows and whether checkout must stay on the base ref. The agent compares YAML to that policy, not GitHub defaults.

  3. 3

    Pair with workflow secret-scan on every workflows change

    pull_request_target is one failure mode in a broader CI threat model. Link both skills from the PR template for .github/workflows edits.

Copy prompt

The prompt to paste

Write SKILL.md for reviewing GitHub Actions workflows that use pull_request_target, untrusted PR head checkouts, or privileged label triggers. Focus on fork PR secret theft and script injection — not general workflow speed or cache tuning.

Repository context:
[.github/workflows/ layout, default branch, fork PR policy, whether fork workflows receive secrets]
[secret names and id-token usage in affected workflows — names only, e.g. GITHUB_TOKEN, AWS_ROLE, NPM_TOKEN]
[team policy: is pull_request_target ever allowed, and required approvals / trusted-SHA gates]

Workflow PR context (paste when using):
[PR link, changed workflow files, on: triggers, whether PR is from a fork]
[label names or issue_comment commands that start privileged jobs, if any]

SKILL.md must include:
1. Purpose — pull_request_target runs in the base repo context with base-branch secrets; checking out the PR head and running install/test/custom scripts is the classic path to exfiltrate GITHUB_TOKEN and cloud credentials from fork PRs.
2. When to use — any PR touching .github/workflows/** where on: includes pull_request_target, workflow_run from fork PRs, or label/issue_comment triggers that run write-capable jobs. When not to use — workflows using only pull_request on same-repo branches with no secret-bearing steps.
3. Hard rules for findings:
   - Block: checkout of the PR head (ref: ${{ github.event.pull_request.head.sha }} or pull_request head ref) followed by npm/yarn/pnpm install, tests, or arbitrary scripts while secrets.*, id-token, or cloud OIDC credentials are available; pull_request_target job that executes code paths only present on the PR branch (not base ref only); label-triggered privileged workflow (e.g. adds label "run-ci" then deploys) that is not pinned to a trusted base SHA or named approver; script injection using untrusted PR title, body, branch name, or label in run: with inline expressions without env indirection and strict allowlist; actions/checkout on untrusted ref with persist-credentials: true (default) combined with subsequent gh, git push, or credential-using steps; pull_request_target combined with any step that runs user-supplied workflow files, Makefile targets, or package.json scripts from the PR checkout.
   - Warn: pull_request_target used where pull_request + paths filter would suffice; reusable workflow called from pull_request_target without ref pin to trusted SHA; permissions: contents: write or packages: write on fork-accessible triggers without documented justification; workflow_dispatch callable after label gate without secondary approval; third-party actions on @main for steps that touch secrets on pull_request_target.
   - Note: YAML formatting, runner label changes with no secret access — never block on style alone.
4. Review steps the agent must execute:
   - List each workflow's on: block; mark which events are reachable from fork-opened PRs.
   - For every pull_request_target job: trace checkout ref; if not base.sha or default branch only, Block and quote the YAML line.
   - Map every step after checkout that invokes npm/yarn/pnpm, make, bash on repo files, or uses docker build with repo context; confirm no secrets.* or TOKEN on those steps for fork paths.
   - Inspect run: scripts and env: for github.event.pull_request.title, body, head.ref, or label names interpolated into shell without quoting discipline — flag injection.
   - Check actions/checkout persist-credentials; if checkout is untrusted, require persist-credentials: false and no subsequent git/gh that needs the token from checkout.
   - For label gates: document required label set, who can add labels, and whether the job pins checkout to base ref or uses github.sha from a trusted dispatch.
   - Compare findings to github-actions-secret-scan and CODEOWNERS policy; link sibling skill if both apply.
5. PR comment template: trigger table (workflow — event — fork reachable? — checkout ref — secrets used), findings by severity, merge recommendation.
6. Safe patterns section: pull_request for fork PRs with secrets stripped via branch protection; pull_request_target limited to comment/react/label on base ref only; manual workflow_dispatch on default branch after maintainer approval; optional trusted-bot pattern with explicit SHA pin documented by security.
7. Two example prompts: innocuous pull_request_target that only posts a comment from base checkout vs fork PR adding checkout head + npm test with secrets.
8. Pitfalls: assuming private repo blocks forks, using pull_request_target to fix fork PR CI without removing secrets from the job, trusting GitHub label permissions on public repos, forgetting composite actions in .github/actions that checkout PR heads.
9. Done means: every Block resolved or PR rejected, fork reachability stated per workflow, no secret values in review comment, persist-credentials and checkout ref named for each affected job.

Rules:
- Never print secret values; reference ${{ secrets.NAME }} and permissions by name only.
- Do not suggest disabling branch protection or "trusted" fork flags without team policy placeholder.
- Output only SKILL.md markdown.

A fork PR does not need to merge — one pull_request_target run that checks out the malicious branch and executes install scripts can exfiltrate the base repo GITHUB_TOKEN. The skill must Block checkout-of-head plus any execution step before arguing for exceptions.

Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code or GitHub.

Get new cases in your inbox

Weekly notes on new use cases and agent workflows. No product pitches.

Occasional notes on new cases. No product pitches in the first note.