Fix GitHub App cross-org member enumeration using per-installation tokens#4774
Open
dustin-decker wants to merge 2 commits into
Open
Fix GitHub App cross-org member enumeration using per-installation tokens#4774dustin-decker wants to merge 2 commits into
dustin-decker wants to merge 2 commits into
Conversation
4 tasks
07427a9 to
977a541
Compare
shahzadhaider1
approved these changes
Mar 5, 2026
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5ad29e6. Configure here.
…kens When a GitHub App is installed across multiple orgs, addMembersByApp discovers all installations via JWT but uses a single installation's token to call ListMembers for every org. GitHub App installation tokens only bypass IP allowlists for their own org, causing 403 errors for cross-org calls. Changes: - Add appsTransport and apiEndpoint fields to appConnector - Add APIClientForInstallation method that creates a per-installation API client using ghinstallation.NewFromAppsTransport - Refactor addMembersByApp to create per-installation clients for each discovered org instead of reusing s.connector.APIClient() - Extract addMembersByOrgWithClient so callers can provide an explicit client (addMembersByOrg delegates to it for backward compat) - Update existing tests to pass appConnector and include installation IDs in mock responses - Add new tests for APIClientForInstallation and addMembersByOrgWithClient
Reuse APIClientForInstallation when constructing the configured GitHub App client so the default path shares the same per-installation client creation logic as cross-org enumeration.
a6449cc to
a3fe806
Compare
Contributor
Author
|
Rebased on latest main, CI is green (15 passing, 0 failing), and all active review threads are resolved. Ready for review/merge once the required approval is refreshed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
addMembersByAppdiscovers all installations via JWT but uses a single installation's token forListMemberscalls across all orgsAPIClientForInstallationtoappConnectorwhich creates per-installation API clients usingghinstallation.NewFromAppsTransportaddMembersByOrgWithClientfromaddMembersByOrgso the app auth path can provide an explicit per-installation clientTest plan
APIClientForInstallation(3 subtests verifying distinct clients, correct installation ID, different tokens)addMembersByOrgWithClientTestAddMembersByAppandTestEnumerateWithAppupdated and passinggo buildpassesNote
Medium Risk
Changes GitHub App authentication and org member enumeration; mis-scoped tokens could still miss members, but behavior is narrowed with tests and per-org error isolation.
Overview
Fixes GitHub App member enumeration when the app is installed on multiple orgs by using an installation-scoped API client for each org instead of one token for every
ListMemberscall (which caused 403s when IP allowlists apply per installation).appConnectornow keeps the sharedAppsTransportand addsAPIClientForInstallation, built withghinstallation.NewFromAppsTransport; the default API client fromNewAppConnectorstill targets the configured installation ID.addMembersByAppwalks app installations, builds a client per installation ID, and callsaddMembersByOrgWithClient; failures for a single org are logged and skipped rather than aborting the whole run.addMembersByOrgdelegates to the same helper with the connector’s default client.New unit tests cover per-installation clients and the refactored member listing; existing app enumeration tests were updated for installation IDs in mocks.
Reviewed by Cursor Bugbot for commit a3fe806. Bugbot is set up for automated code reviews on this repo. Configure here.