fix: post dogfood PR review comments on fork PRs#556
Open
michael-denyer wants to merge 1 commit into
Open
Conversation
The pr-review.yml dogfood workflow failed on every fork-originated PR: GITHUB_TOKEN is read-only in pull_request runs from forks, so the sticky-comment upsert died with HTTP 403 (observed on tirth8205#555). The analysis ran fine — only the comment write failed. Split into the standard two-workflow pattern: - pr-review.yml runs unprivileged (contents: read only) with comment: false, and uploads the rendered report plus PR number as an artifact. - pr-review-comment.yml (workflow_run, pull-requests: write) downloads the artifact and upserts the sticky comment. It never checks out PR code and treats the artifact as untrusted: the PR number must be numeric and the named PR's head must match the triggering run's head_sha before anything is posted. action.yml gains a comment-file output (path to the rendered markdown) so any caller can implement the same pattern; existing consumers are unaffected (comment defaults to true and posts exactly as before). docs/GITHUB_ACTION.md documents the output and replaces the pull_request_target suggestion in the fork-PRs note with this safer pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
No linked issue — fixes a CI failure observed live on #555 and #552 (details below). Happy to file a bug report via the issue form if you'd prefer one for tracking.
What & why
The
pr-review.ymldogfood workflow fails on every fork-originated PR: the graph build and risk analysis complete, but the sticky-comment upsert dies withgh: Resource not accessible by integration (HTTP 403), becauseGITHUB_TOKENinpull_requestruns from public forks is capped at read access — the workflow'spermissions: pull-requests: writecan't raise it. Same-repo PRs (e.g. #548, #545) are unaffected, which is why this never showed up before external fork PRs started arriving: #555 and #552 both fail with the identical 403 at the identical step.docs/GITHUB_ACTION.mdalready documents this exact limitation for external consumers ("Fork PRs" security note); this PR applies the mitigation to the dogfood workflow itself.The fix is the standard unprivileged-analysis / privileged-comment split:
pr-review.ymlnow runs fully unprivileged (contents: readonly —pull-requests: writedropped). It runs the action withcomment: "false"and uploads the rendered report plus the PR number as an artifact.pr-review-comment.yml(new) triggers onworkflow_runwithpull-requests: write, downloads the artifact, and upserts the same sticky comment. It never checks out or executes PR code, and treats the artifact as untrusted input: the PR number must be digits-only, and the named PR's head must match the triggering run'shead_sha, otherwise it refuses to post. All event values reachrun:blocks viaenv:; the comment body is passed as-F body=@file, never shell-interpolated.action.ymlgains acomment-fileoutput (path to the rendered markdown) so any consumer can implement the same pattern. Existing consumers are unaffected —commentstill defaults totrueand posts exactly as before.docs/GITHUB_ACTION.md: documents the new output, updates the "Fork PRs" security note to recommend this pattern (replacing thepull_request_targetsuggestion, which runs untrusted code with a privileged token), and updates the Dogfooding section.Note for review:
workflow_runworkflows execute from the default branch, sopr-review-comment.ymlonly activates after this PR merges. On this PR you'll see the unprivileged half work (report artifact uploaded) but no comment — that's expected, not a failure. The first fork PR after merge will exercise the full path.How it was tested
No Python changed, so no new pytest tests — the comment-rendering logic is untouched and remains covered by
tests/test_action_render.py. Both workflows validated with actionlint (no findings) andaction.ymlchecked to parse cleanly.Checklist
tests/test_action_render.py)uv run pytest tests/ --tb=short -quv run ruff check code_review_graph/uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optionaldocs/, docstrings)