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

fix: [security] Replace colors with chalk. #166

Open
wants to merge 1 commit into
base: v0.4.0
Choose a base branch
from

Conversation

jwalton
Copy link

@jwalton jwalton commented Jan 9, 2022

Description

This replaces the colors library with chalk after the author of colors added an infinite loop to colors/lib/index.js as a protest.

cli-table is actually already safe, because it had colors.js pinned to an old version, but I'm doing my best to remove the author's code from popular packages because it makes it easier to audit my toolchain.

Checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally (or has an appropriate fallback).
  • This change has relevant unit tests.
  • This change has relevant documentation additions / updates (if applicable).

Steps to Test or Reproduce

Existing color test cases are passing.

@Andrew-Hopkins-Liqua
Copy link

Andrew-Hopkins-Liqua commented Jan 10, 2022

+1

The maintainer of the colors package has purposely deployed a corrupted breaking change in protest of not getting funding.
This has caused cli-table to print an infinite amount of garbage output, and not work correctly.

https://snyk.io/blog/open-source-maintainer-pulls-the-plug-on-npm-packages-colors-and-faker-now-what/
Marak/colors.js#285

This issue has run-on effects with Firebase-tools (which uses cli-tables as a dependancy)
firebase/firebase-tools#3999

And with github actions firebase-hosting-deploy ( which uses firebase-tools as a dependancy )
FirebaseExtended/action-hosting-deploy#188

See image below ( garbage output from dependancy "colors" )
image

@@ -11,7 +11,7 @@
},
"keywords": ["cli", "colors", "table"],
"dependencies": {
"colors": "1.0.3"
"chalk": "^4.1.2"

Choose a reason for hiding this comment

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

Why not pin the chalk version, just in case

Copy link
Author

Choose a reason for hiding this comment

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

Pinning in a library is generally a bad idea (present circumstances excluded). If we pinned this to chalk 4.1.2, and a bug fix came out in 4.1.3, we’d have to merge a patch to this library and then all consumers of this library would have to upgrade this and chalk. A critical security vulnerability could take a long time to propagate its way down the dependency tree.

It also means if you have this dependency pinned at 4.1.2, and you use some other library that pins it at 4.1.1, then you needlessly end up with two copies of chalk in your node_modules.

Of course, if you’re consuming cli-table in an application, you absolutely should pin this dependency via a package-lock.json or yarn.lock.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see pinning as an interim solution.
Moving to a new package requires planning and testing, and in the meanwhile pinning the dependency to a specific, non-broken version can be a good idea. I think that will be our plan here.

Copy link
Member

Choose a reason for hiding this comment

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

It's true that pinning can slow down deployments of fixes in scenarios like this (installed software like a CLI), but it also protects against these things just as much. As evidenced here, package maintainers can be unstable, or accounts can get compromised. If things had been fully pinned, we wouldn't be scrambling to address the issue from colors.

Copy link
Author

Choose a reason for hiding this comment

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

If you have a lockfile, you’re not scrambling to fix anything related to colors. Only new installs should be affected by the mess with colors.

(As an aside, If you’re curious to know what kind of a world we’d be living in if libraries pinned all their dependencies in package.json directly, I’d invite you to have a look at this PR. Not quite this exact scenario, but this is the sort of thing we’d all be doing on a regular basis:

webpack-contrib/css-loader#472)

Choose a reason for hiding this comment

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

Will we have the merge of this PR?
In our projects we are using the cli-table. Otherwise, we will have to change it here.
Can we proceed with this PR?

@sjinks sjinks added the Needs Review Submitted for Review label Jan 10, 2022
draperunner added a commit to draperunner/ditched that referenced this pull request Jan 10, 2022
The maintainer of colors has purposely introduced an infinite loop
in the latest version of colors. Therefore we need to ditch this
dependency.

cli-table must also be updated in order to get rid of the colors
dependency entirely. There is a PR:
Automattic/cli-table#166
Or maybe an alternative table lib should be considered as well?
@DABH
Copy link

DABH commented Feb 19, 2022

Hey folks -- I'm grateful the community has been proactive here :) I opened #169 which allows cli-table to stay with colors but uses the new fork which is securely maintained and updated. It may be easier to just use that PR than migrate to chalk. chalk is a somewhat heaver library and it's a bigger migration, so I would argue sticking with @colors/colors may be better, but I will leave it to the maintainers. Thanks, and please lmk if you have any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review Submitted for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants