Why is the `pull_request_target` trigger a critical security risk?
In Simple Words:
The pull_request_target event runs in the context of the base repository (not the fork), granting it access to write tokens and repository secrets.
If a workflow with pull_request_target checks out the code from the untrusted fork (ref: ${{ github.event.pull_request.head.sha }}) and runs build scripts (npm run build), a malicious external contributor can submit a PR with modified npm scripts that steal your production secrets and exfiltrate them!
Golden Rule:
Never check out and execute untrusted pull request code inside a workflow triggered by pull_request_target.