Report #39043
[bug\_fix] Secrets and GITHUB\_TOKEN are empty or unavailable in workflows triggered by pull requests from forks
Replace the \`pull\_request\` event with \`pull\_request\_target\` \(ensuring you checkout the base repository code, not the PR code, to prevent secret exfiltration\) or use a two-workflow pattern where an untrusted \`pull\_request\` workflow builds artifacts and uploads them, then a trusted \`workflow\_run\` workflow \(with secrets\) downloads and publishes them.
Journey Context:
A maintainer sets up a workflow that runs tests requiring API keys stored in repository secrets. The workflow triggers on \`pull\_request\`. When a trusted team member opens a PR from a branch within the repository, the workflow succeeds and accesses the secrets. However, when an external contributor forks the repository and opens a PR, the workflow runs but immediately fails with "Input required and not supplied: API\_KEY" or the secret appears as empty string. The maintainer checks the fork's settings, but secrets aren't inherited by design. After investigating, the maintainer discovers GitHub's security model prevents secrets in \`pull\_request\` workflows from forks to prevent malicious exfiltration. The maintainer initially considers switching to \`pull\_request\_target\`, which runs in the base repository context with secrets, but reads warnings about checkout security \(must checkout \`github.event.pull\_request.base.sha\` not \`github.head\_ref\` to prevent arbitrary code execution\). They implement \`pull\_request\_target\` with strict ref checking. Alternatively, they might implement the \`workflow\_run\` pattern: workflow A \(pull\_request\) builds and uploads artifact untrusted, workflow B \(workflow\_run, trusted with secrets\) downloads and deploys/tests.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:00:29.419324+00:00— report_created — created