Skip to content

Commit 1a4998c

Browse files
committed
adding subdomain for uploads too
1 parent e6fa90d commit 1a4998c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

internal/ghmcp/server.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,22 @@ func newGHESHost(hostname string) (apiHost, error) {
364364
return apiHost{}, fmt.Errorf("failed to parse GHES GraphQL URL: %w", err)
365365
}
366366

367-
uploadURL, err := url.Parse(fmt.Sprintf("%s://%s/api/uploads/", u.Scheme, u.Hostname()))
367+
// Check if subdomain isolation is enabled
368+
// See https://docs.github.com/en/[email protected]/admin/configuring-settings/hardening-security-for-your-enterprise/enabling-subdomain-isolation#about-subdomain-isolation
369+
hasSubdomainIsolation := checkSubdomainIsolation(u.Scheme, u.Hostname())
370+
371+
var uploadURL *url.URL
372+
if hasSubdomainIsolation {
373+
// With subdomain isolation: https://uploads.hostname/
374+
uploadURL, err = url.Parse(fmt.Sprintf("%s://uploads.%s/", u.Scheme, u.Hostname()))
375+
} else {
376+
// Without subdomain isolation: https://hostname/api/uploads/
377+
uploadURL, err = url.Parse(fmt.Sprintf("%s://%s/api/uploads/", u.Scheme, u.Hostname()))
378+
}
368379
if err != nil {
369380
return apiHost{}, fmt.Errorf("failed to parse GHES Upload URL: %w", err)
370381
}
371382

372-
// Check if subdomain isolation is enabled
373-
hasSubdomainIsolation := checkSubdomainIsolation(u.Scheme, u.Hostname())
374-
375383
var rawURL *url.URL
376384
if hasSubdomainIsolation {
377385
// With subdomain isolation: https://raw.hostname/

0 commit comments

Comments
 (0)