Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ensure passwords in hosted Git URLs are correctly escaped#58

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@stevenhilder
Copy link
Contributor

What

Hosted Git URLs may be specified in the formatprotocol://username:password@domain/path.

However, when the username and/or password contain certain punctuation characters (notably: or@), this library fails to return the credentials with these characters correctly escaped.The result is that npm either fails to connect because the hostname has been parsed incorrectly, or fails to authenticate with the host because the credentials have been parsed incorrectly.

constHostedGitInfo=require('hosted-git-info');constusername='user:n@me';constpassword='p@ss:word';constauth=encodeURIComponent(username)+':'+encodeURIComponent(password);consturl='https://'+auth+'@github.com/npm/hosted-git-info.git';constparsed=HostedGitInfo.fromUrl(url);// expected: user%3Ana%40me:p%40ss%3Awordconsole.log(parsed.auth);// actual: user:na@me:p@ss:word

Why

The reason for this is that the "Legacy" API of Node.js'url moduledoes not escape these characters in theauth property of the parsed URL.

Seehttps://nodejs.org/api/url.html#url_percent_encoding_in_urls for details.

How

Node.js' newer, WHATWG-compatible APIdoes escape theusername andpassword properties of the parsed URL. The fix that I propose in this PR is to continue using the Legacy API to minimize code changes and therefore risk of regression, but to use the WHATWG API to return the parsed username and passwordonly when auth is included in the URL.

@isaacs
Copy link
Contributor

This sounds reasonable, but definitely needs a test to be accepted.

My concern is ensuring that this doesn't cause any problems with how pacote et al make the request for the module. Do you have an example where this currently fails in the CLI, so that we can ensure it is fixing a real problem? If it currentlydoesn't fail in the CLI, then that means it probablywill fail with this change (which might still be reasonable, but means that other changes will be required to integrate the version of hosted-git-info/npm-package-arg that includes this change, making it semver-major).

For npm v7, we've been moving towards using the WhatWG-style urls throughout the CLI. I'm assuming that might change the approach here, since escaped auth would be the default? If it turns out to be a semver-major change, we may as well go all the way and use the new parsing style, especially if it's not possible (or just not worth the effort) to pull this in until npm v7 anyway.

@stevenhilder
Copy link
ContributorAuthor

Test added, along with fix for edge-cases where only usernameor password is provided, not both.

Yes, I encountered the problem in the CLI and tracked the error via pacote and npa through to this module.

With apackage.json file similar to the following...

{"dependencies": {"my-dependency":"https://my-username:p%40ssword@github.com/my-username/my-dependency.git"  }}

...the CLI fails with an error similar to the following...

npm ERR! Error while executing:npm ERR! /usr/bin/git ls-remote -h -t https://my-username:p@ssword@github.com/my-username/my-dependency.gitnpm ERR! npm ERR! fatal: unable to access 'https://ssword@github.com/my-username/my-dependency.git/': Could not resolve host: ssword@github.comnpm ERR! npm ERR! exited with error code: 128

With my fix, I am able to runnpm install successfully with no impact (that I could find) on unauthenticated URLs or authenticated URLs without special characters. Therefore I believe this is a bugfix,not a semver-major change.


For npm v7, bear in mind that the newer URL API doesn't provide an.auth property on parsed URLs. You'll have to build the auth from.username and.passwordthe same way I did here; but yes, it will be escaped by default (including in.href).

@isaacs
Copy link
Contributor

Thanks for looking into that@stevenhilder! It looks like this is reasonable to try to get into the next npm/cli v6 release as a bugfix then.

stevenhilder reacted with thumbs up emoji

@mikemimikmikemimik added this to theOSS - Sprint 4 milestoneFeb 13, 2020
@darcyclarkedarcyclarke self-requested a reviewFebruary 18, 2020 17:47
@darcyclarkedarcyclarke self-assigned thisFeb 18, 2020
Copy link
Contributor

@darcyclarkedarcyclarke left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

✅ LGTM; That said,@isaacs are we sure we can pull this in tonpm@6.x as we're currently onhosted-git-info@2.85? I guess the biggest Q there is whether there were serious breaking changes inhosted-git-info@3.0

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

2 more reviewers

@isaacsisaacsisaacs approved these changes

@darcyclarkedarcyclarkedarcyclarke approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@darcyclarkedarcyclarke

Labels

None yet

Projects

None yet

Milestone

OSS - Sprint 4

Development

Successfully merging this pull request may close these issues.

4 participants

@stevenhilder@isaacs@darcyclarke@mikemimik

[8]ページ先頭

©2009-2025 Movatter.jp