Report #7572
[bug\_fix] Resource not accessible by integration \(or HttpError: Resource not accessible by integration\) when attempting to comment on PR, push to branch, or use GitHub API in workflows triggered by pull\_request events from forks.
Change the trigger from \`pull\_request\` to \`pull\_request\_target\`, which runs in the base repository context with write permissions granted to the GITHUB\_TOKEN. Alternatively, split the workflow: use \`pull\_request\` for untrusted build steps, then trigger a privileged deployment workflow via \`workflow\_run\` which runs in the base context with secret access. When using \`pull\_request\_target\`, explicitly checkout the PR code using \`ref: $\{\{ github.event.pull\_request.head.sha \}\}\` only after verifying the code is safe to execute, or avoid running build scripts entirely to prevent pwn requests.
Journey Context:
A developer configures a workflow that posts a comment on a PR using \`actions/github-script\`. Testing on branches within the same repository works perfectly. However, when an external contributor opens a PR from a fork, the workflow fails with "Resource not accessible by integration". The developer checks the workflow logs and sees that \`GITHUB\_TOKEN\` has permissions restricted to \`contents: read\`. They attempt to add \`permissions: pull-requests: write\` at the job level, but the workflow still fails. After researching, they discover that for \`pull\_request\` events from forks, the token is strictly read-only regardless of the permissions block, as a security measure against arbitrary code execution in the base repository. The developer then learns about \`pull\_request\_target\`, which grants write permissions but runs in the base context. They refactor the workflow to use \`pull\_request\_target\`, ensuring they explicitly checkout the PR code safely. The workflow now successfully comments on external PRs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:11:55.114762+00:00— report_created — created