Skip to content

Find, verify, and analyze leaked credentials

Do not nest transports for Github installation client (#1564)

Cody Rosead57de50cd5c
diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.go
index b959ca009..9d6d05329 100644
--- a/pkg/sources/github/github.go
+++ b/pkg/sources/github/github.go
@@ -556,38 +556,41 @@ func (s *Source) enumerateWithApp(ctx context.Context, apiEndpoint string, app *
return nil, errors.New(err)
}
- // This client is used for most APIs.
- itr, err := ghinstallation.New(
+ // This client is required to create installation tokens for cloning.
+ // Otherwise, the required JWT is not in the request for the token :/
+ // This client uses the source's original HTTP transport, so make sure
+ // to build it before modifying that transport (such as is done during
+ // the creation of the other API client below).
+ appItr, err := ghinstallation.NewAppsTransport(
s.httpClient.Transport,
appID,
- installationID,
[]byte(app.PrivateKey))
if err != nil {
return nil, errors.New(err)
}
- itr.BaseURL = apiEndpoint
+ appItr.BaseURL = apiEndpoint
- s.httpClient.Transport = itr
- s.apiClient, err = github.NewEnterpriseClient(apiEndpoint, apiEndpoint, s.httpClient)
+ // Does this need to be separate from |s.httpClient|?
+ instHttpClient := common.RetryableHttpClientTimeout(60)
+ instHttpClient.Transport = appItr
+ installationClient, err = github.NewEnterpriseClient(apiEndpoint, apiEndpoint, instHttpClient)
if err != nil {
return nil, errors.New(err)
}
- // This client is required to create installation tokens for cloning.
- // Otherwise, the required JWT is not in the request for the token :/
- appItr, err := ghinstallation.NewAppsTransport(
+ // This client is used for most APIs.
+ itr, err := ghinstallation.New(
s.httpClient.Transport,
appID,
+ installationID,
[]byte(app.PrivateKey))
if err != nil {
return nil, errors.New(err)
}
- appItr.BaseURL = apiEndpoint
+ itr.BaseURL = apiEndpoint
- // Does this need to be separate from |s.httpClient|?
- instHttpClient := common.RetryableHttpClientTimeout(60)
- instHttpClient.Transport = appItr
- installationClient, err = github.NewEnterpriseClient(apiEndpoint, apiEndpoint, instHttpClient)
+ s.httpClient.Transport = itr
+ s.apiClient, err = github.NewEnterpriseClient(apiEndpoint, apiEndpoint, s.httpClient)
if err != nil {
return nil, errors.New(err)
}