Repository navigation
fix(ci): prevent PR policy checkout state pollution - #1783
Conversation
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
|
| ref: ${{ github.sha }} | ||
| persist-credentials: false |
There was a problem hiding this comment.
Critical Security Issue: pull_request_target with full checkout of untrusted PR head code.
This workflow uses pull_request_target, which runs with write permissions and access to secrets in the context of the base branch. However, ref: ${{ github.sha }} checks out the PR head commit, which is attacker-controlled code.
Previously, sparse-checkout was used as a mitigation to only check out the specific trusted script (scripts/github-actions/check-pr-commit-policy.js). Removing this isolation means the entire PR head repository is now checked out and available on disk. The next step then executes code from this untrusted checkout via require('./scripts/github-actions/check-pr-commit-policy.js').
A malicious PR author could modify check-pr-commit-policy.js (or any other file that gets loaded) to exfiltrate secrets, approve their own PR, or perform other privileged actions.
Recommendations:
- Revert the removal of
sparse-checkoutto maintain the isolation boundary, OR - Switch from
pull_request_targettopull_request(which doesn't have write permissions or secret access by default), OR - Check out the base branch version of the script instead of
${{ github.sha }}(e.g., useref: main), so only trusted code is executed.
| ref: ${{ github.sha }} | ||
| persist-credentials: false |
There was a problem hiding this comment.
Security regression: Removing sparse-checkout widens the attack surface. Previously, only scripts/github-actions/check-pr-commit-policy.js was checked out from the untrusted PR head, limiting exposure. Now the entire repository at the PR head commit is cloned into the workflow workspace.
Combined with the existing issue of using pull_request_target + ref: ${{ github.sha }}, this means all files from a potentially malicious PR are now available in the runner environment. Even though the subsequent step only require()s one specific script, other files (e.g., .npmrc, package.json, symlinks, or other scripts) could be crafted to exploit the execution environment.
If the intent is to fix the security issue, consider checking out the base branch instead (e.g., ref: ${{ github.event.pull_request.base.sha }}) and fetching PR metadata via the GitHub API. If sparse-checkout was removed for a functional reason, please re-add it to minimize exposure until the root cause (ref pointing to untrusted code) is resolved.
Summary
persist-credentials: falsesecurity boundaries.Why
The non-cone checkout left
core.sparseCheckout=truein the repository-local configuration of persistent self-hosted runner workspaces. A later checkout could disable sparse checkout through worktree configuration, then reactivate the repository-local setting when the checkout action removedextensions.worktreeConfig. Files such asgo.moddisappeared from the working tree even though they remained tracked, breaking subsequent builds.This was observed in the first attempt of the v1.13.2 release run. This change removes the source of new contamination instead of adding cleanup commands to every downstream workflow.
Validation
go.mod must survive later checkouts.node scripts/github-actions/check-pr-commit-policy.test.jspasses all 66 tests after the fix.npm run test:github-actionspasses.make checkpasses.make testpasses.make build DIST_DIR=/tmp/ocr-pr-policy-pr-buildpasses.ocr review --audience agent --background ...completed with no findings for the workflow. The test file is excluded by OCR's default selection rules and was inspected separately and exercised by the test suites.The real-Git tests exercise the pinned checkout action's relevant Git command sequence and assert that source contents, HEAD, and clean working-tree status survive subsequent checkouts. They do not execute GitHub Actions itself.
Rollout
Existing contaminated workspaces still require one-time cleanup; this change prevents new contamination rather than repairing existing repositories automatically. The three affected runner workspaces were cleaned separately. Re-enable PR Commit Policy after the fix is merged and verify a policy run followed by a normal CI build on a reused runner. This PR does not move release tags or change runner services.
AI Assistance
OpenAI Codex CLI (
gpt-6-astra, as reported by the session metadata) assisted with diagnosis, implementation, regression tests, and this PR description. The required pre-commit review usedocrwith the configured model identifierclaude-opus-5-5.Related
Follow-up to #1775.