Skip to content

Commit 975c531

Browse files
fix: authenticate python index requests on same host regardless of path
1 parent 2803a0f commit 975c531

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

internal/handlers/python_index.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ func (h *PythonIndexHandler) HandleRequest(req *http.Request, ctx *goproxy.Proxy
9595
// Fall back to static credentials
9696
for _, cred := range h.credentials {
9797
indexURL := simpleSuffixRe.ReplaceAllString(cred.indexURL, "/")
98-
if !helpers.UrlMatchesRequest(req, indexURL, true) && !helpers.CheckHost(req, cred.host) {
98+
// Apply credentials if:
99+
// 1. URL matches with path (e.g., /pypi/...), OR
100+
// 2. Host:port matches (regardless of path), OR
101+
// 3. Explicit host field matches
102+
if !helpers.UrlMatchesRequest(req, indexURL, true) &&
103+
!helpers.UrlMatchesRequest(req, indexURL, false) &&
104+
!helpers.CheckHost(req, cred.host) {
99105
continue
100106
}
101107

internal/handlers/python_index_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,11 @@ func TestPythonIndexHandler(t *testing.T) {
104104
req = httptest.NewRequest("GET", "https://PKGS.dev.azure.com/somepkg", nil)
105105
req = handleRequestAndClose(handler, req, nil)
106106
assertHasBasicAuth(t, req, deltaForceUser, deltaForcePassword, "azure devops case insensitive registry request")
107+
108+
// Package download on completely different path on same host
109+
// Simulates: config pypi.cyco.fun/pypi, but request to pypi.cyco.fun/packages/...
110+
// Using corp.deltaforce.com which has / as the index path
111+
req = httptest.NewRequest("GET", "https://corp.deltaforce.com/packages/somepkg/1.0/wheel.whl", nil)
112+
req = handleRequestAndClose(handler, req, nil)
113+
assertHasBasicAuth(t, req, deltaForceUser, deltaForcePassword, "cert registry with package download on different path")
107114
}

0 commit comments

Comments
 (0)