關於 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, 對項目依賴包進行安全審覈,並生成漏洞報告在控制檯中顯示:node

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

咱們能夠經過漏洞報告的提示信息來修補程序漏洞:webpack

# 執行 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)

經過提示系統自動修補了大部分漏洞, 那剩下的怎麼辦呢?web

# 繼續執行控制檯給的提示命令
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 看看目前依賴包還有什麼問題;express

...
...
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ 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 出現的問題,而且 指出了依賴路徑npm

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 能不能瘦瘦身!babel

參考

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

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

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

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

相關文章
相關標籤/搜索