Repository navigation
fix(core): follow npm/pnpm/yarn/bun script invocations in install hooks - #89
Conversation
…cripts A lifecycle hook such as `postinstall: "npm run setup"` was not followed into `scripts.setup`, so a payload executed by that script was rated low instead of critical. The resolver now follows `npm|pnpm run <name>`, `npm run-script <name>` and `yarn [run] <name>` (yarn bare form only when the script is defined) and scans the script body as a command line. Recursion is bounded at 8 script hops and each name is followed once per hook, so self-referencing scripts terminate and work stays linear. Closes #85
…scripts A followed `scripts[<name>]` body now gets the same inline-danger check as the hook text, so `postinstall: "npm run setup"` with `setup: "curl ... | sh"` is critical. The finding evidence names the followed script. `npm|pnpm|yarn run <name>` also follows a defined `pre<name>` and `post<name>`, under the same hop limit and visited set. Bare `yarn <name>` still needs `<name>` itself defined. Refs #85
Track the fewest hops at which each script was scanned and rescan a name reached at a strictly lower hop count, so a path that first hit a script at the hop limit cannot hide it from a shorter path. Parse package-manager command lines more completely: skip value-taking options with their value (--prefix, -C/--dir, --cwd, -w/--workspace, -F/--filter, --loglevel), treat test/start/stop/restart as script references for npm and pnpm, accept the npm aliases rum and urn, and follow bare `pnpm <name>` and `bun run <name>` only when the script is defined. Refs #85
Replace the precise npm/pnpm/yarn command-line parser with deliberate over-following. After `npm`, `pnpm`, `yarn` or `bun`, every word that names a defined script is followed (also after `--` and unknown options), together with its `pre` and `post` scripts. `t`, `tst`, `it` and `install-test` map to `test`, and `restart` also follows `stop` and `start`. A false positive needs the followed script itself to be dangerous; a missed script that runs would be a bypass. Followed scripts are scanned from a worklist with a visited set instead of recursion, so each script is scanned once, the work is bounded by the number of scripts, and a very long chain cannot overflow the stack. The hop limit is gone. Bump AUDIT_REVISION to 3: rule semantics changed, so audits persisted before script following must be recomputed. Refs #85
- Aliases no longer replace the literal word: `npm run t` follows `scripts.t` as well as `scripts.test`. - `pre<x>` and `post<x>` are enqueued for every word and alias target, whether or not `<x>` is defined, so `npm run build` with only `prebuild` follows `prebuild`. - `npm start` / `npm restart` with no `start` script runs `server.js`, so that file is scanned when it exists. - One command can run several scripts: `restart`, `pack`, `publish`, `version`, `install`/`i`/`ci`/`rebuild`, and the `test` aliases (`t`, `tst`, `it`, `install-test`, `cit`, `install-ci-test`) are mapped in a Map, so inherited keys such as `constructor` cannot match. Refs #85
- An empty `scripts.start` no longer suppresses the `server.js` fallback; only an own, nonempty string does, as in npm. - `it`, `install-test`, `cit` and `install-ci-test` run the install scripts and `test`. The npm install aliases (`add`, `in`, `ins`, `inst`, `insta`, `instal`, `isnt`, `isnta`, `isntal`, `isntall`) and the `verison` typo map like `install` and `version`. - A package-manager command whose subcommand is neither a known command nor a script also follows `prepare`, as a safe default. Refs #85
Any `npm`, `pnpm`, `yarn` or `bun` invocation now enqueues `preinstall`, `install`, `postinstall`, `prepublish` and `prepare`, whatever the subcommand (none, flags only, unknown, built-in or a script name). This replaces the unknown-subcommand special case and ends the alias chase: an alias nobody listed can no longer hide an install script. The alias map stays for `test` and the other non-install scripts, and gains `sit`, `clean-install-test`, `rb`, `clean-install`, `ic`, `install-clean` and `isntall-clean`. Refs #85
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Sentinel dependency audit — WARN · ✓ ok145 allow · 5 warn · 0 block · 0 error
▶ Run Sentinel · 150 packages audited · 2026-11-20T11:34:13.869Z · SBOM uploaded as a build artifact |
npm runs preprepare and postprepare (and the other pre/post pairs) during install. The removed install-alias entries had covered them through the pre/post loop; the unconditional install pass now does.
A lifecycle hook like
"postinstall": "npm run setup"hid whateverscripts.setupran: the payload behind it rated low instead of critical (#85). Now theinstall-scriptsrule follows package-manager invocations into the package's own scripts.npm,pnpm,yarnorbun, every word that names a defined script is followed, along with itspre/posthooks and the npm aliases (t,cit,sit,restart→ stop/start,pack,publish,version).preinstall,install,postinstall,prepublish,prepare).npm startwith nostartscript scansserver.js, as npm does.This over-follows on purpose. Following a script that might not run costs at most a false positive when that script body is itself dangerous; missing one that runs is a bypass. A precise package-manager parser kept missing aliases and options, so it was replaced.
AUDIT_REVISIONgoes to 3, so cached audits from before this change are re-run.Proof: 28 new tests in
packages/core/test/security-npm-run.test.ts, each failing before its fix.npm testpasses (1435 tests, 0 failures, 4 Linux-only skips). Reviewed with sol-loop: 5 rounds with gpt-6.2-sol. Sol verdict: approved.Closes #85.
Created with Claude Opus 5.5 in Claude Code (T3 Code). A Sonnet 5.5 subagent wrote most of the code.