Commit 673cbf4
fix(CI): verify that commit-sha is the head of pr-number in ci-kickoff-manual (#11174)
The `ci-kickoff-manual` workflow takes a `commit-sha` and a `pr-number`
input, with the intention that the commit belongs to that PR. Nothing
checked this.
A mismatch would run CI on unrelated code while reporting commit
statuses and PR comments against the PR, and — because the auto-fix jobs
in `ci-pr-only.yml` do `git push origin HEAD:'${{ inputs.head-ref }}'` —
would let did-check / buf-format / cargo-lock fixups derived from a
foreign tree be pushed onto the PR's head branch.
## Changes
- `get-pr-refs` already fetches the PR, so it is extended to verify that
`commit-sha` is the **head commit** of the PR, and renamed to
`verify-inputs-and-get-pr-refs`.
- It also rejects a `pr-number` that isn't a positive decimal integer or
a `commit-sha` that isn't a full 40-hex SHA, and refuses non-open PRs.
- Neither `github-script` step interpolates the inputs into its JS body
any more — both the verification job and `post-comment-with-ci-link`
read them from `env:`, removing a script-injection surface. The
remaining `${{ inputs.* }}` uses are in `with:` / `ref:` positions,
where the gate above guarantees the values are a 40-hex SHA and a
decimal integer.
- The `confirm` checkbox is now enforced: for boolean
`workflow_dispatch` inputs `required: true` only means the field is
present, not that it is ticked, so the acknowledgement that the PR was
reviewed at this commit was optional in practice.
- Every job now depends on the verification. Previously only
`ci-pr-only` did, so a verification failure did not stop `ci-main`, the
PR comment, or the Slack notification — a failed job does not cancel
independent jobs.
## Don't push autofixes to a branch named after a fork's branch
Follow-up on a review comment, in the same area: the pushing jobs in
`ci-pr-only.yml` (`autofix`, `lock-generate`,
`generate-config-fixtures`) do `git push origin HEAD:<head-ref>`.
`actions/checkout` defaults to `repository: github.repository`, so
`origin` is always this repository, while `head-ref` is `pr.head.ref` —
an unqualified branch name.
On the `pull_request` path that is fine: `ci-kickoff.yml` only calls
`ci-pr-only` when `head.repo.full_name == github.repository`. On the
`ci-kickoff-manual` path — which exists for external contributions —
`head-ref` is the *fork's* branch name, so the push creates a branch of
that name **here** instead of updating the PR. It uses the
`PR_CREATION_BOT` app token, so the job's `contents: read` does not
restrain it. Two notable cases: a fork branch called `main`/`master` is
rejected by the branch ruleset (so the job just fails), and a fork
branch called `dev-gh-*` would land on a name that is a `push` trigger
for Kickoff, running CI Main with secrets on unreviewed code.
The fix gates the push rather than the jobs:
- `ci-pr-only.yml` takes a new `head-repo` input, defaulting to
`github.event.pull_request.head.repo.full_name` and supplied on the
manual path from the `pulls.get` response the verification job already
has (empty if the fork was deleted, which fails closed).
- The three jobs commit and push only when it equals
`github.repository`; otherwise they print the staged diff and still exit
non-zero. The commit is created only on the pushing path, so the printed
diff is the patch the contributor actually has to apply (a `git diff
--cached` after committing would print nothing).
Guarding the jobs with `if: github.event_name == 'pull_request' && …`
instead would work, but `autofix` is the only place the `//pre-commit:*`
checks run (`shfmt`, `ruff`, `buf`, `buf-breaking`, `do-not-merge`,
`buildifier`, `gazelle`, `rustfmt`), so external PRs would get a green
`ci-pr-only-status` with no lint gate at all. Gating the push keeps
those checks gating exactly the PRs that need them most, and leaves the
contributor an actionable diff in the log.
`head-ref` and `head-repo` are also passed to the scripts through the
environment now instead of being interpolated: git allows single quotes
in branch names, so `HEAD:'${{ inputs.head-ref }}'` was itself a
fork-controlled shell-injection surface.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 2c31ebb commit 673cbf4
2 files changed
Lines changed: 122 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
38 | 52 | | |
39 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
40 | 61 | | |
41 | 62 | | |
42 | 63 | | |
43 | 64 | | |
44 | 65 | | |
45 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
46 | 86 | | |
47 | 87 | | |
| 88 | + | |
48 | 89 | | |
49 | 90 | | |
50 | 91 | | |
| 92 | + | |
51 | 93 | | |
52 | 94 | | |
53 | 95 | | |
| |||
61 | 103 | | |
62 | 104 | | |
63 | 105 | | |
64 | | - | |
| 106 | + | |
65 | 107 | | |
66 | 108 | | |
67 | 109 | | |
68 | 110 | | |
69 | | - | |
70 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
71 | 114 | | |
72 | 115 | | |
73 | 116 | | |
| |||
114 | 157 | | |
115 | 158 | | |
116 | 159 | | |
| 160 | + | |
117 | 161 | | |
118 | 162 | | |
119 | 163 | | |
120 | 164 | | |
121 | 165 | | |
122 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
123 | 170 | | |
124 | 171 | | |
125 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
126 | 177 | | |
127 | | - | |
128 | | - | |
| 178 | + | |
| 179 | + | |
129 | 180 | | |
130 | 181 | | |
131 | 182 | | |
132 | | - | |
| 183 | + | |
133 | 184 | | |
134 | 185 | | |
135 | 186 | | |
136 | 187 | | |
| 188 | + | |
137 | 189 | | |
138 | 190 | | |
139 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
| |||
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
| |||
116 | 124 | | |
117 | 125 | | |
118 | 126 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
124 | 142 | | |
125 | 143 | | |
126 | 144 | | |
| |||
163 | 181 | | |
164 | 182 | | |
165 | 183 | | |
| 184 | + | |
166 | 185 | | |
167 | 186 | | |
168 | 187 | | |
| |||
205 | 224 | | |
206 | 225 | | |
207 | 226 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
213 | 242 | | |
214 | 243 | | |
215 | 244 | | |
| |||
222 | 251 | | |
223 | 252 | | |
224 | 253 | | |
| 254 | + | |
225 | 255 | | |
226 | 256 | | |
227 | 257 | | |
| |||
255 | 285 | | |
256 | 286 | | |
257 | 287 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
263 | 303 | | |
264 | 304 | | |
265 | 305 | | |
| |||
0 commit comments