-
Notifications
You must be signed in to change notification settings - Fork 18
fix: authenticate python index requests on same host regardless of path #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -95,7 +95,13 @@ func (h *PythonIndexHandler) HandleRequest(req *http.Request, ctx *goproxy.Proxy | |||||||||
| // Fall back to static credentials | ||||||||||
| for _, cred := range h.credentials { | ||||||||||
| indexURL := simpleSuffixRe.ReplaceAllString(cred.indexURL, "/") | ||||||||||
| if !helpers.UrlMatchesRequest(req, indexURL, true) && !helpers.CheckHost(req, cred.host) { | ||||||||||
| // Apply credentials if: | ||||||||||
| // 1. URL matches with path (e.g., /pypi/...), OR | ||||||||||
| // 2. Host:port matches (regardless of path), OR | ||||||||||
| // 3. Explicit host field matches | ||||||||||
| if !helpers.UrlMatchesRequest(req, indexURL, true) && | ||||||||||
| !helpers.UrlMatchesRequest(req, indexURL, false) && | ||||||||||
|
Comment on lines
+102
to
+103
|
||||||||||
| if !helpers.UrlMatchesRequest(req, indexURL, true) && | |
| !helpers.UrlMatchesRequest(req, indexURL, false) && | |
| if !helpers.UrlMatchesRequest(req, indexURL, true) && | |
| !helpers.UrlMatchesRequest(req, indexURL, false) && |
Copilot
AI
Apr 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new host-only matching is only applied to static credentials in the fallback loop. When a python_index credential is OIDC-configured, NewPythonIndexHandler registers it in oidcRegistry and does not add it to h.credentials, so requests on the same host but different paths will still not be authenticated via OIDC (since OIDCRegistry.TryAuth is path-prefix based). If the reported issue affects OIDC-based python index auth too, this change won't address it; consider whether OIDC registrations for python indexes should also support host-only matching (or an explicit opt-in).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,4 +104,11 @@ func TestPythonIndexHandler(t *testing.T) { | |
| req = httptest.NewRequest("GET", "https://PKGS.dev.azure.com/somepkg", nil) | ||
| req = handleRequestAndClose(handler, req, nil) | ||
| assertHasBasicAuth(t, req, deltaForceUser, deltaForcePassword, "azure devops case insensitive registry request") | ||
|
|
||
| // Package download on completely different path on same host | ||
| // Simulates: config pypi.cyco.fun/pypi, but request to pypi.cyco.fun/packages/... | ||
| // Using corp.deltaforce.com which has / as the index path | ||
| req = httptest.NewRequest("GET", "https://corp.deltaforce.com/packages/somepkg/1.0/wheel.whl", nil) | ||
| req = handleRequestAndClose(handler, req, nil) | ||
| assertHasBasicAuth(t, req, deltaForceUser, deltaForcePassword, "cert registry with package download on different path") | ||
|
Comment on lines
+109
to
+113
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helpers.UrlMatchesRequest(req, indexURL, false)makes index-url credentials apply to any request on the same host:port (regardless of path). This is a behavioral change from URL+path prefix scoping and will cause previously-path-mismatched requests (e.g./foowhen configured for/pyreg/) to be authenticated, potentially leaking credentials to unrelated endpoints on the same host. Consider keeping path scoping forindex-urland only allowing host-only matching when an explicithostfield is configured (as other handlers do), or introduce an explicit opt-in for host-only matching rather than inferring it fromindex-url.