关于 npm audit fix

run npm audit fix to fix them, or npm audit for details

  • npm audit : npm@5.10.0 & npm@6,允许开发人员分析复杂的代码,并查明特定的漏洞和缺陷。
  • npm audit fix :npm@6.1.0,  检测项目依赖中的漏洞并自动安装需要更新的有漏洞的依赖,而不必再自己进行跟踪和修复。

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 packages
  7 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 packages
  4 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 packages
  9 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 能不能瘦瘦身!

参考

About security audits #https://docs.npmjs.com/getting-started/running-a-security-audit

about-audit-reports #https://docs.npmjs.com/getting-started/about-audit-reports

掘金: https://juejin.im/post/5b2a19e351882574e40e8dd5

CSDN: https://blog.csdn.net/weixin_40817115/article/details/81007774?utm_source=blogxgwz2

 

转载于:https://my.oschina.net/jamesview/blog/2963067

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值