Skip to content

Harden benchmark comment workflow against artifact tampering - #3622

Merged
quaquel merged 5 commits into
mesa:mainfrom
yassinekolsi:harden-benchmark-comment-workflow
Oct 24, 2026
Merged

quaquel merged 5 commits into
mesa:mainfrom
yassinekolsi:harden-benchmark-comment-workflow

Conversation

@yassinekolsi

Copy link
Copy Markdown
Contributor

Summary

  • stop passing PR number via artifact from benchmark workflow
  • resolve target PR number in the privileged comment workflow using workflow_run.pull_requests
  • keep benchmark output artifact flow unchanged

Why

The benchmark runner executes untrusted PR code by design. The follow-up comment workflow runs with write permissions and previously trusted pr_number.txt from 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

  • Prevents untrusted benchmark artifacts from selecting an arbitrary PR/issue target for comment posting.
  • Keeps write permissions scoped to the comment step while using trusted workflow_run metadata.

Scope

  • Atomic change in CI workflows only
  • Files changed: 2

Notes

  • No benchmark logic or output generation changed.
  • This is compatible with the existing two-workflow architecture (pull_request benchmark run + workflow_run comment).

Copilot AI review requested due to automatic review settings March 23, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.txt from the untrusted benchmark workflow artifact.
  • Resolve the PR number in the privileged workflow_run job via workflow_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: write permission 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.

@yassinekolsi

Copy link
Copy Markdown
Contributor Author

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.

@yassinekolsi

Copy link
Copy Markdown
Contributor Author

Addressed Copilot suggestion in this update:

  • PR resolution now matches workflow_run.head_sha against workflow_run.pull_requests[*].head.sha.
  • The workflow now fails if there is no matching PR or if multiple PRs match the same head SHA.
  • Comment target PR is taken from this validated single match.

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.

@yassinekolsi

Copy link
Copy Markdown
Contributor Author

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

@quaquel quaquel added the ci Release notes label label Apr 4, 2026
@quaquel

quaquel commented Apr 4, 2026

Copy link
Copy Markdown
Member

Sorry for the belated review. Could you remove the unrelated changes despite the flaky tests?

Also, what is the thread severity?

@yassinekolsi
yassinekolsi force-pushed the harden-benchmark-comment-workflow branch from b7e1e50 to 8b68baf Compare April 7, 2026 01:34
@yassinekolsi

Copy link
Copy Markdown
Contributor Author

Removed the unrelated commits, branch now only contains the 2 workflow-hardening commits.

threat severity is medium, Untrusted PR code could craft pr_number.txt to post benchmark comments to arbitrary PRs/issues. Impact limited to comment injection (no secrets/code execution), but it's a trust boundary violation between the unprivileged benchmark runner and the privileged comment workflow

script: |
const fs = require('fs');
const prNumber = parseInt(fs.readFileSync('pr_number.txt', 'utf8').trim());
const prNumber = parseInt('${{ steps.pr.outputs.number }}', 10);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the script returns prior to setting the number?

@quaquel
quaquel merged commit 88457d2 into mesa:main Oct 24, 2026
13 of 15 checks passed
uses: actions/github-script@v8
with:
script: |
const prs = context.payload.workflow_run.pull_requests || [];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

quaquel pushed a commit that referenced this pull request Nov 4, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants