I'm trying to understand the security model in Github Actions (GHA). Let's say I have the following requirements on a public repo:
- Allow pull requests from forked repos to be opened
- GHA should run unit tests on pull requests
- GHA should post unit test results as a PR comment
In order for the third requirement to work, the pull request needs access to the GITHUB_TOKEN with repo write permissions. This will require the following two permissions:
- Run Workflows from fork pull requests.
- Send write tokens to Workflows from fork pull requests
Now if write tokens are sent to the Workflows in fork PRs, what's to prevent a hacker from changing the Workflow in the PR and using it for any number of malicious purposes (creating a malicious release in the original repo or exfiltrating repo secrets)? I understand you can limit the permissions of the token, but this is done within the workflow; the hacker can just as easily remove the limitations as part of the PR.
Is there any way to accomplish the three requirements without this security hole?

