fix(arborist): fix audit-report determinism due to dropped via links#9638
Merged
Conversation
…9603) **Description:** Fixes #8989 **Bug:** `npm audit` was occasionally generating non-deterministic output with missing vulnerabilities when metavulns from identical-range dependencies caused a collision. **Root Cause:** In `AuditReport#init`, the deduplication logic (`if (!seen.has(k))`) was aggressively dropping identically-computed metavuln advisory ranges across different dependency paths. Because `vuln.addVia()` was invoked *inside* this block, a duplicated range collision would simply skip the execution and permanently drop the `via` link (and its corresponding `effects` link). Consequently, depending on the random `Promise.all` resolution order of the metavuln calculator across network calls, different `via` branches were being non-deterministically truncated. **Fix:** This PR extracts the `addVia` operation from the `seen` deduplication block and implements a comprehensive post-loop reconciliation pass. We ensure that: 1. `via` and `effects` links are deterministically established *after* all dependencies and metavulns are cleanly instantiated. 2. The reconciliation ignores already deleted advisories, guaranteeing that the cleanup lifecycle (`deleteAdvisory`) cannot be accidentally resurrected. 3. Because we aren't repeatedly calling the `fixAvailable` setter during the primary loop iterations, performance overhead remains minimized. **Testing:** - Added a new strict programmatic determinism test in `audit-report.js` covering the identical range metavuln fallback (`*`) condition. - Confirmed the new test correctly reproduces the regression (fails deterministically on unfixed code by dropping the `via` path). - All 27 existing suite tests pass flawlessly. (cherry picked from commit 690bf17)
owlstronaut
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #9603 to
release/v11.