fix(security): gate automatic PR review triggers to trusted authors - #82
Open
BunsDev wants to merge 1 commit into
Open
fix(security): gate automatic PR review triggers to trusted authors#82BunsDev wants to merge 1 commit into
BunsDev wants to merge 1 commit into
Conversation
Signed-off-by: Codex <codex@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the GitHub App adapter’s automatic PR review routing by propagating GitHub’s author_association into the typed PR lifecycle event and using it to block automatic hosted reviews for untrusted PR authors, while keeping maintainer-applied review labels as an explicit opt-in path.
Changes:
- Added
author_associationto webhookPullRequestparsing and the sharedPrChangedEventtype. - Gated automatic lifecycle review task creation to trusted associations (
OWNER,MEMBER,COLLABORATOR) and fail-closed otherwise. - Updated PR webhook fixtures and tests, and added a regression test for rejecting untrusted/missing associations.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/webhook/src/routes.rs | Enforces trusted-author gating for automatic lifecycle review routing and adds a regression test. |
| crates/webhook/src/events.rs | Preserves author_association from webhook payloads into PrChangedEvent. |
| crates/github/src/lib.rs | Extends the shared PrChangedEvent schema with author_association. |
| crates/webhook/tests/parse_fixtures.rs | Adds parsing assertion for author_association on the opened PR fixture. |
| crates/webhook/tests/fixtures/pull_request_opened.json | Adds author_association to opened PR fixture payload. |
| crates/webhook/tests/fixtures/pull_request_synchronize.json | Adds author_association to synchronize PR fixture payload. |
| crates/webhook/tests/fixtures/pull_request_ready_for_review.json | Adds author_association to ready_for_review PR fixture payload. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1845
to
+1857
| #[tokio::test] | ||
| async fn automatic_reviews_reject_untrusted_pr_authors() { | ||
| let state = app_state_with_review(review_on()); | ||
| for association in [None, Some("NONE"), Some("CONTRIBUTOR")] { | ||
| let mut event = pr_event("opened"); | ||
| event.author_association = association.map(str::to_string); | ||
| assert!( | ||
| event_to_task(&state, GitHubEvent::PullRequestChanged(event)) | ||
| .await | ||
| .is_none() | ||
| ); | ||
| } | ||
| } |
Comment on lines
141
to
145
| assert_eq!(e.head_sha, "abc123def4567890abc123def4567890abc123de"); | ||
| assert_eq!(e.base_ref, "main"); | ||
| assert_eq!(e.author_login, "octocat"); | ||
| assert_eq!(e.author_association.as_deref(), Some("MEMBER")); | ||
| assert!(!e.draft); |
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.
Motivation
Description
author_associationon pull-request parsing by addingauthor_associationto the typedPullRequestandPrChangedEvent(webhook and API types).event_to_taskso automatic reviews only proceed whenauthor_associationisOWNER,MEMBER, orCOLLABORATOR, while leaving the maintainer-applied review label path unchanged as an explicit opt-in.author_associationvalues.automatic_reviews_reject_untrusted_pr_authorsto ensure missing/external associations (e.g.,NONE,CONTRIBUTOR) fail closed for automatic reviews.Testing
cargo test -p coven-github-webhook review_lane_testsand the review lane tests passed (10 passed, 0 failed).cargo test -p coven-github-webhook --test parse_fixturesand the fixtures parsing tests passed (14 passed, 0 failed).cargo check --all-targetsandcargo clippy --all-targets -- -D warningswhich succeeded.cargo test --allrun failed due to the environment routing localhost Wiremock traffic through a proxy (HTTP 403), so the full suite was re-run withNO_PROXY=localhost,127.0.0.1,::1 cargo test --alland that run completed successfully (all targeted tests passed); note this failure was environmental and not related to the code change.cargo fmt --all -- --checkreported unrelated formatting drift in the existing HEAD (warning, not caused by these changes).Codex Task