From 0a1d05bfc5b4288d91e34f66bf462fce3503e706 Mon Sep 17 00:00:00 2001 From: Vinay Vyas Date: Wed, 11 Nov 2026 18:39:34 +0000 Subject: [PATCH 1/2] fix(security): verify PR author, repo, branch, and label in admin-approve-merge.sh --- sync-files/admin-approve-merge.sh | 65 ++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/sync-files/admin-approve-merge.sh b/sync-files/admin-approve-merge.sh index 5965b01..f535fee 100755 --- a/sync-files/admin-approve-merge.sh +++ b/sync-files/admin-approve-merge.sh @@ -1,9 +1,62 @@ -gh search repos --owner googleworkspace --archived=false --json name --limit 200 -q '.[].name' | while read -r repo; do - gh pr list --repo "googleworkspace/$repo" \ - --search "is:pr is:open \"chore: Synced file(s) with googleworkspace/.github\"" \ - --json url --jq '.[].url' | while read -r pr_url; do +#!/bin/bash +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euo pipefail + +EXPECTED_TITLE="chore: Synced file(s) with googleworkspace/.github" +EXPECTED_AUTHOR="googleworkspace-bot" +EXPECTED_OWNER="googleworkspace" +EXPECTED_LABEL="sync-files" +EXPECTED_BRANCH_PREFIX="sync-files-" + +gh search repos --owner "$EXPECTED_OWNER" --archived=false --json name --limit 200 -q '.[].name' | while read -r repo; do + gh pr list --repo "$EXPECTED_OWNER/$repo" \ + --state open \ + --author "$EXPECTED_AUTHOR" \ + --label "$EXPECTED_LABEL" \ + --json url,title,author,isCrossRepository,headRepositoryOwner,headRefName,labels \ + --jq '.[] | select( + .author.login == "'"$EXPECTED_AUTHOR"'" and + .isCrossRepository == false and + .headRepositoryOwner.login == "'"$EXPECTED_OWNER"'" and + (.headRefName | startswith("'"$EXPECTED_BRANCH_PREFIX"'")) and + .title == "'"$EXPECTED_TITLE"'" and + any(.labels[]; .name == "'"$EXPECTED_LABEL"'") + ) | .url' | while read -r pr_url; do + [ -z "$pr_url" ] && continue + + # Re-verify PR metadata via gh pr view before taking privileged action + verified_title="$(gh pr view "$pr_url" \ + --json title,state,author,isCrossRepository,headRepositoryOwner,headRefName,labels \ + --jq 'select( + .state == "OPEN" and + .author.login == "'"$EXPECTED_AUTHOR"'" and + .isCrossRepository == false and + .headRepositoryOwner.login == "'"$EXPECTED_OWNER"'" and + (.headRefName | startswith("'"$EXPECTED_BRANCH_PREFIX"'")) and + .title == "'"$EXPECTED_TITLE"'" and + any(.labels[]; .name == "'"$EXPECTED_LABEL"'") + ) | .title')" + + if [ "$verified_title" != "$EXPECTED_TITLE" ]; then + echo "Skipping unverified PR $pr_url" >&2 + continue + fi + echo "Processing $pr_url..." gh pr review "$pr_url" --approve Date: Wed, 11 Nov 2026 20:24:55 +0000 Subject: [PATCH 2/2] chore(ci): update copyright year to 2026 and enable lint/test checks --- .github/workflows/lint.yml | 9 ++++++--- .github/workflows/test.yml | 9 ++++++--- sync-files/admin-approve-merge.sh | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c5cb1be..abe537f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,11 +14,14 @@ name: Lint on: [push, pull_request] +permissions: + contents: read jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + with: + persist-credentials: false - run: | - echo "No lint checks"; - exit 1; + shellcheck sync-files/admin-approve-merge.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index debf465..6f78431 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,11 +14,14 @@ name: Test on: [push, pull_request] +permissions: + contents: read jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + with: + persist-credentials: false - run: | - echo "No tests"; - exit 1; + bash -n sync-files/admin-approve-merge.sh diff --git a/sync-files/admin-approve-merge.sh b/sync-files/admin-approve-merge.sh index f535fee..50146be 100755 --- a/sync-files/admin-approve-merge.sh +++ b/sync-files/admin-approve-merge.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2025 Google LLC +# Copyright 2026 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.