DevelopVulnerabilities
@holtkeeper/vuln-js
A Fixer for JavaScript projects. It removes vulnerable npm packages by editing the package.json next to a lockfile and regenerating that lockfile with the project’s own package manager. It is the fallback for lockfiles osv-scanner fix cannot handle (bun, pnpm, yarn) and a second chance for npm package-lock.json.
Public API
Section titled “Public API”jsFixer({ runner? }): Fixer— fixer namedjs.supports(source)is true forbun.lock,pnpm-lock.yaml,yarn.lockandpackage-lock.json.runnerdefaults tolocalRunner.planManifestEdits(manifest, findings, manager)— pure: returns the edited manifest, the fixed finding ids and notes.lockfileKind(path),detectPackageManager(kind, dir, packageManagerField)andlockfileUpdateCommand(manager)— package-manager detection (LockfileKindis the lockfile family:npm,bun,pnpm,yarn) and the command that regenerates its lockfile.
How a fix works
Section titled “How a fix works”- The lockfile decides the package manager; its directory is the project root.
- For every
npmfinding the target isfixedVersions[0]. Findings without a fix, or whose fix is not newer than the installed version, are skipped with a note. Several findings for the same package use the highest target. - A direct dependency (
dependencies,devDependencies,optionalDependencies) whose range still admits the vulnerable version gets^<target>. - A transitive package gets an override
^<target>. An existing override for the same key or plain name is replaced only when it still admits the vulnerable version; otherwise it is left alone. - The lockfile is regenerated without lifecycle scripts.
changedFilescomes from comparing file hashes before and after. If the package manager fails,package.jsonand the lockfile are restored and theCommandErroris rethrown.
Per package manager
Section titled “Per package manager”| Manager | Override field | Override key | Lockfile command |
|---|---|---|---|
| npm | overrides |
qs@>=6.7.0 <6.7.3 |
npm install --package-lock-only --ignore-scripts |
| bun | overrides |
qs@>=6.7.0 <6.7.3 |
bun install --lockfile-only --ignore-scripts |
| pnpm | pnpm.overrides |
qs@>=6.7.0 <6.7.3 |
pnpm install --lockfile-only --ignore-scripts |
| yarn berry | resolutions |
qs |
yarn install --mode=update-lockfile |
| yarn classic | resolutions |
qs |
yarn install --ignore-scripts |
npm, pnpm and Bun 1.4 match override keys with a semver range (checked against npm 11, pnpm 10 and Bun 1.4.4), so the key covers only the vulnerable versions >=<lowest vulnerable> <target>. With selector keys, findings are grouped per major line, so a fix on qs@2 does not pull qs@6 users along. Yarn classic only matches names and globs, and berry matches exact descriptors, not ranges, so yarn gets one plain-name resolution per package that moves every copy.
Yarn berry is chosen when .yarnrc.yml is in the project directory or packageManager is yarn@2 or later; otherwise yarn classic.
Limitations
Section titled “Limitations”- When the vulnerable copy is transitive but the package is also a direct dependency whose range already excludes it, nothing is overridden (npm rejects overrides that conflict with direct dependencies). A note explains it.
- Non-semver ranges (
file:,workspace:,git, URLs, aliases, dist-tags) and nested npm override objects are skipped with a note. - Only the
package.jsonnext to the lockfile is edited. Workspace members’ manifests are not touched, and overrides kept inpnpm-workspace.yamlare neither read nor merged. - Yarn classic has no lockfile-only mode, so it installs
node_modules(scripts still disabled). - The package manager needs registry access. The rescan decides whether a finding is really gone.