fix(arborist): fix audit-report determinism due to dropped via links#9603
Merged
Conversation
In `AuditReport#init`, the deduplication logic (`if (!seen.has(k))`) prevents evaluating the exact same advisory multiple times. However, if a package has multiple identical-range dependencies that trigger metavulns, those metavulns share the same computed range and produce an identical collision key `k`. Previously, `vuln.addVia()` was called inside the `if (!seen.has(k))` block. When a collision occurred, the duplicate key skipped the block, causing the `via` link (and its reciprocal `effects` link) for the second dependency to be silently dropped. This resulted in an incomplete dependency graph and non-deterministic serialization depending on the resolution order of `Promise.all()` in the real world. This commit removes the inline `addVia` and adds a post-loop reconciliation pass at the end of `#init`. By waiting until all advisories are instantiated and cleaned up, we mathematically guarantee that all valid metavulns establish their `via` links deterministically. This also structurally avoids triggering the expensive `#fixAvailable` setter multiple times during the loop iteration. A comprehensive programmatic test has been added to reproduce and assert the dropped-via bug and determinism.
owlstronaut
requested changes
Jun 24, 2026
owlstronaut
approved these changes
Jun 24, 2026
Contributor
|
🎉 Backport to |
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.
Description:
Fixes #8989
Bug:
npm auditwas 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. Becausevuln.addVia()was invoked inside this block, a duplicated range collision would simply skip the execution and permanently drop thevialink (and its correspondingeffectslink). Consequently, depending on the randomPromise.allresolution order of the metavuln calculator across network calls, differentviabranches were being non-deterministically truncated.Fix:
This PR extracts the
addViaoperation from theseendeduplication block and implements a comprehensive post-loop reconciliation pass. We ensure that:viaandeffectslinks are deterministically established after all dependencies and metavulns are cleanly instantiated.deleteAdvisory) cannot be accidentally resurrected.fixAvailablesetter during the primary loop iterations, performance overhead remains minimized.Testing:
audit-report.jscovering the identical range metavuln fallback (*) condition.viapath).