Skip to content

fix(vcs): verify GitHub installation access before connecting it - #14783

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/vcs-github-installation-ownership
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/vcs-github-installation-ownership

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Hardens GET /v1/vcs/github/callback so a project can only connect a GitHub App installation that the authorizing GitHub user can access.

The installation_id GitHub appends to the callback is not covered by the signed state, and the owner lookup uses the app credentials, which accept every installation of the app. The callback now:

  • requires the OAuth code whenever an installation_id is present, and redirects to the failure URL with an error when it is missing
  • exchanges the code for a user token (a failed exchange redirects to the failure URL instead of surfacing a 500)
  • pages through GET https://api.github.com/user/installations with that token and connects the installation only if its id is listed
  • only then resolves the owner and creates or updates the installation row (now a sparse update)

packages/vcs has no method for listing a user's installations, so the lookup is a private method on the action using the existing clientForOAuth2 HTTP client resource. The OAuth token exchange now uses the same client. The three duplicated failure-redirect blocks are folded into one private failure() method, matching Callback/Base.

Compatibility

The self-hosting guide already asks operators to enable Request user authorization (OAuth) during installation and Redirect on update on their GitHub App. With that setting GitHub always sends code together with installation_id and setup_action (install or update), so the Console flow keeps working. A GitHub App set up without that option will now get the "no authorization code" error and has to enable it. Callbacks with no installation_id (setup_action=request, members without install rights) behave as before.

Test Plan

  • New e2e VCSGitHubConsoleClientTest::testGitHubCallbackRejectsUnverifiedInstallation: a correctly signed state plus an installation_id, with the code missing and with an invalid code, must redirect to the failure URL with ?error= and leave the project's GitHub installations unchanged. Without this change the first call connects the installation and redirects to the success URL.
  • The successful path needs a real GitHub user authorization code, which the e2e suite cannot produce (existing GitHub tests create installations through /v1/mock/github/callback), so it is not covered end to end.
  • 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

The GitHub callback took installation_id from the query string and only
checked it against the app credentials, which accept any installation of
the app. Require the OAuth code returned with the installation, exchange
it, and connect the installation only when it is listed in the
authorizing user's accessible installations.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Wrap getUserSlug/getOwnerName calls in the failure redirect — Get.php:132

This PR rewrites the GitHub App OAuth callback to exchange the authorization code for tokens, verify via the GitHub API that the authorizing user actually has access to the installation, and route every failure through a single signed redirect-or-throw helper, with a new e2e test covering the missing/invalid code rejection.

Files Change
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php Reworks the callback: verifies installation access via the GitHub API, persists fresh installation attributes, and centralizes failure handling in a redirect helper
tests/e2e/Services/VCSGitHub/VCSGitHubConsoleClientTest.php Adds e2e coverage for the callback rejecting a missing or invalid code parameter

One medium finding: two GitHub API calls (getOwnerName/getUserSlug) sit outside the new try/catch, so a transient provider failure escapes the friendly signed failure-redirect path and surfaces as an unhandled error instead.

Reviewed commit: d0ab07b

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental changes introduce no actionable defects.

The GitHub callback now requires an OAuth code and verifies that the authorizing user can access the reported installation before creating or updating its project record. It centralizes failure redirects, handles GitHub lookup failures, and adds e2e coverage for callbacks missing an authorization code.

Latest changes: The latest commits redirect exceptions during GitHub installation-detail lookups to the failure URL and remove the invalid-code exchange case from the e2e test.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php Verifies installation access with the authorizing user's token, persists installation details only after verification, and redirects failures from GitHub lookups.
tests/e2e/Services/VCSGitHub/VCSGitHubConsoleClientTest.php Checks that a callback containing an installation ID but no authorization code redirects to failure without adding an installation.

Reviewed the commits since d0ab07b · 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 · Looks good to merge. 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.

Hardens the GitHub App OAuth callback with signed-state redirects and an installation-access verification check, plus a new e2e test for the missing/invalid code path.

Key findings

  • 🟡 Wrap getUserSlug/getOwnerName calls in the failure redirect — Get.php:132

Comment on lines +132 to +133
$owner = $vcs->getOwnerName($providerInstallationId);
$personal = $oauth2->getUserSlug($accessToken) === $owner;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 bug · medium

Wrap getUserSlug/getOwnerName calls in the failure redirect

The try/catch at src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php:114-121 guards only the three token-exchange calls, but $vcs->getOwnerName(...) (line 132) and $oauth2->getUserSlug($accessToken) (line 133) also make GitHub API calls outside it. getUser() throws Appwrite\Auth\OAuth2\Exception when /user returns a >= 400 status or a non-JSON body, so a transient GitHub API failure during the callback surfaces as an unhandled 500 error page instead of the signed $redirectFailure redirect every other failure in this flow produces. The installation is also left un-persisted with no friendly message sent back to the console.

📋 Prompt for AI Agents

In src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php lines 114-133, extend the existing try/catch (lines 114-121) so that $vcs->getOwnerName($providerInstallationId) and $oauth2->getUserSlug($accessToken) are also covered; on throw, call $this->failure($response, $redirectFailure, 'Failed to verify your GitHub account. Please restart the installation from the Appwrite Console.') and return without persisting the installation. This keeps every provider-side failure after the token exchange on the signed failure-redirect path.

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 5da1670: the adapter construction, getOwnerName and getUserSlug are now wrapped and fall back to the signed failure redirect.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/vcs-github-installation-ownership (after).

Metric Before After Change
🚀 Requests/sec 180.18 174.39 ⚪ -3.2%
⏱️ Latency P50 96.02 ms 100.12 ms ⚪ +4.3%
⏱️ Latency P95 225.64 ms 230.04 ms ⚪ +1.9%
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 100.12 230.04 11,229 174.39 +4.39
Account 185.39 332.97 591 9.76 +9.66
TablesDB 98.08 181.47 6,107 97.57 +13.72
Storage 90.99 216.26 2,955 48.74 +7.49
Functions 132.21 264.89 1,576 26.59 -67.82

Top API waits (after)

API request Max wait (ms)
account.name.update 572.95
tablesdb.rows.create 516.99
account.prefs.update 503.59
storage.buckets.create 488.9
functions.variables.create 447.24

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

…back

Owner and user lookups after the code exchange could surface a 500 instead
of the signed failure redirect. The e2e test no longer sends a made-up code
to GitHub's token endpoint.
@ChiragAgg5k
ChiragAgg5k merged commit acab02f into main Oct 22, 2026
42 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/vcs-github-installation-ownership branch October 22, 2026 17:49
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
#14783)

Ported by hand: 1.9.x has no clientForOAuth2 resource, so the user installations lookup uses utopia-php/fetch.

(cherry picked from commit acab02f)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
#14783)

Ported by hand: 1.9.x has no clientForOAuth2 resource, so the user installations lookup uses utopia-php/fetch.

(cherry picked from commit acab02f)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…lation-ownership

fix(vcs): verify GitHub installation access before connecting it

(cherry picked from commit acab02f)
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