Skip to content

fix(github): reply and resolve refuse threads from other pull requests - #24557

Closed
only21mil wants to merge 3 commits into
pingdotgg:mainfrom
only21mil:fix/c089-05-thread-reply-and-resolve-skip-the-pull-r
Closed

only21mil wants to merge 3 commits into
pingdotgg:mainfrom
only21mil:fix/c089-05-thread-reply-and-resolve-skip-the-pull-r

Conversation

@only21mil

@only21mil only21mil commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Replying to a GitHub review thread, and resolving or unresolving one, sent the client's thread id straight to GitHub. The request names a repository and pull request number, but the server never checked that the thread belongs to that pull request. GitHub writes wherever the thread id points, so the write could land on a thread in any pull request the credential can reach.

The neighboring writes already guard this. updateComment and setReaction read PullRequestSubject first and fail with GitHubSubjectScopeError on a mismatch, and getReviewThreadComments refuses a thread from another pull request. Reply and resolve were the two thread writes left out.

The web Code tab and the mobile discussion screen always send a thread from the pull request on screen, so normal use never hit this. The gap is on the server's side of the contract.

Change

  • PullRequestSubject now also reads a PullRequestReviewThread's pull request, and isSubjectOfPullRequest compares it like the other subject kinds.
  • replyToReviewThread and setReviewThreadResolution take the pull request number and run that check before the mutation. A thread from another pull request fails with GitHubSubjectScopeError, and no mutation is sent.
  • GitHubPullRequestProvider passes the number it already receives. The provider contract carried it all along; the GitHub adapter dropped it.

I reused the existing subject check instead of the ReviewThreadComments read, because that query also pages up to 100 comments. Each reply or resolve now costs one extra GraphQL read, the same small read that comment edits and reactions already make.

Other forges are unaffected. GitLab, Bitbucket and GitCafe put the merge request or pull request number in the request path, and Azure DevOps and Forgejo do not support thread writes.

Scope and approval

A small, focused fix of an obvious bug, with no issue. The two writes skipped a scope check that every sibling write on the same service performs. Valid requests behave as before, and nothing on the wire or in the clients changes.

Verification

  • vp test run --config ../../vite.config.ts src/server/GitHubPullRequestApi.test.ts -t "review thread" from packages/source-control-github. A table-driven pair of tests covers reply, resolve and unresolve: a thread from the named pull request is checked with the right variables and then written; a thread from another pull request fails with GitHubSubjectScopeError and sends no mutation. On the base all 6 new cases fail, because no check runs and the write goes through. With the fix all 9 thread tests pass.
  • vp test run --config ../../vite.config.ts --dir . in packages/source-control-github: 20 files, 386 tests pass (after merging main).
  • vp run check:changed main: format, lint, knip, graphql generation, typecheck of 11 packages and 5 test files pass (after merging main).
  • pullRequestReads.graphql.ts was regenerated with vp run generate.

The new tests fail on the base, before the fix:

Six new review thread tests fail on the base commit

The same tests pass with the fix:

All nine review thread tests pass with the fix

Runtime transcript. The real GitHub provider and API run over HTTPS against a stub Enterprise host on loopback (github.localhost), with synthetic data. Pull request acme/web#7 owns thread PRRT_own; PRRT_other belongs to another pull request. Each call names #7.

On main, both threads are written:

[t3 server] --- review thread PRRT_other, request names acme/web#7 ---
[stub] POST /api/graphql  mutation AddReviewThreadReply  variables={"threadId":"PRRT_other","body":"Done."}
[t3 server] replyToThread PRRT_other: ok
[stub] POST /api/graphql  mutation ResolveReviewThread  variables={"threadId":"PRRT_other"}
[t3 server] setThreadResolution PRRT_other resolved=true: ok

With this change, PRRT_own is checked and then written, and PRRT_other is refused with no mutation sent:

[t3 server] --- review thread PRRT_own, request names acme/web#7 ---
[stub] POST /api/graphql  query PullRequestSubject  variables={"owner":"acme","name":"web","number":7,"subjectId":"PRRT_own"}
[stub] POST /api/graphql  mutation AddReviewThreadReply  variables={"threadId":"PRRT_own","body":"Done."}
[t3 server] replyToThread PRRT_own: ok
[stub] POST /api/graphql  query PullRequestSubject  variables={"owner":"acme","name":"web","number":7,"subjectId":"PRRT_own"}
[stub] POST /api/graphql  mutation ResolveReviewThread  variables={"threadId":"PRRT_own"}
[t3 server] setThreadResolution PRRT_own resolved=true: ok
[t3 server] --- review thread PRRT_other, request names acme/web#7 ---
[stub] POST /api/graphql  query PullRequestSubject  variables={"owner":"acme","name":"web","number":7,"subjectId":"PRRT_other"}
[t3 server] replyToThread PRRT_other: failed with PullRequestProviderError (The named subject did not belong to the named pull request.)
[stub] POST /api/graphql  query PullRequestSubject  variables={"owner":"acme","name":"web","number":7,"subjectId":"PRRT_other"}
[t3 server] setThreadResolution PRRT_other resolved=true: failed with PullRequestProviderError (The named subject did not belong to the named pull request.)

Nothing visible changes. Both clients already send a thread from the pull request on screen, so no screenshot can show a difference.

Not checked:

  • A live reply or resolve against github.com or a real GitHub Enterprise Server. The tests answer GraphQL from fixtures, and the transcript uses a stub host.
  • Whether every Enterprise Server version supports pullRequest on PullRequestReviewThread inside this query. The thread comments read already selects that field.

Prior PRs

No earlier PR makes this fix. The subject check it reuses came from #6039 by Bilal Bakr.

Generated with Claude Opus 5.5 in T3 Code Nightly

…hey name

replyToReviewThread and setReviewThreadResolution sent the client's thread
id straight to GitHub, so a thread from any other pull request the
credential can reach took the write. Both now run the same
PullRequestSubject check that updateComment and setReaction use, which
learns to read a review thread's pull request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Oct 24, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — This is a focused fix that validates review-thread ownership before replying or changing resolution, with tests covering valid and cross-pull-request cases. Because it changes a server-side authorization/scope boundary for GitHub mutations, the change warrants human review.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Replying to, resolving, or unresolving a review thread now requires its pull request number. The API checks the thread’s parent pull request before mutation and rejects mismatches with GitHubSubjectScopeError.

Changes: Review thread scope validation

Layer / File(s) Summary
Review thread ownership lookup
packages/source-control-github/src/server/pullRequestReads.graphql, packages/source-control-github/src/server/pullRequestReads.graphql.ts, packages/source-control-github/src/server/gitHubPullRequestJson.ts
The subject query now reads the parent pull request ID for review threads. Subject matching uses that ID for review thread nodes.
Validate thread writes
packages/source-control-github/src/server/GitHubPullRequestApi.ts, packages/source-control-github/src/server/GitHubPullRequestProvider.ts, packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
The API accepts the pull request number and checks ownership before mutation. Tests cover matching and mismatched pull requests for reply, resolve, and unresolve operations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant GitHubPullRequestProvider
  participant GitHubPullRequestApi
  participant GitHubGraphQL
  GitHubPullRequestProvider->>GitHubPullRequestApi: Submit thread write with pull request number
  GitHubPullRequestApi->>GitHubGraphQL: Read thread parent pull request ID
  GitHubGraphQL-->>GitHubPullRequestApi: Return parent pull request ID
  GitHubPullRequestApi->>GitHubPullRequestApi: Check thread ownership
  GitHubPullRequestApi->>GitHubGraphQL: Mutate thread when ownership matches
Loading
Merge Risk: Minimal · up to 99221

The change adds a pull-request ownership check before review-thread replies and resolution changes. No demonstrated issue currently prevents merging after normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly states the main change: GitHub review-thread replies and resolution changes now reject threads from other pull requests.
Description check Passed The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the issue and fix, justifies the focused scope, reports test results, and identifies c…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the issue and fix, justifies the focused scope, reports test results, and identifies checks that were not performed.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b7624bd and 99221cb.

Files selected for processing: 6

  • packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
  • packages/source-control-github/src/server/GitHubPullRequestApi.ts
  • packages/source-control-github/src/server/GitHubPullRequestProvider.ts
  • packages/source-control-github/src/server/gitHubPullRequestJson.ts
  • packages/source-control-github/src/server/pullRequestReads.graphql
  • packages/source-control-github/src/server/pullRequestReads.graphql.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

only21mil and others added 2 commits November 10, 2026 10:53
…reply-and-resolve-skip-the-pull-r

# Conflicts:
#	packages/source-control-github/src/server/GitHubPullRequestApi.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@only21mil

Copy link
Copy Markdown
Contributor Author

Note

🤖 Opus 5.5 replying on behalf of Victor.

Merged main into this branch to clear the conflict in GitHubPullRequestApi.ts (merge commit cc89fea). Main had wrapped replyToReviewThread and setReviewThreadResolution in Effect.fn spans. The thread check now runs inside those spans, and the span names are unchanged. Nothing was dropped: main still sends both writes without checking the thread's pull request. A follow-up commit (99221cb) wraps one .graphql comment line at 100 columns.

The new review thread tests still fail on main and pass here. The description now includes a short runtime transcript. It runs the real provider and API over HTTPS against a stub Enterprise host on loopback, with synthetic data.

@only21mil

Copy link
Copy Markdown
Contributor Author

Note

🤖 Opus 5.5 replying on behalf of Victor.

Closing this to bring my open PRs down under the new limit. The branch stays on my fork if it is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant