-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: add https port parsing on registry matching for artifactory compatibility #6864
fix: add https port parsing on registry matching for artifactory compatibility #6864
Conversation
💖 Thanks for opening this pull request! 💖 |
078f8d6
to
80dae65
Compare
We cannot add this back. It was removed both from npm and pnpm as it creates a security vulnerability. |
Can we do a registry origin check instead and then resolve the url only if it matches that domain or base path? |
I'll think about it later. @weswigham you were the one who reported the always-auth issue, so I would be happy to have your feedback here. |
@zkochan Since the first commit cannot be merged due to security reasons, I can remove it or make a new PR with only the HTTPS port fix. Related commit that should go in 9efa80a This will allow for scoped packages to resolve correctly if they have the |
…tion for thoses urls
9efa80a
to
fb68e29
Compare
Renamed the PR and rebase dropped the always auth changes. This PR only contains the HTTPS port parsing logic now. |
Noting that the following needs to be done to replicate the issue.
Curiously only the artifactory urls fail that are unavailable externally. I'm wondering if it's defaulting to |
Can you cover this with a unit test? |
Please also handle the case with port |
network/auth-header/src/index.ts
Outdated
/** | ||
* @artifactory adds a https port in the middle of their urls and URL.parse will not return ports in that range | ||
*/ | ||
if (hasHTTPS && urlObj.port === '') { | ||
return urlObj.href | ||
} | ||
|
||
if (urlObj.port === '') return originalUrl |
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.
It is probably just enough to do this:
/** | |
* @artifactory adds a https port in the middle of their urls and URL.parse will not return ports in that range | |
*/ | |
if (hasHTTPS && urlObj.port === '') { | |
return urlObj.href | |
} | |
if (urlObj.port === '') return originalUrl | |
if (urlObj.port === '') return urlObj.href |
it will handle both :80 and :443
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.
@zkochan agreed. I added tests for http|https|ws|wss
and moved the removePort
method to it's own file so it can be tested without exporting it.
…tion for thoses urls
…breaking-artifactory-virtual-registries
…tion for thoses urls
…tion for thoses urls
Congrats on merging your first pull request! 🎉🎉🎉 |
…tifactory compatibility (#6864) Co-authored-by: Frederick Engelhardt <frederick.engelhardt@bestbuy.com> Co-authored-by: Zoltan Kochan <z@kochan.io>
Changes
* add compatibility back forRemoved due to security issue.always-auth=true
so the authorization is still passed to components not matching the registry urlsIssue
1.Removed due to security issue.pnpm
was deleting the authorization header, making registries that act as pass-through registries fail to fetch their tarball file download when attempting to access another registry with shared scope.2.
pnpm
was skipping https ports IE:443
that artifactory was transforming. This caused a registry mismatch and it skipped authorization. This is related to URL which does not returnwell-known
ports (0-1023) in the.ports
param. It still however parses and removes the https port.Solution
Initial fix:
1. Add a logic block to protect against deletion of authorization ifRemoved due to security issue.always-auth
is provided in.npmrc
(<=Node16) or the pnpm config >=Node18.2. Adding a matcher for
:443
fixes the port problem so that when communicating with artifactory the authorization is not removed due to url mismatch.Possible follow-up fixes related to auth (excluded from this PR scope)
registry=https://vllc.dev/artifactory/api/npm/npm-virtual/
adding a second keyregistry-root=https://vllc.dev/artifactory/api/npm/
would capture and add auth to all other registries in this structure and delete the rest.pnpm config file
Use case
This problem applies to all Artifactory registries with (>=2) registries and with scoped packages mixed across each registry. FYI this is a real world problem.
@platform
could resolve to multiple registries resolved by artifactory authorization.Due to a scoped package being unknown which registry to use, using the
@platform:registry=https://<company_domain>/artifactory/api/npm/npm-virtual/
will not properly resolve the package correctly, this is because package-a could point tonpm-virtual
but package-b could point tonpm-virtual-v2
and so on.Artifactory continues to recommend in npm v9 to use the
always-auth=true
flag (which is deprecated in 18).