Repository navigation
Harden benchmark comment workflow against artifact tampering - #3622
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the benchmark comment workflow by removing trust in PR-number data coming from artifacts produced by untrusted PR code, and instead derives the target PR from workflow_run event metadata in the privileged commenting workflow.
Changes:
- Stop uploading
pr_number.txtfrom the untrusted benchmark workflow artifact. - Resolve the PR number in the privileged
workflow_runjob viaworkflow_run.pull_requests. - Keep the existing benchmark output artifact download + comment posting flow.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| .github/workflows/benchmarks.yml | Removes PR-number artifact emission; keeps benchmark result artifact upload intact. |
| .github/workflows/benchmarks-comment.yml | Resolves PR number from trusted workflow_run payload and uses it for comment targeting. |
Comments suppressed due to low confidence (1)
.github/workflows/benchmarks-comment.yml:48
- This workflow only creates an issue comment;
pull-requests: writepermission appears unnecessary. Consider dropping it to minimize the token’s privileges for this privileged workflow.
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Performance benchmarks:\n\n' + output
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Addressed Copilot suggestion in this update:\n\n- PR resolution now matches against .\n- The workflow now fails if there is no matching PR or if multiple PRs match the same head SHA.\n- Comment target PR is taken from this validated single match.\n\nThis removes the remaining ambiguity from selecting .\n\nNote: the failing check is the known flaky visualization screenshot-diff test and is unrelated to this workflow-only PR. |
|
Addressed Copilot suggestion in this update:
This removes the remaining ambiguity from selecting pull_requests[0]. Note: the failing test_virus_on_network_model[chromium] check is the known flaky visualization screenshot-diff test and is unrelated to this workflow-only PR. |
|
The extra commits (grid optimization, benchmark harness, tests) were needed to fix pre-existing flaky failures on Windows and Ubuntu CI that were blocking this branch. They're not intentional scope expansion, the CI hardening PR couldn't pass cleanly without them |
|
Sorry for the belated review. Could you remove the unrelated changes despite the flaky tests? Also, what is the thread severity? |
b7e1e50 to
8b68baf
Compare
|
Removed the unrelated commits, branch now only contains the 2 workflow-hardening commits. threat severity is medium, Untrusted PR code could craft |
| script: | | ||
| const fs = require('fs'); | ||
| const prNumber = parseInt(fs.readFileSync('pr_number.txt', 'utf8').trim()); | ||
| const prNumber = parseInt('${{ steps.pr.outputs.number }}', 10); |
There was a problem hiding this comment.
what happens if the script returns prior to setting the number?
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| const prs = context.payload.workflow_run.pull_requests || []; |
There was a problem hiding this comment.
This breaks benchmark comments on fork PRs. GitHub leaves workflow_run.pull_requests empty when the PR head is in a fork, which is the case for almost every Mesa PR
* Resolve benchmark comment PR number via API so fork PRs get comments workflow_run.pull_requests is always empty when the PR head lives in a fork, so since #3622 the comment job failed with "No pull request found on workflow_run payload." on nearly every PR. Look the PR up with pulls.list using the head owner, branch, and SHA from the event payload instead. Those values come from GitHub, not from the uploaded artifact, so the tampering protection from #3622 is kept. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Tidy benchmark comment workflow Drop error messages that still referred to the workflow_run payload, collapse the duplicate SHA-match failures into one, use optional chaining for the head repository lookup, and pass the PR number to the comment step through env instead of interpolating it into the script. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
workflow_run.pull_requestsWhy
The benchmark runner executes untrusted PR code by design. The follow-up comment workflow runs with write permissions and previously trusted
pr_number.txtfrom an artifact produced by that untrusted run. This allowed artifact-controlled PR targeting.This patch removes that trust boundary violation by deriving the PR number from GitHub event metadata in the privileged workflow.
Security impact
workflow_runmetadata.Scope
Notes
pull_requestbenchmark run +workflow_runcomment).