🌊
npm audit fixでは解決できなかった脆弱性の修正
前提
利用しているライブラリの中に脆弱性のあるものがあるらしい。
Upgrade pug to version 3.0.1 とあるので pug というライブラリが古いと思われる。
$ npm audit
                                                                                
                       === npm audit security report ===                        
                                                                                
┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Remote Code Execution                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ pug                                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.0.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ storybook-addon-vue-info [dev]                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ storybook-addon-vue-info > vue-docgen-api > pug              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1643                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 1 high severity vulnerability in 3839 scanned packages
 npm audit fix を試す
試したが
$ npm audit fix --force
...
up to date in 12.319s
227 packages are looking for funding
  run `npm fund` for details
fixed 0 of 1 vulnerabilities in 3839 scanned packages
  1 vulnerabilities required manual review and could not be updated
なぜかFixされない。
修正方法
- 
npm ls pugでどのライブラリによる依存なのか調べる。
 $ npm ls pug
my-app@1.0.0 <path-to-project>
├─┬ @storybook/vue@6.1.21
│ └─┬ vue-docgen-api@4.36.1
│   └── pug@3.0.2  deduped
├── pug@3.0.2 
└─┬ storybook-addon-vue-info@1.4.2
  └─┬ vue-docgen-api@3.26.0
    └── pug@2.0.4 
storybook-addon-vue-info -> vue-docgen-api -> pug が古いと思われる。
- 
package-lock.jsonの中を書き換える。
 ^2.0.3->^3.0.2.
{
  "name": "my-app",
  ...
  "dependencies": {
    "storybook-addon-vue-info": {
      ...
      "dependencies": {
        ...
        "vue-docgen-api": {
	  ...
          "requires": {
            ...
            "pug": "^2.0.3", <-- ここ
	    ...
          }
        }
      }
    }
  }
}
- 
node_modulesを削除する。
- 
npm installで再インストールする。
結果
$ npm audit
                                                                                
                       === npm audit security report ===                        
                                                                                
found 0 vulnerabilities
 in 3820 scanned packages





Discussion