Route GitHub webhook events to the correct environment based on PR origin#4285
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0599110aed
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR updates the realm-server webhook receiver so GitHub webhook commands are routed to the correct environment (staging vs production vs local) by resolving the PR’s “origin realm” and comparing origins, rather than broadcasting events to all environments.
Changes:
- Made webhook filter handlers async and added dynamic realm resolution from PR body (SubmissionCard URL) with DB fallback by PR number.
- Updated the webhook receiver to pass
dbAdapterinto filter handlers andawaitasync matching/input/realm resolution. - Added unit tests for helper extraction functions (
extractRealmFromPrBody,extractPrNumberFromPayload).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/realm-server/handlers/webhook-filter-handlers.ts | Adds realm/PR resolution helpers, DB lookup, origin-based filtering, and async handler interface. |
| packages/realm-server/handlers/handle-webhook-receiver.ts | Awaits async filter handler methods and passes dbAdapter through. |
| packages/realm-server/tests/server-endpoints/webhook-receiver-test.ts | Adds unit tests for PR-body realm extraction and PR-number extraction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
91521de to
192b1ba
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
192b1ba to
d30292c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d30292ca7f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (filter.realm) { | ||
| let resolvedOrigin = await resolveOriginFromPayload(payload, dbAdapter); |
There was a problem hiding this comment.
Limit origin checks to PR-linked events
matches() now calls resolveOriginFromPayload() for every github-event command that has filter.realm, regardless of event type. We still register commit_comment and discussion_comment commands with a realm in packages/matrix/scripts/register-github-webhook-for-submission-realm.ts (lines 235-247), but those payloads do not carry PR body/PR number fields, so origin resolution returns null and this branch rejects them every time. This regresses existing behavior by making those configured webhook commands impossible to execute.
Useful? React with 👍 / 👎.
d30292c to
9bad05d
Compare
backspace
left a comment
There was a problem hiding this comment.
I haven’t been looking at this work, is there validation that webhook requests are only processed from authorised sources?
@backspace Yes, each |


Summary
check_run,check_suite)How it works
pull_request,pull_request_reviewevents — extract the Submission Card URL from the PR body, compare its origin againstfilter.realm. Reject if origins don't match.check_run,check_suiteevents — no PR body available, so queryboxel_indexfor a PrCard matching the PR number and compare its realm origin.Fail-closed — if origin cannot be resolved from a PR-related event, the match is rejected to prevent cross-environment broadcast.
Test plan
check_runevent routing via PrCard DB lookup