Report #53939
[bug\_fix] Workflow triggered by pull\_request from a fork fails with 'Resource not accessible by integration' or cannot access repository secrets needed for API calls or deployment
Change the workflow trigger from \`pull\_request\` to \`pull\_request\_target\`, and ensure the workflow checks out the code from the base repository \(not the PR\) or specifically uses \`ref: $\{\{ github.event.pull\_request.head.sha \}\}\` only after validation, to safely run with repository secrets.
Journey Context:
Maintainer sets up a workflow that deploys a preview environment or posts a comment using a third-party API key stored in repository secrets. It works perfectly for internal team members pushing branches. However, when an external contributor forks the repository and submits a pull request, the workflow fails immediately with "Resource not accessible by integration" or the secret appears empty. Maintainer checks the fork's Actions tab and sees the workflow didn't even run there \(expected\). They check the base repo Actions and see the failed run. They search and learn that \`pull\_request\` workflows from forks run in the fork's context with read-only permissions and no access to secrets, to prevent malicious PRs from exfiltrating secrets via \`echo $SECRET\`. Maintainer finds references to \`pull\_request\_target\`, which runs in the base repository context with access to secrets. They switch the trigger to \`pull\_request\_target\`. However, they must also change the checkout step because \`pull\_request\_target\` by default checks out the base branch \(main\), not the PR code. If they blindly checkout the PR code without validation, they reintroduce the security risk. The proper fix involves using \`pull\_request\_target\` to get the secrets, but checking out the code safely or using the GitHub API to get PR info without executing untrusted code. The workflow now succeeds for fork PRs because \`pull\_request\_target\` grants the job the repository's secrets and write permissions, running in a privileged context that can safely interact with the PR \(e.g., posting comments with the API\) without exposing secrets to the fork.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T21:01:56.165622+00:00— report_created — created