Skip to content

ci: check out trusted base in pr-comment, not the fork head_sha#140

Open
atassis wants to merge 1 commit into
amd:develfrom
atassis:fix/pr-comment-checkout-trusted-base
Open

ci: check out trusted base in pr-comment, not the fork head_sha#140
atassis wants to merge 1 commit into
amd:develfrom
atassis:fix/pr-comment-checkout-trusted-base

Conversation

@atassis

@atassis atassis commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The "Comment on PR with Test Results" workflow (.github/workflows/pr-comment.yml) fails its checkout step on every fork PR. For example, run 30051409584 aborts with:

Refusing to check out fork pull request code from a 'workflow_run' workflow.

The step uses ref: ${{ github.event.workflow_run.head_sha }}. For a fork PR that head_sha is the fork's commit, and recent actions/checkout refuses to check out fork code inside a workflow_run job. So the comment job goes red even when the Krackan/Phoenix suites all passed, which trains people to ignore failures on this check.

There are two problems, and both are fixed the same way:

  1. False failure. The job's actual work (aggregate the artifacts, post one comment) is unaffected by which source it checks out. The checkout just aborts before any of it runs.
  2. Pwn-request exposure. This job runs from workflow_run with a write-scoped GITHUB_TOKEN and secrets. Its only use of the working tree is running ci/scripts/pretty_aggregate.py; artifacts and PR metadata come from the API. Checking out head_sha means running the fork author's copy of that script under a token that can write to the repo, so a malicious fork could edit the script to exfiltrate the token or push to the base.

Fix: drop the ref so checkout takes the default branch, i.e. the trusted base copy of the aggregation script. Legitimate PRs get the same comment; untrusted code no longer runs under the write token. I chose this over allow-unsafe-pr-checkout: true, which would silence the error while leaving the hole open.

The "Comment on PR with Test Results" workflow runs from workflow_run, so
it executes in the base repo context with a write-scoped GITHUB_TOKEN and
secrets. Its checkout step used ref: github.event.workflow_run.head_sha,
which for a fork PR points at the fork's commit.

actions/checkout now refuses that: it fails the step with "Refusing to
check out fork pull request code from a 'workflow_run' workflow", so the
comment job goes red on every fork PR even when the test suites passed.

Beyond the false failure, the old behavior is a pwn-request vector. The
job's only use of the working tree is running ci/scripts/pretty_aggregate.py;
artifacts and PR metadata come from the API. Checking out head_sha meant
running the fork author's copy of that script under a token that can write
to the repo. A malicious fork could edit the script to exfiltrate the token
or push to the base repo.

Drop the ref so checkout takes the default branch, i.e. the trusted base
copy of the aggregation script. Legitimate PRs get the same comment; the
untrusted code no longer runs under the write token. This is the correct
fix rather than allow-unsafe-pr-checkout: true, which would keep the hole
open.
@atassis
atassis force-pushed the fix/pr-comment-checkout-trusted-base branch from ba4ecd1 to e2af73a Compare July 24, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant