Interview Prep/CI/CD/GitHub Actions

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.

All CI/CD questions

More on GitHub Actions