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

Implements --check-resolutions #4302

Merged
merged 3 commits into from
Mar 31, 2022
Merged

Implements --check-resolutions #4302

merged 3 commits into from
Mar 31, 2022

Conversation

arcanis
Copy link
Member

@arcanis arcanis commented Mar 30, 2022

What's the problem this PR addresses?

If an attacker changes the resolutions field in the lockfile, Yarn will take it relatively well and just assume the new resolution is the truth. As a result they can easily inject malicious code inside a large lockfile update, and they'll be very difficult to spot - even #4299 wouldn't protect against that, as Yarn would just refetch the compromised package resolution rather than the original one.

How did you fix it?

The getSatisfying function (previously only used for yarn dedupe) will now be used to check that the resolution locators are valid for a given descriptor (for example [email protected] isn't a valid resolution for foo@^1.0.0 since they have different idents, but it is a valid resolution for bar@^1.0.0 or even foo@npm:[email protected]).

In order to allow for this, I had to change the signature of the getSatisfying function:

  • It now accepts the resolution dependencies (required for the resolvers like patch: / exec: to compute their derivation)
  • It now accepts an array of locators (required because otherwise we can't check the idents)
  • It now returns a sorted property (required because sorting still doesn't make sense in many resolvers)

More tests need to be written (I wrote a few to cover the main ones, ie Git and npm), but I'm not sure I'll write them all in this PR alone.

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 mentioned this pull request Mar 30, 2022
3 tasks
if (opts.checkResolutions) {
const {locators} = await noLockfileResolver.getSatisfying(descriptor, resolvedDependencies, [finalResolution], {...resolveOptions, resolver: noLockfileResolver});
if (!locators.find(locator => locator.locatorHash === finalResolution.locatorHash)) {
throw new ReportError(MessageName.RESOLUTION_MISMATCH, `Invalid resolution ${structUtils.prettyResolution(this.configuration, descriptor, finalResolution)}`);
Copy link
Member

Choose a reason for hiding this comment

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

I feel like the error message could include a more detailed explanation detailing what it means that the resolution is invalid, how it might've happened and how it could be fixed.

Copy link
Member Author

@arcanis arcanis Mar 30, 2022

Choose a reason for hiding this comment

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

I'd like to keep messages on one line if possible, so I was thinking to explain that in more details within the website's error page (especially since this error should never surface in regular situations).

Copy link
Member

Choose a reason for hiding this comment

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

🤔 We can do it like that for now, but in the future, I feel like actually showing helpful advice directly (without having to navigate to the website) would be an important UX improvement. I really like the way you improved the project detection error message for example.

@arcanis arcanis mentioned this pull request Mar 31, 2022
3 tasks
@arcanis arcanis force-pushed the mael/check-resolutions branch from 675e552 to 8ce30d9 Compare March 31, 2022 16:06
@arcanis arcanis merged commit 1d85482 into master Mar 31, 2022
@arcanis arcanis deleted the mael/check-resolutions branch March 31, 2022 18:17
@arcanis arcanis mentioned this pull request Mar 31, 2022
13 tasks
@leotm
Copy link

leotm commented Jun 14, 2022

appreciate this PR @arcanis 👍 handy when upgrading

noticed v4's flagging old (v3) set resolutions Invalid (thx @paul-soporan for mentioning)

if legit (not false positives), fixing one by one may take a while
(reverting to v3, reverting old res commit, reverting to v4, check, repeat fix)

got a repro here, its a yarn install blocker on ubuntu but not on macOS

just read b34398a, lemme know if i've done smth strange, if a bug happy to raise the issue

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.

4 participants