[BUG] `npm audit` nondeterministically includes a top-level metavuln (@types/jest) with an unchanged lockfile
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
Hướng nghiên cứu
Start with workspaces/arborist/lib/audit-report.js, especially AuditReport#init and the loop that adds calculated metavulnerabilities to the advisories set. Read the existing audit report tests and add a case that controls calculator resolution order for a growing set of advisories. Done means identical raw audit input produces the same report, including the @types/jest top-level metavulnerability.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- I have searched the existing issues
- I am using the latest npm (also reproduced on npm 12.2.2 via
npx) - This is not solely a request to bump a dependency for a CVE — this is about
npm audit's report being nondeterministic for an unchanged tree, independent of which advisory is involved.
Current Behavior
With a lockfile that does not change, consecutive npm audit --json runs disagree about whether a top-level package is reported as a (meta)vulnerability. In a minimal tree whose only direct dependency is @types/[email protected], the entry vulnerabilities["@types/jest"] (a high metavuln reached via expect → jest-message-util/jest-util → picomatch, GHSA-fc5q-39xc-vjpf) is present on some runs and absent on others, with no change to package.json, package-lock.json, or node_modules. The deeper packages (expect, jest-message-util, jest-util, jest-mock, picomatch) are reported on every run — only the top-level metavuln flickers, which also makes the high/total counts flip between 5 and 6.
This breaks any tooling that ratchets the audit output against a baseline (the same lockfile intermittently crosses the threshold).
run 1: absent | high=5 | total=5
run 2: PRESENT | high=6 | total=6
run 3: PRESENT | high=6 | total=6
run 4: absent | high=5 | total=5
... (2 of 12 runs PRESENT on npm 11.17.0; 2 of 12 on npm 12.2.2)
Expected Behavior
The same tree plus the same advisory data should produce the same report every time. npm audit should be deterministic for an unchanged lockfile.
Steps To Reproduce
- Empty folder with this
package.json:{ "name": "audit-flake-repro", "version": "1.0.0", "private": true, "devDependencies": { "@types/jest": "30.0.0" } } npm install --ignore-scripts- Run this a dozen times and watch the top-level entry appear and disappear:
for i in $(seq 1 12); do npm audit --json 2>/dev/null \ | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const j=JSON.parse(s);const v=j.vulnerabilities||{};console.log((v["@types/jest"]?"PRESENT":"absent ")+" high="+Object.values(v).filter(x=>x.severity==="high").length)})' done
Root cause (investigated)
The nondeterminism is entirely client-side, in AuditReport#init — not in the server response:
- Running with
--loglevel silly, a PRESENT run and an absent run have an identical bulk request body and an identical raw server report (the object logged bylog.silly('audit report', this.report)atworkspaces/arborist/lib/audit-report.js#L102, before#initruns). Same input, different output. - Diffing the two silly logs, the only difference is the order in which the metavuln packuments resolve from cache (
expect,jest-message-util,jest-utilare fetched in a different order between runs).
The mechanism is an iterate-while-mutating race on the advisories Set in #init:
const advisories = new Set(await Promise.all(promises))(L128) is then iterated withfor (const advisory of advisories)(L130).- Inside the loop, metavulns for dependents are computed asynchronously and pushed back into that same Set from promise callbacks:
p.push(calc.then(meta => { if (...) advisories.add(meta) }))(L182–L185), awaited per-advisory atawait Promise.all(p)(L191). - The top-level
@types/jestmetavuln is propagated up the dependent chainpicomatch → jest-message-util/jest-util → expect → @types/jest, each level added to the Set during the triggering advisory'sawait Promise.all(p). Whenexpect's metavuln resolves and is added before the Set iterator drains, the@types/jestmetavuln it produces is visited and becomes a top-level entry (PRESENT). When it resolves after the iterator is alreadydone,@types/jestis never visited (absent).
Since the order in which these cached packument lookups resolve is timing-dependent, the visited set of advisories — and therefore the final report — varies run to run.
The same code shape is present on latest (arborist 10.0.4), so the issue is not version-specific.
A fix would make #init drain the growing set deterministically (e.g. a worklist loop that keeps processing until no new advisories remain, instead of a single for...of pass over a Set that is being mutated by async callbacks), with a test that controls the calculator resolution order. Happy to open a PR if the maintainers agree on the approach.
Environment
- npm: 11.17.0 (also reproduced on 12.2.2 via
npx [email protected]) - Node.js: 24.19.0
- OS: Ubuntu on WSL2 (Linux 6.x)
- npm config: defaults, public registry, no user
.npmrc - Bundled:
@npmcli/arborist9.8.0,@npmcli/metavuln-calculator9.0.3 (as shipped with npm 11.17.0)
- Ngôn ngữ chính
- JavaScript
- Star
- 10.3k
- Fork
- 5k
- Merge trung bình
- 4 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của npm/cli
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsCó thể đã có người làm @saruk-vedant đã nhận 7 ngày trước. Đang mởBug Needs Triage Triage Requested
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyCó thể đã có người làm @drawliin đã nhận 42 ngày trước. Đang mởcmd:delete Priority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 2 ngày
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởEngineering Priority 1
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 2 ngày
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysCó thể đã có người làm @greenlincoln05 đã nhận 63 ngày trước. Đang mởPriority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
Issue tương tự
-
docs: add SECURITY.md vulnerability reporting policyCó thể đã có người làm @AK-Lmn đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
flisk-sh/linux2wasm#12 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
possible bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Mintplex-Labs/anything-llm#7388 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 60/100
Maintainer thường phản hồi trong vòng 1 ngày
-
v6: Minified bootstrap.min.css is missing header infoCó thể đã có người làm @lazerg đã nhận hôm nay. Đang mởbug build confirmed has-pr v6
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
githubnext/gh-aw-workshop#6332 ·
Maintainer thường phản hồi trong vòng 1 ngày