Page MenuHomePhabricator

libup possible has issues with npm audit to get all vulnerability removed
Open, Needs TriagePublic

Description

https://libraryupgrader2.wmcloud.org/logs2/268222

Attempting to npm audit fix
$ npm audit fix --only=dev

> core-js@3.10.1 postinstall /src/repo/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

added 599 packages from 342 contributors in 14.206s

70 packages are looking for funding
  run `npm fund` for details

fixed 55 of 56 vulnerabilities in 599 scanned packages
  1 vulnerability required manual review and could not be updated

It says there is still one issue. But when running it locally again it shows to me:

# npm audit

                       === npm audit security report ===

# Run  npm update hosted-git-info --depth 7  to resolve 1 vulnerability

  Moderate        Regular Expression Denial of Service

  Package         hosted-git-info

  Dependency of   stylelint-config-wikimedia [dev]

  Path            stylelint-config-wikimedia > stylelint > meow > read-pkg-up
                  > read-pkg > normalize-package-data > hosted-git-info

  More info       https://npmjs.com/advisories/1677



found 1 moderate severity vulnerability in 599 scanned packages
  run `npm audit fix` to fix 1 of them.

# npm audit fix
updated 1 package in 3s

65 packages are looking for funding
  run `npm fund` for details

fixed 1 of 1 vulnerability in 599 scanned packages

# npm audit

                       === npm audit security report ===

found 0 vulnerabilities
 in 599 scanned packages

That looks like an issue with npm audit not doing all possible fixes.
In this package-lock.json the package hosted-git-info is with version 3.0.7 => 3.0.8 (directly) and 2.8.9 => 2.8.9 as dependency of read-pkg

When looking at other extensions with stylelint-config-wikimedia there is the same problem.

Event Timeline

The only thing I can think of is what we're running a different npm version? We're currently on 6.14.5. Latest 6.x is 6.14.13.

On AbuseFilter is now twiced updated for hosted-git-info possible by this problem

I have updated to 6.14.13 locally and it is still an issue

After checking out https://gerrit.wikimedia.org/r/c/mediawiki/extensions/AbuseFilter/+/686753 npm audit says I still have an issue:

km@9683552ac492:/AbuseFilter$ npm audit
                                                                                
                       === npm audit security report ===                        
                                                                                
# Run  npm update hosted-git-info --depth 7  to resolve 1 vulnerability
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hosted-git-info                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ stylelint-config-wikimedia [dev]                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ stylelint-config-wikimedia > stylelint > meow > read-pkg-up  │
│               │ > read-pkg > normalize-package-data > hosted-git-info        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1677                            │
└───────────────┴──────────────────────────────────────────────────────────────┘


found 1 moderate severity vulnerability in 864 scanned packages
  run `npm audit fix` to fix 1 of them.

Also I found https://github.com/npm/hosted-git-info/pull/84#issuecomment-833756049 which suggests that yesterday, npm didn't think 2.8.9 was safe to upgrade to.

@Umherirrender Should we just run npm audit fix --only=dev in a loop like 2 or 3 times? I don't fully understand what's going wrong here.

I have no idea how to handle this at best. The loop would be a workaround, but that sounds okay. Is npm audit giving an return code when there is still something to fix? But also without it calling it twice would be okay.

Change 686797 had a related patch set uploaded (by Legoktm; author: Legoktm):

[labs/libraryupgrader@master] Run `npm audit fix` 3 times to pick up more fixes

https://gerrit.wikimedia.org/r/686797

Change 686797 merged by jenkins-bot:

[labs/libraryupgrader@master] Run `npm audit fix` 3 times to pick up more fixes

https://gerrit.wikimedia.org/r/686797

Is npm audit giving an return code when there is still something to fix?

npm audit yes, npm audit fix, no.

Fingers crossed that 3 times is the charm.