Repository navigation
fix(vcs): match event repositories to their provider's installations - #14800
Conversation
GitHub, Origin and Entire deliveries looked up repositories by provider repository id alone, while the Gitea, GitLab and Bitbucket handlers also check that the repository's installation belongs to their provider. Apply the same check so a delivery only acts on repositories its provider owns.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
This PR hardens the VCS webhook surface against provider-ID collisions by filtering the repositories matched on
Reviewed commit: 9f7536a |
🟢 Tier S · Ready to mergeGitHub, Origin, and Entire webhook handlers now resolve repository IDs only through installations belonging to their respective provider, paging and filtering installation matches per page. The VCS Gitea E2E test sends a signed GitHub push naming a Gitea repository and verifies that the delivery does not create a deployment. Latest changes: The E2E regression now snapshots the function's deployment IDs before the GitHub delivery and asserts they are unchanged afterward, rather than checking only for a deployment with the test commit hash.
📂 Walkthrough · 4
Reviewed the commits since |
There was a problem hiding this comment.
Adds a filterRepositories guard to the GitHub, Origin, and Entire VCS webhook handlers so cross-provider deliveries cannot trigger deployments.",
"detailed_summary": "This PR hardens the VCS webhook surface against provider-ID collisions by filtering the repositories matched on providerRepositoryId down to those connected through an installation of the delivering provider. The guard is applied to the push and pull-request paths in each of the three webhook controllers, and an e2e test verifies a GitHub delivery naming a Gitea repository no longer deploys.
| Files | Change |
|---|---|
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php, .../Origin/Events/Create.php, .../Entire/Events/Create.php |
Adds an identical filterRepositories() helper that resolves each candidate repository's installation and keeps only same-provider matches, applied to the push and pull-request repository queries. |
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php |
Adds testGitHubPushIgnoresGiteaRepository, asserting a GitHub push for a repository linked to a Gitea installation creates no deployment. |
| ", | |
| "risk_score |
Key findings
- 🟡 Avoid one installation lookup per repository in
filterRepositories— Create.php:207
| private function filterRepositories(array $repositories, Database $dbForPlatform, Authorization $authorization): array | ||
| { | ||
| return \array_values(\array_filter($repositories, function (Document $repository) use ($dbForPlatform, $authorization) { | ||
| $installation = $authorization->skip(fn () => $dbForPlatform->getDocument('installations', $repository->getAttribute('installationId', ''))); |
There was a problem hiding this comment.
🟡 performance · medium
Avoid one installation lookup per repository in filterRepositories
filterRepositories fetches the installation with getDocument inside the array_filter callback, so each candidate repository triggers a separate platform-database read (src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php line 207). The helper runs on every push and pull request webhook delivery, and the identical per-item lookup is repeated in the Entire and Origin controllers. On a delivery matching a page of repositories this multiplies database reads by the result size for work one batched query would do.
📋 Prompt for AI Agents
In src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php around lines 204-211, the filterRepositories helper calls $dbForPlatform->getDocument('installations', ...) once per repository inside array_filter. Rewrite it to collect the distinct installationId values from the repositories, fetch those installations in one authorization-skipped find query, and keep only repositories whose installation exists and has provider 'github'. Apply the same change to the Entire and Origin Events/Create.php files, which carry identical helpers.
There was a problem hiding this comment.
Fixed in the latest commit: filterRepositories now collects the distinct installation ids and fetches the provider's installations in a single find, in all three handlers.
Filtering matched repositories by provider read each installation separately; look them up together instead.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Filtering after a single capped lookup could drop this provider's repositories behind other providers' rows with the same id. Page through the matches and filter each page instead.
The deployments list does not accept a commit hash filter.
…ation-provider fix(vcs): match event repositories to their provider's installations (cherry picked from commit 0772262)
What does this PR do?
The GitHub, Origin and Entire webhook handlers looked up
repositoriesbyproviderRepositoryIdalone. The Gitea, GitLab and Bitbucket handlers also check that each repository's installation belongs to their provider (resolveGiteaInstallationand its siblings). This PR applies the same check to the other three.Each of the three event actions gets a private
findRepositories(). It pages through the repositories with the delivery'sproviderRepositoryId, loads each page's installations in one query filtered to that action's provider (github,origin,entire), and keeps up to 100 matching repositories. Filtering each page, instead of after a single capped lookup, means rows from other providers cannot push this provider's repositories past the cap. It replaces every lookup byproviderRepositoryId: GitHub push, pull request and closed-PR cleanup, Origin push and pull request, and Entire push. Following the module's convention for provider handlers, the method is duplicated in each action instead of put in a shared base.Test Plan
VCSGiteaConsoleClientTest::testGitHubPushIgnoresGiteaRepository: connects a function to a Gitea repository, sends a correctly signed GitHub push naming that repository's id, and asserts the delivery returns 200 and creates no deployment. Without this change the GitHub handler treats the Gitea repository as linked and tries to build a GitHub client for the delivery's installation.phpstan.neon) and Rector pass on the touched files. E2E runs in the CI lanes.Related PRs and Issues
None.
Checklist
Related: appwrite-labs/cloud#6666