Skip to content
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

Adds notice support to the login command #4308

Merged
merged 19 commits into from
Nov 3, 2022
Merged

Adds notice support to the login command #4308

merged 19 commits into from
Nov 3, 2022

Conversation

arcanis
Copy link
Member

@arcanis arcanis commented Mar 31, 2022

What's the problem this PR addresses?

The npm registry is implementing some authentication features around tokens. For this to work they need us to display the npm-notice header.

Closes #5006

How did you fix it?

Prints the header before requesting the OTP token.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@arcanis arcanis requested a review from merceyz August 4, 2022 16:24
Comment on lines 275 to 284
const autoOpen = notice.match(/open (https?:\/\/\S+)/i);
if (autoOpen) {
try {
await execUtils.execvp(`open`, [autoOpen[1]], {cwd: ppath.cwd()});
} catch {
try {
await execUtils.execvp(`xdg-open`, [autoOpen[1]], {cwd: ppath.cwd()});
} catch {}
}
}
Copy link
Member

@merceyz merceyz Aug 4, 2022

Choose a reason for hiding this comment

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

Poor Windows users, we should just let https://yarnpkg.com/package/open handle this as it deals with the edge cases.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't open spawn a bundled shell file, meaning that we can't bundle it?

Copy link
Member

@merceyz merceyz Aug 4, 2022

Choose a reason for hiding this comment

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

It can do that but it will check if it can use it first (which it can't) and fall back to the system one.
https://github.com/sindresorhus/open/blob/05ba9e150cc1a2629e518a9cc19b586c6ca3f269/index.js#L173-L182

Copy link
Member

@merceyz merceyz Nov 1, 2022

Choose a reason for hiding this comment

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

I think the ideal solution would be to not automatically open the link, this seems like a CVE waiting to happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

From a UX perspective I think the auto-open would still be very beneficial. What if we checked the hostname (or even the full url) to check it matches a known pattern? Various other tools have this kind of "open if possible" logic (AWS iirc?), so it should be possible to achieve it safely 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a prompt; pressing <enter> will try to open the url, but people can use n (or ctrl-c).

Copy link
Member

Choose a reason for hiding this comment

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

I still don't think we should if we can't do it consistently.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I saw your comment after merging - by consistently, do you refer to the Windows support? I can disable this altogether for win32, if you think that's better (I'm probably a little biased, but I'd like to avoid adding dependencies from this maintainer if I can avoid it ...).

Copy link
Member

@merceyz merceyz Nov 3, 2022

Choose a reason for hiding this comment

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

Yeah, I was referring to Windows support.

@arcanis arcanis merged commit 599df9d into master Nov 3, 2022
@arcanis arcanis deleted the mael/notice-login branch November 3, 2022 10:09
merceyz pushed a commit that referenced this pull request Nov 3, 2022
* Adds notice support to the login command

* Opens the auth url automatically

* Replaces tryPromise with try/catch

* Updates snapshots

* Adds test

* Avoids replaceAll

* Fixes lint

* Loosens the regex

* Fixes tests

* Adds tests

* Adds a prompt before opening the url

* Versions

* Renames TEST_ENV into YARN_IS_TEST_ENV

* Fixes publish test

* Fixes set/version test

* Fixes windows test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add security key 2FA support for yarn npm login
3 participants