Skip to content

fix(ci): prevent PR policy checkout state pollution - #1783

Merged
lizhengfeng101 merged 1 commit into
mainfrom
fix/pr-policy-checkout-state
Oct 20, 2026
Merged

lizhengfeng101 merged 1 commit into
mainfrom
fix/pr-policy-checkout-state

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Summary

  • Replace the PR Commit Policy workflow's single-file, non-cone sparse checkout with the default full working-tree checkout, while retaining shallow history.
  • Preserve the trusted base SHA, read-only permissions, and persist-credentials: false security boundaries.
  • Add real-Git regression tests for fresh and previously cleaned sparse workspaces, and reject sparse-checkout inputs in the workflow contract.

Why

The non-cone checkout left core.sparseCheckout=true in 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 removed extensions.worktreeConfig. Files such as go.mod disappeared 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

  • The new regression test fails with the original workflow: go.mod must survive later checkouts.
  • node scripts/github-actions/check-pr-commit-policy.test.js passes all 66 tests after the fix.
  • npm run test:github-actions passes.
  • make check passes.
  • make test passes.
  • make build DIST_DIR=/tmp/ocr-pr-policy-pr-build passes.
  • Required 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 used ocr with the configured model identifier claude-opus-5-5.

Related

Follow-up to #1775.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 2 issue(s) in this PR.

  • ✅ Successfully posted inline: 2 comment(s)

Comment on lines 28 to 29
ref: ${{ github.sha }}
persist-credentials: false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · critical
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:

  1. Revert the removal of sparse-checkout to maintain the isolation boundary, OR
  2. Switch from pull_request_target to pull_request (which doesn't have write permissions or secret access by default), OR
  3. Check out the base branch version of the script instead of ${{ github.sha }} (e.g., use ref: main), so only trusted code is executed.

Comment on lines 28 to 29
ref: ${{ github.sha }}
persist-credentials: false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · critical
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.

@css521 css521 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants