msw icon indicating copy to clipboard operation
msw copied to clipboard

vuln: cookie package

Open jamescrowley opened this issue 1 year ago • 6 comments

Prerequisites

Environment check

  • [X] I'm using the latest msw version
  • [X] I'm using Node.js version 18 or higher

Browsers

No response

Reproduction repository

https://github.com/boxwise/boxtribute

Reproduction steps

The latest msw release (<= 2.4.9) has a transient dependency on several versions of the cookie library that are < 7.0.0, which has a vulnerability (https://github.com/advisories/GHSA-pxg6-pf52-xh8x).

Current behavior

You are referencing it via

  • @bundled-es-modules/[email protected] which has not been updated (wrapper appears stale - may be possible to just reference cookie directly now?)
  • [email protected], which has an open PR to fix: https://github.com/socketio/socket.io/pull/5205

While it's unlikely to impact msw given your use-case, it will force the dependency to a lower version for others that use it in production-facing code.

Expected behavior

No security warnings

jamescrowley avatar Oct 09 '24 03:10 jamescrowley

Hi, @jamescrowley. Thanks for raising this.

So the issue is that @bundled-es-modules/cookie hasn't updated the cookie version in a while.

wrapper appears stale - may be possible to just reference cookie directly now?

Does it finally ship as proper ESM? I will have to take a look, it would be great to drop the wrapper if that's the case.

kettanaito avatar Oct 09 '24 09:10 kettanaito

@kettanaito they've decided to remain CJS only, but it appears to work fine with your set up.

I just did a quick PoC here, removing the bundled es module. Appears to lint & build fine (but haven't checked further than that)

I only upgraded to 0.7.2 as 1.0.0 has a breaking signature change.

jamescrowley avatar Oct 09 '24 11:10 jamescrowley

Thanks! I gave it a try in #2321, and it looks good so far. Will wait for the CI results and then proceed with publishing it.

kettanaito avatar Oct 10 '24 17:10 kettanaito

Yeah, so cookie being CJS-only breaks our ESM consumers (ref). We cannot use it as-is, it has to be ESM. I will open a PR against @bundled-es-modules to bump the cookie version instead.

The effort already exists: https://github.com/bundled-es-modules/cookie/pull/3

kettanaito avatar Oct 10 '24 17:10 kettanaito

Hi, 👋

Thanks for the hard work on the fix! 🙏

Will the cookie vulnerability also be fixed in msw v1?

I couldn't find any information on the backporting policy. Apologies if this is not the right place to ask.

Thanks again!

domon-envato avatar Oct 14 '24 06:10 domon-envato

Hi, @domon-envato. This is absolutely the right place to ask.

We support the backports for security vulnerabilities based on the time availability. We are also welcoming contributors to open pull requests to ship those backports, if the matter is time-pressing.

MSW v1 doesn't depend on @bundled-es-modules/cookie but on cookie instead. If that's a non-breaking version bump (which, I hope it is on their side), provisioning a backport shouldn't be a problem.

Backports also release automatically to NPM as soon as they are merged under the backport tag.

I need to add a decision document about backports 👍

Would you be interesting in seeing this one through? I will share a more detailed instruction in the decision document later today, hopefully.

kettanaito avatar Oct 14 '24 09:10 kettanaito

Hello, what is the status of this? thank you

TannerS avatar Oct 28 '24 18:10 TannerS

@TannerS, you can find the latest status on the PR, always: https://github.com/mswjs/msw/pull/2312#issuecomment-2408907675. Looks like we are blocked by the dependency where the fix has been merged but wasn't yet released. I tried moving this in-house but don't have the capacity right now (and that's likely not a good idea anyway). The sad reality of not publishing ESM in 2024.

kettanaito avatar Oct 28 '24 19:10 kettanaito

Thanks for the update, i am still learning but interested in understanding what you mean by The sad reality of not publishing ESM in 2024.?

:D

TannerS avatar Oct 30 '24 13:10 TannerS

Could it make sense to consider swapping from cooke (and thus @bundled-es-modules/cookie) to something like https://github.com/unjs/cookie-es ? It has the advantage of being maintained by the larger unjs org

Pewtro avatar Nov 04 '24 09:11 Pewtro

At this point, its what like 5 functions and maybe 100 lines of code? I would just make it native to msw and cut the dependency. The updation lag time of this with a CVE is not good. Node itself is moving faster.

curtdept avatar Nov 05 '24 23:11 curtdept

2.0.1 of @bundled-es-modules/cookie has been released, so people can run npm audit fix or similiar commands to update their package-lock files to resolve this vulnerability (if they don't want to manually update it).

Pewtro avatar Nov 07 '24 08:11 Pewtro

@curtdept, I wouldn't replicate packages, especially those that are getting CVE reports. The issue is not in cookie. The issue is in how it's distributed and how we expect to rely on it in MSW.

I've got some good feedback from the Node.js folks behind cookie. Will explore how to improve this dependency chain in the future.

kettanaito avatar Nov 07 '24 12:11 kettanaito

Released: v2.6.2 🎉

This has been released in v2.6.2!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

kettanaito avatar Nov 07 '24 12:11 kettanaito

Does it finally ship as proper ESM? I will have to take a look, it would be great to drop the wrapper if that's the case.

Would you consider dropping it for a different package? https://github.com/unjs/cookie-es

This is a fork that has been maintained for several years, has ~1 million weekly downloads vs the wrappers ~2 million.

Unfortunately the jshttp/cookie seems to be in a committed exclusive relationship with cjs. Found it in here: https://github.com/jshttp/cookie/issues/152#issuecomment-2390659837

SamMousa avatar Nov 14 '24 16:11 SamMousa

Would you consider dropping it for a different package? https://github.com/unjs/cookie-es

@kettanaito As a rebuttal, in a way, the issue is cookie because it requires this heavily lagged, generated wrapper due to lack of esm support.

The above seems to be a worthy maintained alternative.

curtdept avatar Nov 14 '24 16:11 curtdept

Sounds good to me. Pull requests are welcome!

kettanaito avatar Nov 17 '24 10:11 kettanaito