What is the difference between `pull_request` and `pull_request_target`?
AdvancedConceptGitHub Actions
Answer
pull_request runs the workflow from the PR's merge commit with a read-only token and no secrets for forks, so untrusted code is contained. pull_request_target runs the workflow definition from the base branch with a write token and access to secrets, designed for labelling or commenting on fork PRs.
The danger: if a pull_request_target workflow checks out and runs the PR's code (ref: ${{ github.event.pull_request.head.sha }}), an attacker's code runs with secrets and write access (a "pwn request"). Never build or execute untrusted PR code in that context.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?IntermediateWhat are reusable workflows and how do you call one?Intermediate