fix(arborist): allow audit fix to install safe downgrades#9791
Open
github-actions[bot] wants to merge 1 commit into
Open
fix(arborist): allow audit fix to install safe downgrades#9791github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
## What / Why `npm audit` can report that a fix is available through `npm audit fix` when the highest safe version inside the declared dependency range is older than the installed version. Arborist already selects that safe candidate using the advisory range, but `CanPlaceDep` rejects it because replacement candidates normally must be newer than the installed version. This causes `npm audit fix` to complete without applying the advertised remediation. ## How - Pass the existing audit report from `PlaceDep` into `CanPlaceDep` and recursive peer placement checks. - Permit an older candidate only when: - the installed node is vulnerable; - the candidate is not vulnerable; and - the candidate passes the existing replacement and peer dependency checks. - Preserve existing no-downgrade behavior for ordinary installs and updates. - Add synthetic, strictly mocked regressions covering: - compatible safe downgrades; - non-audit placement; - still-vulnerable candidates; - peer conflicts; - actual tree replacement; and - metavulnerability removal by pruning a vulnerable transitive dependency. This does not change audit reporting or `--force` behavior. Fixes outside declared dependency ranges still require `npm audit fix --force`. ## Testing - Focused Arborist placement and audit tests - npm command-level audit tests ## References Fixes #9557 Fixes #9718 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 882d0b2)
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 #9761 to
release/v11.