Skip to content

fix(core): follow npm/pnpm/yarn/bun script invocations in install hooks - #89

Merged
tonibergholm-codento merged 9 commits into
mainfrom
fix/85-follow-npm-run
Nov 20, 2026
Merged

tonibergholm-codento merged 9 commits into
mainfrom
fix/85-follow-npm-run

Conversation

@tonibergholm-codento

Copy link
Copy Markdown
Contributor

A lifecycle hook like "postinstall": "npm run setup" hid whatever scripts.setup ran: the payload behind it rated low instead of critical (#85). Now the install-scripts rule follows package-manager invocations into the package's own scripts.

  • After npm, pnpm, yarn or bun, every word that names a defined script is followed, along with its pre/post hooks and the npm aliases (t, cit, sit, restart → stop/start, pack, publish, version).
  • Every package-manager invocation also follows the install lifecycle (preinstall, install, postinstall, prepublish, prepare).
  • npm start with no start script scans server.js, as npm does.
  • A followed script gets the same inline-danger check and command-line scan as the hook, and the evidence names it.
  • Scripts are followed from a worklist with a visited set, so each is scanned once, chains of any length terminate, and the work stays linear.

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_REVISION goes 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 test passes (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.

…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
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e92c61d7-6b4a-4d03-85dc-103a4db470c9
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T11:35:31.078035Z 5edc8f1 New commits
🔒 Security Review ✅ Completed 2026-11-20T11:37:37.868835Z 5edc8f1 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Sentinel dependency audit — WARN · ✓ ok

145 allow · 5 warn · 0 block · 0 error
provenance: 46 verified · 0 invalid · 104 absent · 0 unknown

package verdict score finding how to fix
esbuild@​0.28.1 warn 62/100 `install.js` combines launch + write + read primitives — partial materialization pattern. Review the finding details; approve with a recorded rationale only if you understand and accept the risk.
fast-uri@​3.1.9 warn 75/100 Network egress: connects to a hardcoded IP address. Confirm the egress is expected for this package's purpose; if not, remove it or pin to a version without it.
isexe@​2.0.0 warn 77/100 `test/basic.js` combines read + launch + write primitives — partial materialization pattern. Review the finding details; approve with a recorded rationale only if you understand and accept the risk.
tsx@​4.22.4 warn 76/100 `dist/index-D9F1FXzN.cjs` combines read + write primitives — partial materialization pattern. Review the finding details; approve with a recorded rationale only if you understand and accept the risk.
undici-types@​7.18.2 warn 64/100 Network egress: imports a raw networking module. Confirm the egress is expected for this package's purpose; if not, remove it or pin to a version without it.

▶ Run sentinel explain <package> <version> for a suggested safe version and a ready waiver.

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.
@tonibergholm-codento
tonibergholm-codento merged commit dfcc42e into main Nov 20, 2026
7 checks passed
@tonibergholm-codento
tonibergholm-codento deleted the fix/85-follow-npm-run branch November 20, 2026 13:46
tonibergholm-codento added a commit that referenced this pull request Nov 20, 2026
Bump all seven workspaces, the exact internal pins, ENGINE_VERSION and the
CLI/MCP versions to 0.1.0-alpha.3, and add the release notes. The release
carries the security audit hardening (#84) and the install-script
detection-gap fixes (#89, #90, #91, #92).
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.

Detection gap: install-scripts does not follow npm/yarn/pnpm run into package scripts

1 participant