Skip to content

fix(remediation): drop a stale command when a merged target is raised - #1142

Merged
sonukapoor merged 1 commit into
mainfrom
bugfix/issue-1140-stale-merged-fix-command
Sep 15, 2026
Merged

sonukapoor merged 1 commit into
mainfrom
bugfix/issue-1140-stale-merged-fix-command

Conversation

@sonukapoor

Copy link
Copy Markdown
Collaborator

A copy-run fix command could name a version the scan itself had already determined was still vulnerable.

Measured on a real repo, for nx@22.5.0:

  • advisory hint 22.7.2, which validation found still vulnerable (18 versions scanned above current, 17 still vulnerable)
  • validatedFirstFixedVersion: 22.7.7
  • recommendedAction: "Upgrade nx to 22.7.7+", correct
  • runnableFixCommand: pnpm add nx@22.5.1, neither of those

A package can enter the plan twice. Here axios carried a transitive remediation whose package was nx, creating a chain-resolution target with an explicit command built for nx@22.5.1, while nx also entered as a direct target at the validated 22.7.7. upsertTarget raised targetVersion correctly but kept existing.command ?? next.command, and buildTargetCommand prefers an explicit command over deriving one from targetVersion.

recommendedAction is derived from the finding fields, which is why it stayed right while the command went wrong.

The mirror case is guarded as well: when the existing target wins the comparison, a command built for the lower incoming version is equally stale.

Verified with a differential across eight projects and 51 direct findings with commands: zero disagreements between the emitted command and the validated fix version, where the new test fails without the change.

Closes #1140

Related to #1007 and #1113. The review on #1113 asked for plan.targets as well as plan.command; runnableFixCommand reads from targets, so this is that half. Original diagnosis of the underlying cross-wiring belongs to @osfv.

When one package enters the plan twice, upsertTarget raises targetVersion to
the higher of the two but kept `existing.command ?? next.command`, so an
explicit command string built for the lower version survived the merge.
buildTargetCommand prefers an explicit command over deriving one from
targetVersion, so the stale string won whenever the target had no workspace
scoping to override it.

Measured on a real repo: nx validated at 22.7.7 after 18 versions were
scanned and 17 found still vulnerable, while the emitted command read
`pnpm add nx@22.5.1`. recommendedAction is derived from the finding and
stayed correct, which is why the two disagreed.

The mirror case is guarded too: when the existing target wins, a command
built for the lower incoming version is equally stale.
@sonukapoor
sonukapoor merged commit d59ba4b into main Sep 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix command can name a still-vulnerable version when two targets for one package merge

1 participant