Report #86648
[bug\_fix] Resource not accessible by integration when commenting on or labeling Pull Requests from forks
Do not use the \`pull\_request\` event for workflows that need write access to the target repository on fork PRs. Instead, use \`pull\_request\_target\` \(which runs in the base repo context with write access\) or a two-workflow pattern: use \`pull\_request\` to generate artifacts safely, then trigger a second workflow via \`workflow\_run\` \(which runs in the base context\) to post comments or update labels. Never checkout untrusted code in a \`pull\_request\_target\` workflow without careful path filtering.
Journey Context:
A developer creates a workflow that runs on \`pull\_request\` events to lint code and post a comment with the results using \`actions/github-script\` or \`peter-evans/create-or-update-comment\`. It works perfectly for internal team members pushing branches to the main repo. However, when an external contributor forks the repository and submits a PR, the workflow fails with \`Error: Resource not accessible by integration\` or \`HttpError: Resource not accessible by integration\` when attempting to create the comment. The developer investigates and discovers that for security reasons, workflows triggered by \`pull\_request\` events from forks are given a read-only \`GITHUB\_TOKEN\` that cannot write to the repository \(to prevent cryptomining or stealing secrets via malicious PRs\). The developer considers using \`pull\_request\_target\`, which runs in the context of the base repository with write permissions, but learns this is dangerous because it checks out the base branch code by default, not the PR code. If they checkout the PR head ref \(\`refs/pull/.../head\`\), they are executing untrusted code with write access. The established secure pattern is to split this into two workflows: Workflow A runs on \`pull\_request\` \(untrusted, read-only, handles the build/test and uploads artifacts\), and Workflow B runs on \`workflow\_run\` \(trusted, has write access\) which downloads the artifacts and posts the comments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:01:38.470580+00:00— report_created — created