fix(typosquat): suppress scoped-package and short-name false positives (v0.5.5)#8
Merged
Merged
Conversation
…s (v0.5.5) Scoped npm packages have verified scope ownership: @babel/parser is published by the babel team, it cannot pretend to be `parcel`. Comparing scoped basenames against unscoped popular targets was producing overwhelming false positives across @astrojs/*, @babel/*, @floating-ui/*, @img/*, @react-dnd/*, @shikijs/*, @sinonjs/*, @types/*, @wix/* etc. Skip the check for scoped names; detecting real scope-confusion attacks (@bable/lodash) needs per-scope reputation data we don't have. Distance 2 across 4-5 char names means ~half the characters differ — that's a different word, not a typo. Tighten the threshold to require distance 1 when either name is shorter than 7 chars. This eliminates asap/tsup, clsx/tsx, vfile/vite, regex/remix, defu/debug, nise/nest, jose/core, parse5/parcel and similar legitimately-distinct pairs while still catching real short-name typos like lodsh/lodash. Allowlist five legit packages that sit at distance 1 from popular targets and were being flagged on first scan: color, acorn, react-dnd, jose, prismjs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
A real-world scan against an Astro/Wix project surfaced 34 typosquat false positives. Three patterns accounted for all of them, fixed in this PR:
1. Scoped packages compared against unscoped popular targets (15 FPs). The checker stripped the scope and compared the basename, so
@babel/parserwas flagged as a possible typosquat ofparcel,@astrojs/prismofprisma,@floating-ui/coreofora, etc. But npm scopes carry verified ownership —@babel/parseris published by the babel team and cannot impersonateparcel. Skip the check entirely for scoped names. Detecting real scope-confusion attacks (@bable/lodash) needs per-scope reputation data we don't have; that's an explicit tradeoff documented in the code.2.
MAX_DISTANCE = 2too lenient for short names (16 FPs). Distance 2 across 4-5 char names means ~half the characters differ — that's a different word, not a typo. Examples:asap/tsup,clsx/tsx,vfile/vite,regex/remix,defu/debug,nise/nest,jose/core,parse5/parcel. Switched to a length-adaptive threshold: require distance 1 when either name is shorter than 7 chars. Distance-1 short typos likelodsh/lodashare still caught.3. Legit packages at distance 1 from popular targets (3 FPs). Allowlisted
color,acorn,react-dnd,jose,prismjs— all widely-used real packages that sit at distance 1 from existing entries (colors,react-dom,@nestjs/core, etc.).Of the 34 FPs in the original report, 31 disappear with these fixes. Remaining edge case:
piccolorevspicocolors(genuinely suspicious-looking; kept flagged).Test plan
npm test)lodahs/lodash(transposition),expres/express(deletion),cornmander/commander(homoglyph),reqests/requests(PyPI)npm run buildclean🤖 Generated with Claude Code