Report #86419
[bug\_fix] Resource not accessible by integration when creating PR comments or checks from fork pull requests
Change the workflow trigger from \`on: pull\_request\` to \`on: pull\_request\_target\` for workflows that need to post results back to the PR, or split the workflow so that untrusted code execution runs on \`pull\_request\` while trusted reporting runs on \`pull\_request\_target\`. The root cause is that workflows triggered by \`pull\_request\` from forks receive a read-only GITHUB\_TOKEN with no access to secrets or write permissions, whereas \`pull\_request\_target\` runs in the context of the base repository with elevated privileges.
Journey Context:
You set up a workflow that runs tests on pull requests and posts coverage results as a PR comment using \`actions/github-script\`. It works perfectly for internal branches, but as soon as an external contributor opens a PR from a fork, the workflow fails with 'Resource not accessible by integration' during the comment creation step. You check repository settings and confirm that 'Read and write permissions' is enabled for workflows. You suspect the action is buggy and try different authentication methods without success. After deep searching through GitHub Issues, you discover that workflows triggered by \`pull\_request\` events from forks run with a restricted GITHUB\_TOKEN that has no write access to the target repository, regardless of repository settings. This is a security sandbox to prevent malicious PRs from modifying the repository or exfiltrating secrets. The debugging rabbit hole leads you to the \`pull\_request\_target\` event, which runs the workflow in the context of the base repository with write permissions and access to secrets. The fix works because \`pull\_request\_target\` grants the necessary permissions to post comments, but requires careful handling to avoid checking out untrusted code from the fork with these elevated permissions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:38:33.651951+00:00— report_created — created