mirror of
https://github.com/turnstonelabs/turnstone.git
synced 2026-08-12 23:12:23 -06:00
fix(ci): refuse fork PRs in the vendor-js dispatch path
The workflow_dispatch input is an arbitrary PR number, and the job used only headRefName to pick the checkout ref. For a fork PR that is a bare branch name that can collide with a branch in this repo, so the job (contents:write, ends in git push) would operate on that unrelated branch. Resolve isCrossRepository alongside headRefName and fail loudly unless the PR head lives in this repository.
This commit is contained in:
@@ -46,7 +46,16 @@ jobs:
|
||||
PR_NUMBER: ${{ inputs.pr_number }}
|
||||
run: |
|
||||
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
|
||||
ref=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json headRefName -q .headRefName)
|
||||
# The dispatch input is an arbitrary PR number; refuse fork PRs.
|
||||
# A fork's headRefName is a bare branch name that may collide
|
||||
# with a branch in this repo, and checkout+push would then hit
|
||||
# that unrelated branch ("same-repo PRs only" applies here too).
|
||||
pr_json=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json headRefName,isCrossRepository)
|
||||
if [[ "$(jq -r '.isCrossRepository' <<< "$pr_json")" != "false" ]]; then
|
||||
echo "::error::PR #${PR_NUMBER} head is not a branch in this repository; refusing to complete it."
|
||||
exit 1
|
||||
fi
|
||||
ref=$(jq -r '.headRefName' <<< "$pr_json")
|
||||
else
|
||||
ref="$HEAD_REF"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user