Repository navigation
fix(vcs): verify GitHub installation access before connecting it - #14783
Conversation
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.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
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.
One medium finding: two GitHub API calls ( Reviewed commit: d0ab07b |
🟢 Tier S · Ready to merge
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.
📂 Walkthrough · 2
Reviewed the commits since |
There was a problem hiding this comment.
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/getOwnerNamecalls in the failure redirect — Get.php:132
| $owner = $vcs->getOwnerName($providerInstallationId); | ||
| $personal = $oauth2->getUserSlug($accessToken) === $owner; |
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
Fixed in 5da1670: the adapter construction, getOwnerName and getUserSlug are now wrapped and fall back to the signed failure redirect.
✨ 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
|
…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.
…lation-ownership fix(vcs): verify GitHub installation access before connecting it (cherry picked from commit acab02f)
What does this PR do?
Hardens
GET /v1/vcs/github/callbackso a project can only connect a GitHub App installation that the authorizing GitHub user can access.The
installation_idGitHub 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:codewhenever aninstallation_idis present, and redirects to the failure URL with an error when it is missingGET https://api.github.com/user/installationswith that token and connects the installation only if its id is listedpackages/vcshas no method for listing a user's installations, so the lookup is a private method on the action using the existingclientForOAuth2HTTP client resource. The OAuth token exchange now uses the same client. The three duplicated failure-redirect blocks are folded into one privatefailure()method, matchingCallback/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
codetogether withinstallation_idandsetup_action(installorupdate), 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 noinstallation_id(setup_action=request, members without install rights) behave as before.Test Plan
VCSGitHubConsoleClientTest::testGitHubCallbackRejectsUnverifiedInstallation: a correctly signed state plus aninstallation_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./v1/mock/github/callback), so it is not covered end to end.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