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

Update pnpm to v9.15.0 [SECURITY] #40560

Merged
merged 5 commits into from
Dec 20, 2024
Merged

Conversation

matticbot
Copy link
Contributor

This PR contains the following updates:

Package Type Update Change
pnpm (source) packageManager minor 9.3.0 -> 9.15.0
pnpm (source) engines minor ^9.3.0 <9.12.0 -> ^9.15.0 <9.15.1

pnpm no-script global cache poisoning via overrides / ignore-scripts evasion

CVE-2024-53866 / GHSA-vm32-9rqf-rh3r

More information

Details

Summary

pnpm seems to mishandle overrides and global cache:

  1. Overrides from one workspace leak into npm metadata saved in global cache
  2. npm metadata from global cache affects other workspaces
  3. installs by default don't revalidate the data (including on first lockfile generation)

This can make workspace A (even running with ignore-scripts=true) posion global cache and execute scripts in workspace B

Users generally expect ignore-scripts to be sufficient to prevent immediate code execution on install (e.g. when the tree is just repacked/bundled without executing it).

Here, that expectation is broken

Details

See PoC.

In it, overrides from a single run of A get leaked into e.g. ~/Library/Caches/pnpm/metadata/registry.npmjs.org/rimraf.json and persistently affect all other projects using the cache

PoC

Postinstall code used in PoC is benign and can be inspected in https://www.npmjs.com/package/ponyhooves?activeTab=code, it's just a console.log

  1. Remove store and cache
    On mac: rm -rf ~/Library/Caches/pnpm ~/Library/pnpm/store
    This step is not required in general, but we'll be using a popular package for PoC that's likely cached
  2. Create A/package.json:
    {
      "name": "A",
      "pnpm": { "overrides": { "rimraf>glob": "npm:ponyhooves@1" } },
      "dependencies": { "rimraf": "6.0.1" }
    }
    Install it with pnpm i --ignore-scripts (the flag is not required, but the point of the demo is to show that it doesn't help)
  3. Create B/package.json:
    {
      "name": "B",
      "dependencies": { "rimraf": "6.0.1" }
    }
    Install it with pnpm i

Result:

Packages: +3
+++
Progress: resolved 3, reused 3, downloaded 0, added 3, done
node_modules/.pnpm/[email protected]/node_modules/ponyhooves: Running postinstall script, done in 51ms

dependencies:
+ rimraf 6.0.1

Done in 1.4s

Also, that code got leaked into another project and it's lockfile now!

Impact

Global state integrity is lost via operations that one would expect to be secure, enabling subsequently running arbitrary code execution on installs

As a work-around, use separate cache and store dirs in each workspace

Severity

  • CVSS Score: Unknown
  • Vector String: CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:P/VC:N/VI:L/VA:N/SC:H/SI:H/SA:H

References

This data is provided by OSV and the GitHub Advisory Database (CC-BY 4.0).


Release Notes

pnpm/pnpm (pnpm)

v9.15.0: pnpm 9.15

Compare Source

Minor Changes
  • Metadata directory version bumped to force fresh cache after we shipped a fix to the metadata write function. This change is backward compatible as install doesn't require a metadata cache.
Patch Changes
  • pnpm update --global should not crash if there are no any global packages installed #​7898.
  • Fix an exception when running pnpm update --interactive if catalogs are used.
Platinum Sponsors
Bit Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me

v9.14.4: pnpm 9.14.4

Compare Source

Patch Changes
  • Don't ever save mutated metadata to the metadata cache.
Platinum Sponsors
Bit Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me
Silver Sponsors
Leniolabs_ Vercel
Depot moonrepo
devowl.io Cerbos
vlt Vite

v9.14.3: pnpm 9.14.3

Compare Source

Patch Changes
  • Some commands should ignore the packageManager field check of package.json #​7959.
Platinum Sponsors
Bit Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me
Silver Sponsors
Leniolabs_ Vercel
Depot moonrepo
devowl.io Cerbos
vlt Vite

v9.14.2

Compare Source

Patch Changes
  • pnpm publish --json should work #​8788.
Platinum Sponsors
Bit Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me

v9.14.1

Compare Source

Minor Changes
  • Added support for pnpm pack --json to print packed tarball and contents in JSON format #​8765.
Patch Changes
  • pnpm exec should print a meaningful error message when no command is provided #​8752.
  • pnpm setup should remove the CLI from the target location before moving the new binary #​8173.
  • Fix ERR_PNPM_TARBALL_EXTRACT error while installing a dependency from GitHub having a slash in branch name #​7697.
  • Don't crash if the use-node-version setting is used and the system has no Node.js installed #​8769.
  • Convert settings in local .npmrc files to their correct types. For instance, child-concurrency should be a number, not a string #​5075.
  • pnpm should fail if a project requires a different package manager even if manage-package-manager-versions is set to true.
  • pnpm init should respect the --dir option #​8768.
Platinum Sponsors
Bit Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me

v9.14.0

Compare Source

v9.13.2: pnpm 9.13.2

Compare Source

Patch Changes
  • Detection of circular peer dependencies should not crash with aliased dependencies #​8759. Fixes a regression introduced in the previous version.
  • Fix race condition of symlink creations caused by multiple parallel dlx processes.
Platinum Sponsors
Bit Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me
Silver Sponsors
Leniolabs_ Vercel
Depot moonrepo
devowl.io Cerbos
vlt Vite

v9.13.1: pnpm 9.13.1

Compare Source

Patch Changes
  • Fixed some edge cases where resolving circular peer dependencies caused a dead lock #​8720.
Platinum Sponsors
Bit Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me
Silver Sponsors
Leniolabs_ Vercel
Depot moonrepo
devowl.io Cerbos
vlt Vite

v9.13.0: pnpm 9.13

Compare Source

Minor Changes
  • The self-update now accepts a version specifier to install a specific version of pnpm. E.g.:

    pnpm self-update 9.5.0
    

    or

    pnpm self-update next-10
    
Patch Changes
  • Fix Cannot read properties of undefined (reading 'name') that is printed while trying to render the missing peer dependencies warning message #​8538.
Platinum Sponsors
Bit Figma
Gold Sponsors
Discord Prisma
u|screen JetBrains
Nx CodeRabbit
Route4Me
Silver Sponsors
Leniolabs_ Renovate Bot.

@matticbot matticbot added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Type] Janitorial labels Dec 11, 2024
@matticbot
Copy link
Contributor Author

⚠️ Artifact update problem

Renovate failed to update an artifact related to this branch. You probably do not want to merge this PR as-is.

♻ Renovate will retry this branch, including artifacts, only when one of the following happens:

  • any of the package files in this branch needs updating, or
  • the branch becomes conflicted, or
  • you click the rebase/retry checkbox if found above, or
  • you rename this PR's title to start with "rebase!" to trigger it manually

The artifact failure details are included below:

File name: undefined
Command failed: /tmp/monorepo/.github/files/renovate-post-upgrade-run.sh renovate/npm-pnpm-vulnerability

@matticbot matticbot force-pushed the renovate/npm-pnpm-vulnerability branch from 07ab4b0 to c5aafa8 Compare December 11, 2024 16:11
@matticbot matticbot force-pushed the renovate/npm-pnpm-vulnerability branch from c5aafa8 to 116b05d Compare December 12, 2024 06:11
Copy link
Contributor

github-actions bot commented Dec 12, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the renovate/npm-pnpm-vulnerability branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack renovate/npm-pnpm-vulnerability
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin renovate/npm-pnpm-vulnerability
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@matticbot
Copy link
Contributor Author

Edited/Blocked Notification

Renovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR.

You can manually request rebase by checking the rebase/retry box above.

⚠️ Warning: custom changes will be lost.

@robertsreberski robertsreberski requested a review from a team December 20, 2024 13:41
@anomiex
Copy link
Contributor

anomiex commented Dec 20, 2024

Sorry, I've been somewhat ignoring this because I don't see that CVE-2024-53866 was affecting us and I'll probably have to resurrect the workaround for pnpm/pnpm#3935 since it was regressed in 9.12.0.

@robertsreberski
Copy link
Contributor

Thanks for explaining! Why is it not affecting us, if I may ask?

@anomiex
Copy link
Contributor

anomiex commented Dec 20, 2024

We're not using overrides anywhere.

@tbradsha
Copy link
Contributor

We're not using overrides anywhere.

Though if I'm reading the issue correctly, should a different repo use malicious overrides, it could affect the monorepo when running pnpm install, right?

@anomiex
Copy link
Contributor

anomiex commented Dec 20, 2024

Hmm, maybe.

@anomiex anomiex merged commit b414852 into trunk Dec 20, 2024
76 checks passed
@anomiex anomiex deleted the renovate/npm-pnpm-vulnerability branch December 20, 2024 15:25
@github-actions github-actions bot removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants