简体   繁体   English

使用“npm 审计”时如何只检查高漏洞?

[英]How to check for only high vulnerabilities when using “npm audit”?

When you I execute npm install using new npm 6 i got a messages that tell me I have some vulnerabilities :当我使用新的npm 6执行npm install我收到一条消息,告诉我我有一些漏洞

[!] 75 vulnerabilities found [4867 packages audited] [!] 发现 75 个漏洞 [审核了 4867 个包]

Severity: 66 Low |严重性:66 低 | 4 Moderate | 4 中等 | 5 High 5 高

Run npm audit for more detail运行npm audit以获取更多详细信息

I ran npm audit but got a truncated list of vulnerabilities.我运行了npm audit但得到了一个截断的漏洞列表。

How I can check for only High vulnerabilities list ?我如何只检查漏洞列表?

Thanks谢谢

不是您正在寻找的答案,但它会做同样的事情:

npm audit | grep -B 1 -A 10 High

This one worked for me:这个对我有用:

Show High Only只显示高

npm audit | grep -E "(High)" -B3 -A10

Show both Critical and High Issues显示关键和高问题

npm audit | grep -E "(High | Critical)" -B3 -A10

Look at the issue discussion where this solution is proposed.查看提出此解决方案的问题讨论。

If your are looking to do it in Powershell, just use the following command (Adapted from @stayingcool's answer):如果您想在 Powershell 中执行此操作,只需使用以下命令(改编自 @stayingcool 的回答):

Show High Only只显示高

npm audit | Select-String -Pattern "High" -Context 0,10

Show both High and Critical显示高和严重

npm audit | Select-String -Pattern "(High | Critical)" -Context 0,10

Edit: I recommend this (better) answer: https://stackoverflow.com/a/58056454/88111编辑:我推荐这个(更好的)答案: https : //stackoverflow.com/a/58056454/88111

It's not as pretty, but you can do:它不那么漂亮,但你可以这样做:

npm audit --parseable | grep high

With one additional downside being any package/issue metadata containing "high" will also be printed.另一个缺点是任何包含"high"包/问题元数据也将被打印。

When you I execute npm install using new npm 6 i got a messages that tell me I have some vulnerabilities :当您使用新的npm 6执行npm install我收到一条消息,告诉我我有一些漏洞

[!] 75 vulnerabilities found [4867 packages audited] [!]发现了75个漏洞[已审核4867个程序包]

Severity: 66 Low |严重程度:66低| 4 Moderate | 4中| 5 High 5高

Run npm audit for more detail运行npm audit以获取更多详细信息

I ran npm audit but got a truncated list of vulnerabilities.我进行了npm audit但截断了漏洞列表。

How I can check for only High vulnerabilities list ?如何仅检查“漏洞”列表?

Thanks谢谢

The --audit-level=high flag doesn't change the output of npm audit. --audit-level=high标志不会改变 npm 审计的输出。

I'm sending this to html for reporting purposes, so looking to clean it up further:我将此发送到 html 以用于报告目的,因此希望进一步清理它:

npm audit | grep -E "(High | Critical)" -B3 -A11 --color=always | grep -E '┌|│|├|└' --color=never

But this will lose the title, and the 'found vulnerabilities' at the bottom.但这将失去标题,以及底部的“发现的漏洞”。 I found it simplest to just run npm audit a couple times and get the bits I need appended to a file.我发现最简单的方法是运行几次 npm audit 并将我需要的位附加到文件中。

Ended up going with something like this:结束了这样的事情:

npm audit | grep '===' --color=never > temp.txt
npm audit | grep -E "(High | Critical)" -B3 -A11 --color=never | grep -E '┌|│|├|└' --color=never >> temp.txt
npm audit | grep -E "(found|scanned packages)" --color=never >> temp.txt
cat temp.txt

Or as a catchy one liner (lol) that also removes the temp.txt file:或者作为一个引人入胜的衬垫 (lol) 也删除了 temp.txt 文件:

npm audit | grep '=== npm audit' --color=never > temp.txt; npm audit | grep -E "(High | Critical)" -B3 -A11 --color=never | grep -E '┌|│|├|└' --color=never >> temp.txt; npm audit | grep -E "(found|scanned packages)" --color=never >> temp.txt; cat temp.txt; rm temp.txt;

The line is ugly but is working well across a bunch of different repos, provided you only need the output in the terminal.这条线很丑,但在一堆不同的存储库中运行良好,前提是您只需要终端中的输出。

When outputting to a file, npm audit includes ansi color codes, that can't be turned off.输出到文件时,npm 审核包含无法关闭的 ansi 颜色代码。 And this is a problem for my reports!这对我的报告来说是个问题! Sed can be used to remove them: sed 可用于删除它们:

sed -i '' $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' temp.txt

只是计算高点:

npm audit | grep 'High' | wc -l | rev

Put this line into your audit scripts:将此行放入您的审计脚本中:

"audit": "level=$(npm audit --parseable | grep -E 'high|critical' | wc -l | rev); [ $level == 0 ] && exit 0"

This code does check the output of npm audit .这段代码会检查npm audit的输出。 If there are no high or critical vulnerabilities the process will not exit with error.如果没有高漏洞或严重漏洞,该过程将不会错误退出。

This package might be what you are looking for:这个包可能就是你要找的:

https://www.npmjs.com/package/audit-filter https://www.npmjs.com/package/audit-filter

It lets you filter by advisory number, which is better than filtering by level.它允许您按建议编号进行过滤,这比按级别过滤要好。

$ cat .nsprc
{
  "exceptions": [
    "https://npmjs.com/advisories/532",
    "https://npmjs.com/advisories/577"
   ]
}

Couple that with npm config for audit level and you're golden.将它与审计级别的 npm 配置结合起来,你就是黄金。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM