Skip to content

fix(vcs): match event repositories to their provider's installations - #14800

Merged
ChiragAgg5k merged 4 commits into
mainfrom
fix/vcs-event-installation-provider
Oct 22, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
fix/vcs-event-installation-provider

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

The GitHub, Origin and Entire webhook handlers looked up repositories by providerRepositoryId alone. The Gitea, GitLab and Bitbucket handlers also check that each repository's installation belongs to their provider (resolveGiteaInstallation and 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's providerRepositoryId, 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 by providerRepositoryId: 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

  • New e2e 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.
  • Pint, PHPStan (host, phpstan.neon) and Rector pass on the touched files. E2E runs in the CI lanes.

Related PRs and Issues

None.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Related: appwrite-labs/cloud#6666

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.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Avoid one installation lookup per repository in filterRepositories — Create.php:207
🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Consolidate the duplicated filterRepositories helper (Create.php:204) — The same filterRepositories body is added to three controllers, differing only in the provider literal (src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php line 204; the Entire and Origin controllers carry identical copies).

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

Reviewed commit: 9f7536a

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

GitHub, 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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/VCS/Http/Entire/Events/Create.php Filters paginated repository matches to Entire installations for push events.
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php Filters paginated repository matches to GitHub installations for push, pull-request, and cleanup events.
src/Appwrite/Platform/Modules/VCS/Http/Origin/Events/Create.php Filters paginated repository matches to Origin installations for push and pull-request events.
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php Adds and strengthens the regression check that a GitHub push naming a Gitea repository does not create a deployment.

Reviewed the commits since 8714fde · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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', '')));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/vcs-event-installation-provider (after).

Metric Before After Change
🚀 Requests/sec 186.36 199.69 🟢 +7.1%
⏱️ Latency P50 91.53 ms 87.1 ms ⚪ -4.8%
⏱️ Latency P95 221.41 ms 204.12 ms 🟢 -7.8%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 87.1 204.12 12,540 199.69 -17.29
Account 157.5 300.81 660 11.2 -18.98
TablesDB 82.48 152.95 6,820 111.27 -34.85
Storage 83.61 201.64 3,300 55.34 +4.21
Functions 126.05 229.95 1,760 30.19 -10.73

Top API waits (after)

API request Max wait (ms)
account.name.update 587.7
account.prefs.update 420.53
storage.files.create 399.43
storage.buckets.create 369.78
tablesdb.rows.decrement 368.69

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

The deployments list does not accept a commit hash filter.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 0772262 into main Oct 22, 2026
39 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/vcs-event-installation-provider branch October 22, 2026 17:50
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…ation-provider

fix(vcs): match event repositories to their provider's installations

(cherry picked from commit 0772262)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant