pull_request vs pull_request_target for fork pull requests

Verdict: Use pull_request_target when a fork PR workflow needs write access and secrets; it runs in the base repository context and checks out the base ref. Never also check out the PR head under it, or untrusted code runs with secrets.

Criterionpull_requestpull_request_target
Runs inThe fork's own workflow and codeThe base repository context and workflow definition
Token for fork PRsRead-only GITHUB_TOKEN by defaultBase-repository permissions with secrets access
Default checkoutThe pull request head refThe base branch ref, which is why it is safer
Main hazardLimited: token is read-only for forksChecking out the PR head executes untrusted code with secrets

Rules

Traps