Skip to content

Commit 4dd5055

Browse files
committed
fix: public github release downloads should not be authenticated
1 parent 72f780a commit 4dd5055

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

internal/handlers/git_server.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ func getCredentialsForRequest(r *http.Request, credentials *gitCredentialsMap, e
327327
hostCreds := credentials.get(host)
328328
credsForRequest := hostCreds.getCredentialsForRepo(allReposScopeIdentifier)
329329

330+
// GitHub release download URLs are public
331+
// and do not require authentication
332+
if len(credsForRequest) != 0 && isGitHubReleaseDownload(r.URL.Path) {
333+
return nil
334+
}
335+
330336
// Append any repo-scoped credentials
331337
if org, repo, ok := extractor(r.URL.Path); ok {
332338
nwo := fmt.Sprintf("%s/%s", org, repo)
@@ -343,6 +349,10 @@ func getCredentialsForRequest(r *http.Request, credentials *gitCredentialsMap, e
343349
return credsForRequest
344350
}
345351

352+
func isGitHubReleaseDownload(path string) bool {
353+
return strings.Contains(path, "/releases/download/")
354+
}
355+
346356
// HandleResponse handles retrying failed auth responses with alternate credentials
347357
// when there are multiple tokens configured for the git server.
348358
//

internal/handlers/git_server_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ func TestGitServerHandler(t *testing.T) {
124124
"valid github request")
125125
}
126126

127+
func TestGitServerPublicReleaseDownload(t *testing.T) {
128+
installationCred := testGitSourceCred("github.com", "x-access-token", "v1.token")
129+
gheCred := testGitSourceCred("ghe.some-corp.com", "x-access-token", "corp")
130+
131+
credentials := config.Credentials{
132+
installationCred,
133+
gheCred,
134+
}
135+
handler := NewGitServerHandler(credentials, nil)
136+
137+
req := httptest.NewRequest("HEAD", "https://github.com/gradle/gradle-distributions/releases/download/v9.3.0/gradle-9.3.0-bin.zip", nil)
138+
req, _ = handler.HandleRequest(req, nil)
139+
assertUnauthenticated(t, req, "Public release download URL should not be authenticated")
140+
}
141+
127142
func TestGitServerHandler_AuthenticatedAccessToGitHubRepos(t *testing.T) {
128143
installationToken1 := "v1.token1"
129144
privateRepo1Cred := testGitSourceCred("github.com", "x-access-token", installationToken1, withAccessibleRepos([]string{"github/private-repo-1"}))

0 commit comments

Comments
 (0)