Skip to content

fix(ci): remove checkout of untrusted PR head in pull_request_target workflow#187

Open
lizhengfeng101 wants to merge 1 commit into
mainfrom
fix/codeql-untrusted-checkout
Open

fix(ci): remove checkout of untrusted PR head in pull_request_target workflow#187
lizhengfeng101 wants to merge 1 commit into
mainfrom
fix/codeql-untrusted-checkout

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Collaborator

Summary

  • Remove explicit ref: github.event.pull_request.head.sha from the checkout step so that pull_request_target uses its default behavior of checking out the base branch (trusted code only)
  • PR head commits are still fetched as git objects for git diff computation but are never checked out to the working directory
  • Resolves two critical CodeQL alerts (#1, #2): actions/untrusted-checkout/critical

Context

The ocr-review.yml workflow uses pull_request_target to access secrets for fork PRs. Previously it checked out the PR head code (ref: ${{ github.event.pull_request.head.sha }}), which placed untrusted files in the working directory — a malicious fork could exploit this via crafted .npmrc, package.json, or other files to hijack subsequent npm install or other commands running with secret access.

Since ocr review --from X --to Y uses git diff between two commit objects and does not depend on the working tree contents, removing the ref: override has no functional impact.

Test plan

  • Verify ocr review --from ... --to ... still works correctly without the PR head checked out (it only needs the git objects, not the working tree)
  • Confirm the two CodeQL alerts are resolved after merge

…workflow

Remove explicit `ref: github.event.pull_request.head.sha` from the
checkout step so that pull_request_target uses its default behavior of
checking out the base branch (trusted code). PR head commits are still
fetched as git objects for diff computation but are never checked out to
the working directory. This resolves two critical CodeQL alerts
(actions/untrusted-checkout/critical).
@github-actions

Copy link
Copy Markdown

OpenCodeReview: No comments generated. Looks good to me.

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.

1 participant