2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

npm install したときに、high severity vulnerabilitiesの対応備忘

Posted at

概要

npm install したときに、high severity vulnerabilitiesが発生

npm audit fixで解消せず

npm-force-resolutionsを活用して解決を目指す

> npm install

...

10 high severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

原因

とあるパッケージの依存関係にあるパッケージが古いバージョンやなんらかの原因により、脆弱性があると判断されている様子

一般的な対応

npm audit fix
or
npm audit fix --force

で対応可能らしい

今回のケースでは上記のコマンドで対応不可だったので
詳しく調べてみる

対応

何が起こっているか確認する

npm auditを試す

> npm audit
# npm audit report

glob-parent  <5.1.2
Severity: high
glob-parent before 5.1.2 vulnerable to Regular Expression Denial of Service in enclosure regex - https://github.com/advisories/GHSA-ww39-953v-wcq6
No fix available
node_modules/babel-cli/node_modules/glob-parent
node_modules/glob-base/node_modules/glob-parent
  chokidar  1.0.0-rc1 - 2.1.8
  Depends on vulnerable versions of anymatch
  Depends on vulnerable versions of glob-parent
  node_modules/babel-cli/node_modules/chokidar
    babel-cli  *
    Depends on vulnerable versions of babel-register
    Depends on vulnerable versions of chokidar
    node_modules/babel-cli
  glob-base  *
  Depends on vulnerable versions of glob-parent
  node_modules/glob-base
    parse-glob  >=2.1.0
    Depends on vulnerable versions of glob-base
    node_modules/parse-glob
      micromatch  1.6.2 - 2.3.11
      Depends on vulnerable versions of parse-glob
      node_modules/babel-cli/node_modules/micromatch
        anymatch  1.2.0 - 1.3.2
        Depends on vulnerable versions of micromatch
        node_modules/babel-cli/node_modules/anymatch

glob-parent5.1.2未満は脆弱性があるようで、これが原因になっている様子

現在の状態を確認

npm lsで確認してみる

 npm ls glob-parent
app@0.1.0 ...
├─┬ babel-cli@6.26.0
│ └─┬ chokidar@1.7.0
│   ├─┬ anymatch@1.3.2
│   │ └─┬ micromatch@2.3.11
│   │   └─┬ parse-glob@3.0.4
│   │     └─┬ glob-base@0.3.0
│   │       └── glob-parent@2.0.0
│   └── glob-parent@2.0.0
└─┬ webpack-dev-server@4.15.1
  └─┬ chokidar@3.5.3
    └── glob-parent@5.1.2

glob-parent@2.0.0が解消されれば良さそうと見立てる

解決方法

npm-force-resolutionsを使います

> npm i npm-force-resolutions

`package.json'にどこまでバージョンを上げるか書き加えます
今回は5.1.2まで上げてみます

package.json
"resolutions": {
    "glob-parent": "^5.1.2"
  }

実行します

> npx npm-force-resolutions

clean install します

npm ci
...

found 0 vulnerabilities

脆弱性はなさそうですね

最後に

無事バージョンを上げることが出来、脆弱性は解消できました
改めて'npm ls'にてバージョンを確認したところpackage.lock.json的には違和感の残る結果の様でした

また今後、別の方法も模索出来ればと...

> npm ls glob-parent

app@0.1.0 ...
├─┬ babel-cli@6.26.0
│ └─┬ chokidar@1.7.0
│   ├─┬ anymatch@1.3.2
│   │ └─┬ micromatch@2.3.11
│   │   └─┬ parse-glob@3.0.4
│   │     └─┬ glob-base@0.3.0
│   │       └── glob-parent@^5.1.2 invalid: "^2.0.0" from node_modules/glob-base
│   └── glob-parent@^5.1.2 invalid: "^2.0.0" from node_modules/babel-cli/node_modules/chokidar
└─┬ webpack-dev-server@4.15.1
  └─┬ chokidar@3.5.3
    └── glob-parent@^5.1.2 invalid: "~5.1.2" from node_modules/chokidar
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?