Report #66691
[bug\_fix] Secrets unavailable in pull\_request workflow from forks causing authentication failures
Use \`pull\_request\_target\` event \(with strict path/checkout security\) or use a two-workflow pattern with \`workflow\_run\`. Root cause: The \`pull\_request\` event runs in the context of the merge commit from the fork, which has no access to repository secrets to prevent malicious exfiltration. \`pull\_request\_target\` runs in the context of the base repository, granting secret access, but requires careful handling of untrusted code to prevent pwn requests.
Journey Context:
You have a workflow that runs integration tests requiring a private API key stored in repository secrets. It works perfectly on pushes to main and on PRs from branches within the same repository. However, when a contributor forks the repo and submits a PR from their fork, the job fails immediately with 'Error: Input required and not supplied: api-key'. You check the workflow—it's using \`on: pull\_request\`. You verify the secret exists in the repository settings. You add debug logging and confirm \`secrets.MY\_API\_KEY\` is empty in the fork PR context. Searching 'github actions secrets not available pull request fork' leads to documentation explaining the security model: \`pull\_request\` events from forks run in an unprivileged context without secret access to prevent cryptomining attacks and secret exfiltration. The solution is switching to \`pull\_request\_target\`, which runs in the base repo context with secrets, but you must be careful not to checkout the untrusted PR code directly. You refactor the workflow to use \`pull\_request\_target\`, ensuring you checkout the base repository code or carefully sanitize inputs, and the secret becomes available. Alternatively, you implement a two-workflow pattern where the untrusted code runs in \`pull\_request\` without secrets, then uploads artifacts, and a privileged \`workflow\_run\` workflow processes them with secrets. The fork PRs now pass because they can access the necessary credentials through the secure context switch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:25:29.357671+00:00— report_created — created