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 SNYK-JS-ANSIREGEX-1583908 and move to ESM #4748

Closed
rafaelmaeuer opened this issue Sep 14, 2021 · 10 comments
Closed

Fix SNYK-JS-ANSIREGEX-1583908 and move to ESM #4748

rafaelmaeuer opened this issue Sep 14, 2021 · 10 comments
Labels
dependencies Pull requests that update a dependency file type: chore generally involving deps, tooling, configuration, etc.

Comments

@rafaelmaeuer
Copy link

Is your feature request related to a problem or a nice-to-have?? Please describe.

As of https://snyk.io/vuln/SNYK-JS-ANSIREGEX-1583908 my investigations lead to mocha referencing the vulnerability by peer dependencies of "wide-align": "v1.1.3" -> "string-width": "^1.0.2 || 2" -> "strip-ansi": "^4.0.0" -> "ansi-regex": "^3.0.0".

Describe the solution you'd like

Forcing @iarna to accept iarna/wide-align#57 from @jimmywarting will update "string-width": "^5.0.1" resulting in a fix of https://snyk.io/vuln/SNYK-JS-ANSIREGEX-1583908 with peer-dependencies "strip-ansi": "^7.0.1" -> "ansi-regex": "^6.0.1". It will require some changes towards ESM on mocha-side too:

const align = require('wide-align');

Describe alternatives you've considered

Alternatively the use of @jimmywarting branch https://github.com/jimmywarting/wide-align/tree/esm as dependency, or investigation of a replacement for string-width are thinkable.

@juergba
Copy link
Contributor

juergba commented Sep 14, 2021

We get security issues like this one on a regular basis.

  • please add a PoC explaining how this ReDoS is supposed to affect Mocha. Is there a masked tester attacking himself? How will he/she accomplish this attack? Which server/services are endangered?
  • [...] move to ESM: no, we won't move to ESM for now. Certainly not based on a security message like this.

@juergba juergba added status: waiting for author waiting on response from OP - more information needed and removed type: feature enhancement proposal labels Sep 14, 2021
@jimmywarting
Copy link

jimmywarting commented Sep 14, 2021

I have used a simpler variant in one other project of mine (note that it dose not take into consideration the characters width)
Feel free to take, copy use it if you like

export function alignLeft(str, width) {
    return String(str).slice(0, width).padEnd(width)
}
export function alignRight(str, width) {
    return String(str).slice(0, width).padStart(width)
}
export function alignCenter(str, width) {
    const internalString = String(str)
    const leftPadding = Math.floor((width - internalString.length) / 2) + internalString.length
    return internalString.padStart(leftPadding).padEnd(width).slice(0, width)
}

@jimmywarting
Copy link

jimmywarting commented Sep 14, 2021

honestly, now when i looked at what you used wide-align for in the one-and-done (which is the only place)
where it only use align left and dumps something out in the console.log

console.log(
` ${align.left(key, maxKeyLength + 1)}${
description ? `- ${description}` : ''
}`
);

then i don't think the wide-align package (and 4 other dependencies) is worth keeping around to solve one such tiny thing. it don't justify the only tiny thing you use it for.
there are other decent ways to present it into the log with 0 dependencies.

i say: remove the wide-align dependency (and don't replace it with something else)
find other ways to dump it nicely to the log, there are also console.table, console.group

@iarna
Copy link

iarna commented Sep 14, 2021

I don't have an opinion here as to if you should use wide-align but I will note that it doesn't do the same thing as the code @jimmywarting posted above -- the whole point of wide-align is that it can do console alignment of wide/double-width/full-width characters (eg, characters that display using two cells instead of one), something that anything using padStart/padEnd (or string.length) is gonna fail at. If wide characters are not a concern, then there's no point in using the module. If they are important, then you need either wide-align or another module that implements the same logic.

@juergba
Copy link
Contributor

juergba commented Sep 17, 2021

@dhuang612 are you interested in removing dependency wide-align and replacing it with alignLeft() shown above?
If yes, go ahead and open a PR, please use npm v6 to rebuild package-lock.json.

@dhuang612
Copy link

Hi,
Was I tagged by mistake?

@juergba
Copy link
Contributor

juergba commented Sep 17, 2021

No

@dhuang612
Copy link

Sure, I can try to work on this

@juergba
Copy link
Contributor

juergba commented Sep 22, 2021

@dhuang612 I will publish a new release this weekend, probably.
I would take over this one, unless your PR is ready within the next days. Thanks.

@dhuang612
Copy link

I am really busy over this next week and wouldn't have time to get to it before October.

@juergba juergba added type: chore generally involving deps, tooling, configuration, etc. dependencies Pull requests that update a dependency file and removed status: waiting for author waiting on response from OP - more information needed labels Sep 24, 2021
@juergba juergba closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file type: chore generally involving deps, tooling, configuration, etc.
Projects
None yet
Development

No branches or pull requests

5 participants