Skip to content

fix(ci): don't checkout PR head in pull_request_target - #1311

Merged
kalbasit merged 1 commit into
mainfrom
fix/backport-workflow-security
Jun 1, 2026
Merged

kalbasit merged 1 commit into
mainfrom
fix/backport-workflow-security

Conversation

@kalbasit

@kalbasit kalbasit commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Removes ref: ${{ github.event.pull_request.head.sha }} from the actions/checkout step in the backport workflow
  • pull_request_target runs with write access to secrets (needed to create backport PRs); checking out the unreviewed fork head in this context is a CodeQL high-severity finding (alert cmd/ncps: Implement urfave/cli and the serve command #1): a malicious fork PR could place code that gets executed while the PAT is in scope
  • The korthout/backport-action resolves commit SHAs via the GitHub API — it does not require the PR branch to be the current HEAD; removing ref: makes the checkout use the base branch (trusted, reviewed code) instead

Test plan

  • Merge a PR with a backport label and verify the backport action still creates the backport PR correctly

pull_request_target runs with write access to secrets. Checking out
the untrusted PR head SHA in this context is a known SSRF/code-exec
risk (CodeQL alert #1): a malicious fork PR could place code that
later steps inadvertently execute while the PAT is in scope.

The backport action uses the GitHub API to cherry-pick commits by
SHA — it does not need the PR branch checked out as HEAD. Removing
the ref: parameter makes checkout use the base branch (trusted code)
instead.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kalbasit

kalbasit commented Jun 1, 2026

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 1, 2026
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ef2d9dbd-53df-43be-8afe-c4b329e75d6a

📥 Commits

Reviewing files that changed from the base of the PR and between f21e67c and f28ef90.

📒 Files selected for processing (1)
  • .github/workflows/backport.yml
💤 Files with no reviewable changes (1)
  • .github/workflows/backport.yml

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Updated internal CI/CD workflow configuration for improved reliability and security practices.

Walkthrough

The backport workflow's checkout action is updated to authenticate using a personal access token stored in secrets.GHA_PAT_TOKEN and removes the explicit ref parameter that pointed to the pull request head SHA.

Changes

Backport Authentication

Layer / File(s) Summary
Checkout action token configuration
.github/workflows/backport.yml
The actions/checkout@v6 step is updated to use token: ${{ secrets.GHA_PAT_TOKEN }} for authentication and the explicit ref: ${{ github.event.pull_request.head.sha }} parameter is removed.

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size:XS

Poem

A token flows through the backport's vein, 🐰
No longer chasing refs in the rain,
PAT powers the checkout stage,
Fresh credentials turn the page,
The workflow leaps with newfound might! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main security-focused change: removing the PR head checkout reference from the pull_request_target workflow step.
Description check ✅ Passed The description is directly related to the changeset, explaining the security rationale and implementation details of removing the ref parameter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@kalbasit
kalbasit merged commit e92df33 into main Jun 1, 2026
36 checks passed
@kalbasit
kalbasit deleted the fix/backport-workflow-security branch June 1, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant