Skip to content

fix(vcs): bind GitHub repository links to their installation - #14975

Merged
lohanidamodar merged 6 commits into
mainfrom
fix/vcs-repository-installation-check
Oct 29, 2026
Merged

lohanidamodar merged 6 commits into
mainfrom
fix/vcs-repository-installation-check

Conversation

@lohanidamodar

Copy link
Copy Markdown
Member

What does this PR do?

Hardens how Git repositories are bound to VCS installations for installation-scoped providers like GitHub.

  • Connecting a repository (Sites and Functions, create and update): the repository is now resolved through the project's own installation. For installation-scoped providers, it must belong to that installation's owner, or the request fails with provider_repository_not_found before anything is saved. Until now, this lookup ran only for repository-scoped providers.
  • GitHub webhooks (push, pull request, and closed-PR cleanup): only repository links made through the installation that sent the event are matched. Matching by repository ID alone is no longer enough.
  • resolveInstallationRepository in Compute\Base is shared by the four connect paths. Those paths now pass its owner and name to RepositoryWebhooks::ensure, which already skips installation-scoped providers.

Test Plan

New E2E tests in VCSGitHubConsoleClientTest:

  • testConnectRepositoryOutsideInstallationRejected: creating a function or site, or updating a function, with a public repository outside the installation returns 404 provider_repository_not_found.
  • testGitHubPushFromAnotherInstallationIsIgnored: a signed push for a linked repository from a different installation creates no deployment.

Existing VCS tests cover legitimate links and pushes through the same installation.

Locally: Pint, PHPStan and Rector refactor:check pass on the changed files.

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?

Verify on connect that the repository belongs to the installation's owner for
installation-scoped providers, and match push and pull request webhooks only
against repositories linked through the event's installation.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Reconnect path skips repository ownership validation · Update.php:285–297 · unchanged line

// src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php
285	        if ($isConnected && !empty($providerRepositoryId) && !empty($repositoryId) && !$installation->isEmpty()) {
286	            $repository = $dbForPlatform->getDocument('repositories', $repositoryId);
287	            if (
288	                !$repository->isEmpty()
289	                && $repository->getAttribute('providerRepositoryId') === $providerRepositoryId
290	                && $repository->getAttribute('installationInternalId') !== $installation->getSequence()
291	            ) {
292	                $dbForPlatform->updateDocument('repositories', $repository->getId(), new Document([
293	                    'installationId' => $installation->getId(),
294	                    'installationInternalId' => $installation->getSequence(),
295	                ]));
296	            }

The new resolveInstallationRepository guard runs only in the !$isConnected branch, but a connected function can still receive a different providerRepositoryId in the same update: the connect block is skipped, no ownership check runs, and the document update at src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php:351 persists the unvalidated providerRepositoryId while keeping the old repositoryId, leaving the resource pointing at a repository document for a different repo. The reconnect block (lines 285-297) also re-points an existing repository link to another installation with no provider-side verification. The exact scenario the new e2e test rejects on create and unconnected update is therefore still reachable via update of an already-connected function, producing a link whose repository id and repository document disagree. The same gap exists in src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php in the mirrored blocks.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Provider failures in resolveInstallationRepository map to wrong errors (Base.php:115) — resolveInstallationRepository catches only RepositoryNotFound (src/Appwrite/Platform/Modules/Compute/Base.php:115), but the adapters throw more: GitHub's getOwnerName throws OwnerNotFound for a deleted installation and a generic Exception otherwise, GitLab's getRepositoryName throws a plain Exception on any 4xx/5xx, and getRepository returns the raw body for non-404 statuses.

This PR introduces resolveInstallationRepository in Compute\Base, which verifies during create and update that a requested providerRepositoryId actually belongs to the caller's provider installation before it is linked to a function or site. GitHub webhook handling is tightened so builds trigger only for pushes matching the recorded providerInstallationId, and the e2e suite gains a rejection test for connecting a repository outside the installation.

Files Change
src/Appwrite/Platform/Modules/Compute/Base.php Adds resolveInstallationRepository plus repository-document cleanup on failure during create/update.
src/Appwrite/Platform/Modules/Functions/Http/Functions/{Create,Update}.php, src/Appwrite/Platform/Modules/Sites/Http/Sites/{Create,Update}.php Wire the ownership check into connect and reconnect paths for functions and sites.
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php Filters push events by providerInstallationId so only the connected installation triggers builds.
tests/e2e/Services/VCSGitHub/VCSGitHubConsoleClientTest.php Adds an e2e case asserting the cross-installation connect is rejected.

Reviewed commit: aaefe1d

@ghost

ghost commented Oct 27, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The earlier scan-cap finding is resolved, and the incremental changes introduce no remaining issues.

Repository connections for Functions and Sites are resolved through their owning VCS installation, and GitHub webhook events are matched to links from the installation that sent them. The PR adds E2E coverage for rejecting repositories outside an installation and ignoring cross-installation pushes, along with adapter coverage for scanning beyond 1,000 repositories.

Latest changes: The latest commits remove the 1,000-repository scan cap in GitHub installation lookup and add a regression test for repositories beyond that boundary and missing repositories.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 9
File Change
packages/vcs/src/Adapter/Git/GitHub.php Removes the fixed page cap when looking up a repository in a GitHub installation.
packages/vcs/tests/GitHubTest.php Adds adapter coverage for finding a repository beyond the former cap and reporting a missing repository.
src/Appwrite/Platform/Modules/Compute/Base.php Adds shared validation that resolves linked repositories through their owning installation.
src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php Resolves the selected repository through its installation before creating a function.
src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php Validates repository selection when connecting or changing a function's installation.
src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php Resolves the selected repository through its installation before creating a site.
src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php Validates repository selection when connecting or changing a site's installation.
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php Scopes push, pull-request, and closed-PR cleanup matching to the event's installation.
tests/e2e/Services/VCSGitHub/VCSGitHubConsoleClientTest.php Adds E2E coverage for rejecting out-of-installation repositories and ignoring cross-installation pushes.
✅ Fixed since the last review · 1
  • Valid repositories beyond the 1,000-repo scan are rejected · src/Appwrite/Platform/Modules/Compute/Base.php:115

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

ghost
ghost previously requested changes Oct 27, 2026

@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 B · 1 blocking finding to address. Summary

@github-actions

github-actions Bot commented Oct 27, 2026 •

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.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/vcs-repository-installation-check (after).

Metric Before After Change
🚀 Requests/sec 136.66 130.92 ⚪ -4.2%
⏱️ Latency P50 125.53 ms 132.02 ms 🔴 +5.2%
⏱️ Latency P95 294.58 ms 313.66 ms 🔴 +6.5%
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 132.02 313.66 8,151 130.92 +19.08
Account 252.5 452.8 429 7.1 +26.03
TablesDB 126.99 244.62 4,433 72.7 +14.94
Storage 122.88 279.89 2,145 37.54 +13.05
Functions 182.11 362.87 1,144 20.72 +16.99

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 587.86
account.get 561.29
account.name.update 519.46
account.prefs.update 489.99
functions.delete 483.7

@lohanidamodar

Copy link
Copy Markdown
Member Author

Responses to the review:

  • Reconnect path: fixed in 395f7ec, which now verifies the repository before moving a link to another installation.
  • Changing providerRepositoryId while already connected: this behavior predates the PR. That update never creates or changes a repository link, so the webhook still matches the old repository ID only, and only for its own installation. I've left it out of scope.
  • Other provider errors (OwnerNotFound, generic failures) still fail the request instead of linking, so I left them unmapped to keep the diff small.

@ghost
ghost dismissed their stale review October 27, 2026 01:26

The findings that requested changes are resolved. See the summary comment for what is still open.

@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

@abnegate

Copy link
Copy Markdown
Member

@hansi-codes review

@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

@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

lohanidamodar and others added 2 commits October 29, 2026 08:57
getInstallationRepository stopped after 1,000 repositories, so a selected
repository past that point was reported as not selected.

@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

@lohanidamodar
lohanidamodar merged commit 58cf2f3 into main Oct 29, 2026
47 checks passed
@lohanidamodar
lohanidamodar deleted the fix/vcs-repository-installation-check branch October 29, 2026 11:20
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.

3 participants