Skip to content

Fix Check ToolHandler.cpp / Check AUTHORS File failing on every fork PR - #9786

Closed
timosachsenberg wants to merge 4 commits into
developfrom
claude/sweet-fermat-dbvneb
Closed

timosachsenberg wants to merge 4 commits into
developfrom
claude/sweet-fermat-dbvneb

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

What changed

Split each workflow into two:

  1. check-tool-handler.yml / check-authors-file.yml — now triggered on plain pull_request (not _target), so checking out the fork's head is safe and unrestricted. Runs the existing ci-tools check script and, instead of posting the PR comment directly (this job only gets a read-only token when triggered from a fork), uploads the PR number + comment body as an artifact.
  2. check-tool-handler-comment.yml / check-authors-file-comment.yml (new) — triggered on workflow_run once the corresponding check completes. This job runs in the base repo's context (never checks out fork code) and can safely hold a pull-requests: write token. It downloads the artifact and posts the comment.

Note: github.event.workflow_run.pull_requests is empty for fork-originated PRs, so the PR number is carried through the artifact rather than read off the workflow_run event.

This mirrors GitHub's documented secure replacement pattern for pull_request_target combined with fork-code checkout.

Test plan

  • YAML syntax validated for all 4 files (python3 -c "import yaml; yaml.safe_load(...)")
  • Since this only triggers under real fork-PR conditions, please verify end-to-end against an actual external-fork PR after merge (e.g. re-run on a currently-failing fork PR, or open a throwaway fork PR) — I could not simulate a workflow_run-triggered cross-run artifact download locally.
  • Confirm the comment still posts correctly for the "found an issue" case (exit code 100 path) and stays silent for the clean case.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ELBxffE1E3xZ9ar5Fvs7xZ


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Added automated pull request comments for AUTHORS and ToolHandler validations after each check finishes.
  • Bug Fixes
    • Improved comment reliability by preparing comment content during validation and only publishing when valid output is available.
    • Strengthened safety by running workflows with read-only permissions and avoiding direct commenting from less-trusted contexts.
  • Chores
    • Updated workflow triggers and refined execution flow to post comments in a more controlled, consistent manner.

actions/checkout@v6 now refuses to check out a fork's PR head from a
pull_request_target job (the "pwn request" guard), which made both
checks fail unconditionally for every externally-forked PR since
~2026-07-16 instead of running their intended AUTHORS/ToolHandler
diff check.

Split each into an unprivileged pull_request-triggered check job
(safe to checkout fork code, no secrets) that uploads its result as
an artifact, plus a privileged workflow_run-triggered companion job
that never touches fork code and posts the PR comment. This mirrors
GitHub's recommended replacement for pull_request_target +
fork-checkout.

Fixes #9785

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ELBxffE1E3xZ9ar5Fvs7xZ
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Claude

Please consider applying the following patch:

--- AUTHORS	2026-07-23 09:12:56.072553585 +0000
+++ AUTHORS.new	2026-07-23 09:13:02.073464308 +0000
@@ -27,6 +27,7 @@
  - Chris Bielow
  - Christian Ehrlich
  - Christie Mathews
+ - Claude
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2935196e-5b33-4d9f-86ba-4c01097ba004

📥 Commits

Reviewing files that changed from the base of the PR and between e0a6a0c and dd7b636.

📒 Files selected for processing (4)
  • .github/workflows/check-authors-file-comment.yml
  • .github/workflows/check-authors-file.yml
  • .github/workflows/check-tool-handler-comment.yml
  • .github/workflows/check-tool-handler.yml
🚧 Files skipped from review as they are similar to previous changes (4)
  • .github/workflows/check-tool-handler.yml
  • .github/workflows/check-authors-file.yml
  • .github/workflows/check-tool-handler-comment.yml
  • .github/workflows/check-authors-file-comment.yml

📝 Walkthrough

Walkthrough

The AUTHORS and ToolHandler checks now run on pull_request with read-only permissions, upload optional comment bodies as artifacts, and delegate privileged PR comment creation to separate workflow_run workflows that resolve the PR from the checked commit.

Changes

Fork-safe check workflows

Layer / File(s) Summary
AUTHORS check artifact production
.github/workflows/check-authors-file.yml
The check now uses pull_request with contents: read, writes conditional output to pr-comment/body, and uploads the directory as an artifact.
AUTHORS comment posting
.github/workflows/check-authors-file-comment.yml
After a successful check, the companion workflow downloads the artifact, resolves the PR from workflow_run.head_sha, and posts only a non-empty comment body.
ToolHandler check artifact production
.github/workflows/check-tool-handler.yml
The check now uses pull_request with contents: read, captures exit-code-specific comment output, and uploads it as an artifact.
ToolHandler comment posting
.github/workflows/check-tool-handler-comment.yml
After a successful check, the companion workflow downloads the artifact, resolves the PR from the head SHA, and conditionally posts its non-empty body.

Sequence Diagram(s)

sequenceDiagram
  participant PullRequest
  participant CheckWorkflows
  participant CommentArtifacts
  participant CommentWorkflows
  participant GitHubPullRequest
  PullRequest->>CheckWorkflows: open pull request into develop
  CheckWorkflows->>CommentArtifacts: upload optional comment body
  CheckWorkflows-->>CommentWorkflows: successful workflow_run
  CommentWorkflows->>CommentArtifacts: download matching artifact
  CommentWorkflows->>GitHubPullRequest: resolve PR from head SHA and post comment
Loading

Poem

I’m a rabbit with workflows neat,
Artifacts hop on nimble feet.
Read-only paws inspect the code,
Privileged friends bear the comment load.
AUTHORS and ToolHandler run—
Safe checks for everyone!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: splitting the fork-PR workflows into safer pull_request and workflow_run jobs.
Linked Issues check ✅ Passed The workflow split and artifact-based comment posting address #9785 by restoring fork PR checks without privileged checkout.
Out of Scope Changes check ✅ Passed The changes stay focused on the two failing workflow pairs and their comment-posting path, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/sweet-fermat-dbvneb

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
.github/workflows/check-authors-file-comment.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

.github/workflows/check-authors-file.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

.github/workflows/check-tool-handler-comment.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/check-authors-file-comment.yml:
- Around line 19-32: The “Post comment on the PR” step must not trust
pr-comment/pr-number from the untrusted artifact. Derive the target PR from
trusted workflow_run metadata or API data, or validate the artifact number is
numeric and corresponds to the workflow_run head SHA before invoking gh pr
comment; only post after that validation succeeds.

In @.github/workflows/check-tool-handler-comment.yml:
- Around line 28-32: Update the workflow step’s condition to use `test -s
pr-comment/body` so the `gh pr comment` command runs only when the comment body
file exists and contains text; preserve the existing repository, token, and
body-file arguments.
- Around line 27-32: Update the “Post comment on the PR” step to stop using the
artifact-controlled pr-comment/pr-number as the target. Derive the PR number
from trusted workflow_run metadata, preferably
github.event.workflow_run.pull_requests[0].number, or resolve the run-to-PR
association through the GitHub API before invoking gh pr comment; preserve the
existing body-file posting behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 04512de1-8a4f-45a4-9137-4a696e12e0a6

📥 Commits

Reviewing files that changed from the base of the PR and between cb84612 and d97e23f.

📒 Files selected for processing (4)
  • .github/workflows/check-authors-file-comment.yml
  • .github/workflows/check-authors-file.yml
  • .github/workflows/check-tool-handler-comment.yml
  • .github/workflows/check-tool-handler.yml

claude added 2 commits July 23, 2026 09:20
The privileged workflow_run "comment" jobs were trusting a PR number
written into an artifact by the unprivileged pull_request "check" job.
Unlike pull_request_target, pull_request runs execute the workflow
file as it exists on the fork's own branch, so a malicious fork could
rewrite that step to fabricate an arbitrary PR number and get our
privileged bot to post a comment on an unrelated PR.

Resolve the target PR instead from workflow_run.head_sha (set by
GitHub itself, not influenced by the fork's workflow content) via the
"list pull requests associated with a commit" API. The artifact is
now only used for the comment body, never for PR targeting.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ELBxffE1E3xZ9ar5Fvs7xZ
hashFiles('pr-comment/body') only checks that the file exists, not
that it has content — the check step always creates the file via
shell redirection even when there's nothing to report, so an empty
artifact would still pass and produce a comment with an empty body.
Use a real shell -s (exists-and-non-empty) test instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ELBxffE1E3xZ9ar5Fvs7xZ

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/check-tool-handler-comment.yml (1)

23-29: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle missing comment artifacts before downloading.

The producer skips creating tool-handler-pr-comment when no finding is written (if-no-files-found: ignore), and actions/download-artifact@v4 fails for a missing named artifact. A clean PR therefore exits the privileged check before the empty-body guard runs. Upload an empty body for clean checks, or make the download conditional on artifact existence and keep the -s check.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/check-tool-handler-comment.yml around lines 23 - 29,
Update the “Download PR comment artifact” step so missing
tool-handler-pr-comment artifacts do not fail the workflow before the empty-body
guard; either always upload an empty body for clean checks or conditionally
download only when the artifact exists, while preserving the existing `-s`
check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/check-authors-file-comment.yml:
- Around line 31-37: Update the Resolve the PR for this run's head commit step
to query all associated PRs and select a target only when exactly one open PR
points to workflow_run.head_sha; remove the unconditional `.[0].number`
selection. Leave `pr_number` empty when zero or multiple matching open PRs exist
so subsequent privileged comment posting is skipped.

In @.github/workflows/check-tool-handler-comment.yml:
- Around line 31-37: Update the “Resolve the PR for this run's head commit” step
to filter the pull-request API results using the workflow run’s head SHA, head
branch, and repository context, then require exactly one matching PR before
writing pr_number to GITHUB_OUTPUT. Fail the step when zero or multiple PRs
match instead of selecting `.[0]`.

---

Outside diff comments:
In @.github/workflows/check-tool-handler-comment.yml:
- Around line 23-29: Update the “Download PR comment artifact” step so missing
tool-handler-pr-comment artifacts do not fail the workflow before the empty-body
guard; either always upload an empty body for clean checks or conditionally
download only when the artifact exists, while preserving the existing `-s`
check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d462fca-55a3-47f0-93ef-7456f2495828

📥 Commits

Reviewing files that changed from the base of the PR and between d97e23f and e0a6a0c.

📒 Files selected for processing (4)
  • .github/workflows/check-authors-file-comment.yml
  • .github/workflows/check-authors-file.yml
  • .github/workflows/check-tool-handler-comment.yml
  • .github/workflows/check-tool-handler.yml
💤 Files with no reviewable changes (2)
  • .github/workflows/check-tool-handler.yml
  • .github/workflows/check-authors-file.yml

Two more issues in the fork-safe check workflows:

- actions/download-artifact@v4 hard-fails when the named artifact
  doesn't exist, and upload-artifact (with if-no-files-found: ignore)
  skipped creating the artifact whenever pr-comment/ was empty, which
  was the common "nothing to report" case. Always `touch
  pr-comment/body` so the artifact (and its non-empty check) exists
  regardless of outcome.

- The commit-to-PRs API doesn't document a response order and can
  return more than one PR for a commit, so blindly taking `.[0].number`
  could target the wrong PR. Require exactly one open PR whose head
  SHA matches the run's head_sha, and skip commenting otherwise.

Also moved the ${{ }} expressions used inside `run:` shell blocks into
`env:` vars per zizmor's template-injection lint, even though the
values involved (a repo slug, a commit SHA, a numeric PR id) aren't
actually attacker-controllable.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ELBxffE1E3xZ9ar5Fvs7xZ

Copy link
Copy Markdown
Contributor Author

Re the outside-diff finding on check-tool-handler-comment.yml (23-29): also fixed in dd7b636. The check step now unconditionally touches pr-comment/body, so the directory is never empty and the artifact always gets uploaded (previously, a clean PR with nothing to report left pr-comment/ empty, upload-artifact's if-no-files-found: ignore skipped creating the artifact, and the companion job's download-artifact would then hard-fail since the named artifact didn't exist). The -s pr-comment/body guard in the comment step still correctly skips posting when the file is empty. Same fix applies to the AUTHORS-file pair.


Generated by Claude Code

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.

Check ToolHandler.cpp / Check AUTHORS File fail for every external (fork) PR since ~2026-07-16

2 participants