Skip to content

fix(security): gate automatic PR review triggers to trusted authors - #82

Open
BunsDev wants to merge 1 commit into
mainfrom
codex/fix-vulnerability-in-pr-review-handling
Open

fix(security): gate automatic PR review triggers to trusted authors#82
BunsDev wants to merge 1 commit into
mainfrom
codex/fix-vulnerability-in-pr-review-handling

Conversation

@BunsDev

@BunsDev BunsDev commented Aug 14, 2026

Copy link
Copy Markdown
Member

Motivation

  • Prevent untrusted PR authors (forks/non-collaborators) from enqueuing automatic hosted reviews that run coven-code with repository write authority.
  • Close the authorization gap where lifecycle PR events could create ReviewPullRequest tasks without any collaborator/trust check.

Description

  • Preserve and surface GitHub's author_association on pull-request parsing by adding author_association to the typed PullRequest and PrChangedEvent (webhook and API types).
  • Gate automatic lifecycle review routing in event_to_task so automatic reviews only proceed when author_association is OWNER, MEMBER, or COLLABORATOR, while leaving the maintainer-applied review label path unchanged as an explicit opt-in.
  • Update PR fixtures and parsing assertions to include and validate author_association values.
  • Add a regression test automatic_reviews_reject_untrusted_pr_authors to ensure missing/external associations (e.g., NONE, CONTRIBUTOR) fail closed for automatic reviews.

Testing

  • Ran cargo test -p coven-github-webhook review_lane_tests and the review lane tests passed (10 passed, 0 failed).
  • Ran cargo test -p coven-github-webhook --test parse_fixtures and the fixtures parsing tests passed (14 passed, 0 failed).
  • Ran cargo check --all-targets and cargo clippy --all-targets -- -D warnings which succeeded.
  • An initial cargo test --all run failed due to the environment routing localhost Wiremock traffic through a proxy (HTTP 403), so the full suite was re-run with NO_PROXY=localhost,127.0.0.1,::1 cargo test --all and that run completed successfully (all targeted tests passed); note this failure was environmental and not related to the code change.
  • cargo fmt --all -- --check reported unrelated formatting drift in the existing HEAD (warning, not caused by these changes).

Codex Task

Signed-off-by: Codex <codex@openai.com>
Copilot AI lite review requested due to automatic review settings August 14, 2026 14:40

Copilot AI 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.

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_association to webhook PullRequest parsing and the shared PrChangedEvent type.
  • 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants