fix: add path-prefix matching for static npm registry credentials#146
Open
ryemelia wants to merge 1 commit into
Open
fix: add path-prefix matching for static npm registry credentials#146ryemelia wants to merge 1 commit into
ryemelia wants to merge 1 commit into
Conversation
When multiple npm registries share the same hostname with different URL paths (e.g., two Artifactory virtual repos), the proxy incorrectly applies the first matching credential based on host+port only. This causes 403 errors when the wrong scoped token is sent. Add path-segment-aware matching to the static credential loop, consistent with OIDCRegistry.TryAuth behavior. Credentials configured for /team-a-npm/ will no longer be applied to /team-b-npm/ requests. Fixes dependabot#145
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #145
What
Add path-segment-aware matching to the static credential loop in
NPMRegistryHandler.HandleRequest, so that credentials configured for one path-scoped registry are not applied to sibling paths on the same host.Why
When multiple npm registries share the same hostname but use different URL paths (common with JFrog Artifactory, AWS CodeArtifact, and Azure DevOps), the proxy sends the first matching credential based on host+port only. If the tokens are scoped to their respective repos, the wrong token results in a 403.
The OIDC code path was already fixed via
OIDCRegistry(#78, #87, #91), but the static token fallback was not updated.How
After the existing host+port check, compare the request URL path against the credential's registry path using segment-aware prefix matching:
registry.npmjs.org) continues to match any path on that host — no behavior change./team-a-npmdoes not match/team-a-npm-evil.Tests
TestNPMRegistryHandler_SameHostDifferentPaths: verifies two registries on the same host with different paths receive their respective tokens, and unrelated paths are unauthenticated.All existing tests pass (
go test ./...).Checklist