Skip to content

Fix GHEC base URL Issue#4777

Draft
shahzadhaider1 wants to merge 3 commits intotrufflesecurity:mainfrom
shahzadhaider1:fix/ghec-baseurl
Draft

Fix GHEC base URL Issue#4777
shahzadhaider1 wants to merge 3 commits intotrufflesecurity:mainfrom
shahzadhaider1:fix/ghec-baseurl

Conversation

@shahzadhaider1
Copy link
Contributor

@shahzadhaider1 shahzadhaider1 commented Feb 27, 2026

Description:

Explain the purpose of the PR.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Note

Medium Risk
Changes how GitHub REST/GraphQL clients and GitHub App transports derive BaseURL for enterprise endpoints; mis-detection or URL normalization could break authentication or API calls for some enterprise configurations, though coverage is improved with new targeted tests.

Overview
Fixes GitHub Enterprise Cloud with data residency (*.ghe.com) endpoint handling by detecting GHE.com instances, normalizing web vs API hostnames, and building REST/GraphQL clients without /api/v3 (GraphQL at /graphql).

Updates GitHub App auth to ensure ghinstallation token refresh and clients inherit the correct enterprise BaseURL (via NewFromAppsTransport), and adds tests covering GHE.com normalization/detection, correct BaseURL construction for cloud vs GHES vs GHE.com, and App transport BaseURL propagation.

Written by Cursor Bugbot for commit 2021488. This will update automatically on new commits. Configure here.

…ew() to ensure the enterprise BaseURL is properly inherited
if err != nil {
return nil, fmt.Errorf("could not normalize GHE.com endpoint: %w", err)
}
installationTransport.BaseURL = normalizedURL
Copy link

Choose a reason for hiding this comment

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

Trailing slash on ghinstallation BaseURL causes mismatch

Medium Severity

normalizeGHECloudAPIEndpoint appends a trailing slash (for go-github's BaseURL requirement), but here its result is assigned to installationTransport.BaseURL, which is a ghinstallation field. The ghinstallation library expects BaseURL without a trailing slash (its default is "https://api.github.com"). This trailing slash can produce double-slash URLs during token refresh (e.g., https://api.company.ghe.com//app/installations/...).

Fix in Cursor Fix in Web

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

baseURLField := transportVal.FieldByName("BaseURL")
require.True(t, baseURLField.IsValid(), "Transport should have a BaseURL field")
assert.Equal(t, enterpriseEndpoint, baseURLField.String(),
"Transport.BaseURL should be set to enterprise endpoint")
Copy link

Choose a reason for hiding this comment

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

Test expects BaseURL without trailing slash, code adds one

Medium Severity

The test asserts that the transport's BaseURL equals enterpriseEndpoint ("https://api.example.ghe.com", no trailing slash). However, normalizeGHECloudAPIEndpoint always sets u.Path = "/" before returning, so the actual BaseURL stored on the installationTransport (and inherited by apiTransport via NewFromAppsTransport) will be "https://api.example.ghe.com/" — with a trailing slash. Both assertions at lines 396 and 408 will fail due to this mismatch.

Additional Locations (1)

Fix in Cursor Fix in Web

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