Skip to content

harden(node): strip NODE_OPTIONS + NPM_CONFIG_* for npm/pnpm/npx + JS toolchain #37

Description

@thehoff

Goal

Zero-trust layer across the entire Node-based wrappers. NODE_OPTIONS=--require /tmp/evil.js hijacks every Node process — that includes npm, pnpm, npx, vitest, jest, playwright, tsc, eslint, prettier, prisma, next. One env-strip covers the whole ecosystem.

Pattern

secure_node_command(binary) helper used by all Node-spawning sites. Same shape as secure_rg_command().

Env vars to strip

  • NODE_OPTIONS (--require, --inspect-brk=0.0.0.0:9229, etc.)
  • All NPM_CONFIG_* and npm_config_* (lowercase; matches every .npmrc key including script-shell, ignore-scripts=false, node-options, userconfig, globalconfig)
  • PRISMA_QUERY_ENGINE_BINARY, PRISMA_SCHEMA_ENGINE_BINARY, PRISMA_INTROSPECTION_ENGINE_BINARY
  • PLAYWRIGHT_BROWSERS_PATH
  • TS_NODE_PROJECT
  • NEXT_SHARP_PATH

Args to reject

  • --require <path> (jest/vitest), --setupFiles, --globalSetup, --reporter <path> (jest/vitest/playwright reporters are arbitrary JS)
  • --plugin <abs-path>, --rulesdir, --resolve-plugins-relative-to (eslint), --plugin <abs> (prettier)
  • --config <path outside cwd> (every JS tool — soft check)
  • npm install/pnpm install/npx <pkg> for packages not in package.json (or just whitelist read verbs)

Wire-in sites

src/cmds/js/*.rs — all 8+ files. Each resolved_command(...)secure_node_command(...).

Tests

tests/security/node_hardening.rs:

  • NODE_OPTIONS="--require /tmp/evil.js" contextcrawler tsc --version does NOT execute evil.js
  • NPM_CONFIG_USERCONFIG=/tmp/evil-npmrc contextcrawler npm config get registry does NOT read evil-npmrc
  • vitest --reporter /tmp/evil-reporter.js rejected

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions