Skip to content

fix: make fix safe by default, new health score, verified typosquat check - #15

Open
AjayBThorat-20 wants to merge 1 commit into
feat/exploit-risk-rankingfrom
fix/safer-fix-and-health-score
Open

AjayBThorat-20 wants to merge 1 commit into
feat/exploit-risk-rankingfrom
fix/safer-fix-and-health-score

Conversation

@AjayBThorat-20

@AjayBThorat-20 AjayBThorat-20 commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

What and why

devcompass fix could make breaking changes in its default safe mode. On a project with axios@0.21.1, esbuild@0.19.0 and express@4.17.1 it would install axios@0.33.0, esbuild@0.25.0, cookie@0.7.0 and send@0.19.0, install transitive packages at the top level, and uninstall packages flagged as unused.

fix

  • "Safe" now means within semver's caret range: never a major, never a 0.x minor bump (breaking under semver). npm audit's fixAvailable object only counts when isSemVerMajor is false, and a merged finding is judged on the fix version actually chosen, not on any one source's safeFix.
  • A vulnerability with no concrete fix version is a review item instead of an install of @latest.
  • A vulnerable transitive package is never installed at the top level; it's listed under "Needs manual action" with npm audit fix and one combined overrides / pnpm.overrides / resolutions snippet.
  • Packages are only removed with the new --remove-unused flag, never by --all.
  • Each package is installed once, at the highest selected version; the dry-run summary shows versions again.

Health score: each category's penalty approaches a fixed cap (security 5, license/quality/outdated 1.5, unused 0.5) instead of growing with the number of findings, so 30 outdated packages can't outweigh one critical vulnerability. Any CRITICAL or known-exploited vulnerability caps the score at 3.9, any HIGH at 5.9. Scores change for most projects, so --ci --threshold users should re-check theirs.

Typosquat: a one-character name match (two swapped letters now count as one, catching loadsh and axois) is only reported when npm download counts confirm the look-alike is ≥50× more popular and the package has under 100k downloads a month. Thresholds come from real numbers: typo packages get 55 to 30k a month, while real look-alikes like preact, vuex, nuxi and cuid get 0.7M to 164M. The scan is reported incomplete if the counts can't be fetched, and the fix text is "Review before using", never "Replace with" the look-alike.

Install scripts: the regex scan of the project's own scripts is gone. Dependencies that run code at install time are listed from the lockfile as information (analyze, --deep, metadata.installScripts) and never scored.

Stacked on #14.

Merging the stack: use Create a merge commit, not squash (squashing makes every later PR show these commits again). After merging the PR below this one, click Delete branch on it; GitHub then retargets this PR to main and CI runs.

How I tested it

  • npm run test:coverage on Node 24.21.0, clean npm ci, network disabled: 206/206 pass, 40.7% lines
  • npm audit --audit-level=high clean
  • Fixture above: safe fixes 16 → 9, all within the caret range; fix --dry-run lists 6 transitive packages and the loadsh typosquat under "Needs manual action" with one overrides snippet
  • Real fix --yes on a scratch project: 3 in-place updates, backup created, unused package left alone, score 3.2 → 3.8

🤖 Generated with Claude Code

… check

`fix` could make breaking changes in its default safe mode. On a project
with axios@0.21.1, esbuild@0.19.0 and express@4.17.1 it would install
axios@0.33.0, esbuild@0.25.0, cookie@0.7.0 and send@0.19.0, install
transitive packages at the top level, and uninstall packages flagged as
unused.

fix:
- "Safe" now means within semver's caret range: never a major, never a
  0.x minor bump. npm audit's fixAvailable object only counts when
  isSemVerMajor is false, and a merged finding is judged on the fix
  version actually chosen, not on any one source's own safeFix.
- A security finding with no concrete fix version is a review item
  instead of an install of @latest.
- A vulnerable transitive package is never installed at the top level;
  it's listed under "Needs manual action" with `npm audit fix` and one
  combined overrides/pnpm.overrides/resolutions snippet.
- Packages are only removed with the new --remove-unused flag, never by
  --all. Unused findings are no longer counted as safe fixes.
- Each package is installed once, at the highest selected version, and
  the dry-run summary shows versions again.

Health score: each category's penalty approaches a fixed cap (security
5, license/quality/outdated 1.5, unused 0.5) instead of growing with the
number of findings. Any CRITICAL or known-exploited vulnerability caps
the score at 3.9, any HIGH at 5.9.

Typosquat: a one-character name match (two swapped letters now count as
one) is only reported when npm download counts confirm the look-alike is
50x+ more popular and the package has under 100k downloads a month. The
scan is reported incomplete when the counts can't be fetched. The fix
text is "Review before using", never "Replace with" the look-alike.

Install scripts: the regex scan of the project's own scripts is gone.
Dependencies that run code at install are listed from the lockfile as
information (analyze, --deep, metadata.installScripts), never scored.
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.

1 participant