Remove fallback npmjs.org auth data #2975
Closed
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.
Problem
The current behaviour is that for scoped packages (
@<scope>/<pkgName>) yarn always sends an authentication to the registry. This was introduced in #1146 in order to support private packages on npmjs.orgWhen a user is loggedin on the cli to npmjs.org and has configured a different pirvate registry, which in most cases is a proxy to npmjs.org, yarn still sends the npmjs.org auth data to the private registry, making the private-registry fail as it does not know anything about npmjs.org credentials.
Summary
The technical reason this happens is that because of the changes in #1146 the flag ‘always-auth’ is set to true for scoped packages (which is actually fine I think), but the method to retrieve the authToken/credentials has a fallback to npmjs.org auth data.
https://github.com/yarnpkg/yarn/blob/master/src/registries/npm-registry.js#L175
The fix was simply to remove all fallbacks from getAuth().
Imho the Fallback to npmjs.org-credentials should never happen, as yarn should never ever send credentials from npmjs.org to any other API besides npmjs.org.
The fallback to
''is most probably in there with old npm clients which were storing credentials without a registry-scope in the config. I couldn't find where--registrywas added but it was already available in 1.4.By looking at it I saw that it still supports insecure plaintext basic auth which is a feature from npm <= 1.4, so I took the risk and removed it. Neither npm >= 2 or yarn do save basic auth data anymore and npm 2 was released in 2014. (
_tokenis also dropped in npm@5)Test plan
I could add some unit-tests for npm-registry, though the critical part would more be to do integration tests.
But I wait for initial feedback before writing tests.
Fixes #2953 #2151