run npm audit fix to fix them, or npm audit for details
npm
升级到 @6
以后, 在项目中更新或者下载新的依赖包, 控制台会自动运行 npm audit
, 对项目依赖包进行安全审核,并生成漏洞报告在控制台中显示:
added 1864 packages from 947 contributors and audited 29947 packages in 218.903s
found 395 vulnerabilities (350 low, 42 moderate, 3 high)run `npm audit fix` to fix them, or `npm audit` for details
我们可以通过漏洞报告的提示信息来修补程序漏洞:
# 执行 npm audit fix
# 此命令将自动更新有安全漏洞的依赖项
npm audit fix
# 运行结果
# 加载了30个依赖包
# 删除了7个依赖包
# 更新了38个依赖包
# 移动了1个依赖包
# 修正了29947个扫描包中395个漏洞中的298个
+ babel-plugin-transform-es2015-modules-commonjs@6.26.2
+ babel-plugin-dynamic-import-node@1.2.0
+ express@4.16.3
+ antd@3.6.3
+ babel-cli@6.26.0
+ babel-preset-env@1.7.0
+ babel-core@6.26.3
+ compression@1.7.2
+ lodash@4.17.10
added 30 packages from 49 contributors, removed 7 packages, updated 38 packages and moved 1 package in 29.292s
fixed 298 of 395 vulnerabilities in 29947 scanned packages7 package updates for 97 vulns involved breaking changes(use `npm audit fix --force` to install breaking changes; or do it by hand)
通过提示系统自动修补了大部分漏洞, 那剩下的怎么办呢?
# 继续执行控制台给的提示命令
npm audit fix --force
# 运行结果
# 加载了33依赖包
# 删除了17个依赖包
# 更新了8个依赖包
# 修正了29771个扫描包中16个漏洞
added 33 packages from 68 contributors, removed 17 packages and updated 8 packages in 171.584s
fixed 16 of 16 vulnerabilities in 29771 scanned packages4 package updates for 14 vulns involved breaking changes(installed due to `--force` option)
目前为止我们执行了2个命令来修复漏洞, 那手动执行 npm audit
看看目前依赖包还有什么问题;
...
...
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate│ Memory Exposure│
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ tunnel-agent │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in│ >=0.6.0│
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ image-webpack-loader [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path│ image-webpack-loader > imagemin-webp > cwebp-bin > │
│ │ bin-wrapper > download > caw > tunnel-agent│
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/598 │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 9 moderate severity vulnerabilities in 32545 scanned packages9 vulnerabilities require manual review. See the full report for details.
# 在32545个扫描包中发现了9个中度严重缺陷
# 漏洞需要手动检查. 详情请参阅完整报告.
上面详细信息表述了 tunnel-agent
出现的问题,并且 指出了依赖路径
image-webpack-loader > imagemin-webp > cwebp-bin >bin-wrapper > download > caw > tunnel-agent
访问提示链接https://nodesecurity.io/advisories/598
里面给出了解决方案
Remediation
tunnel-agent Update to version 0.6.0 or later.
结语
现在安全问题是不容忽视的, npm
安装的依赖包错中复杂. 往往安装一个包, 会自动安装一大堆相关联的依赖包, 这个时候开发者是不易察觉的; 就算开发者有安全意识, 但是也缺乏解决安全漏洞的手段. npm@6
自带的 npm audit
也是帮助开发者解决基本的安全漏洞问题; 但是最终希望的是 npm
能不能瘦瘦身!