Skip to content

Detection gap: preloads and bins from bundled node_modules are not resolved in install scripts #87

Closed

Description

@tonibergholm-codento

Kind

Missed detection (should have been flagged, wasn't)

Package name and version

Synthetic pattern, no real package. Found during the security audit hardening (#84); listed as a follow-up in ADR-0056.

Expected vs actual verdict

The install-scripts rule deliberately resolves preload values (-r, --require, --import, --loader, and the same flags inside NODE_OPTIONS) only when they start with ./, ../ or /. That stopped false criticals from a bundled dotenv/config. As a side effect, a package can run its own code through a bare module name, or through an extension-less relative path, without the hook escalating:

Lifecycle command What runs
node -r evil setup.js node_modules/evil/index.js, shipped inside the tarball as a bundled dependency
NODE_OPTIONS=--require=./hook node -v hook.js (relative, but no extension)
NODE_OPTIONS='-r ./hook.js' node -v hook.js (flag and value as separate words inside the quoted value)
evil-bin node_modules/.bin/evil-bin, a bundled dependency's bin

All of these rate low. The files are still scanned by the other rules.

The pattern

A package bundles a dependency (or a bin) that carries the payload and loads it from a lifecycle hook by module name, by a bin name on npm's PATH, or by an extension-less preload path.

Suggested approach

Resolve bare names against the tarball only, never against the network or the host:

  • -r and friends: package/node_modules/<spec>, <spec>.js, <spec>/index.js, and that directory's package.json main. Skip the name when none of those is shipped.
  • Extension-less relative preload values: try .js and /index.js, as script operands already do.
  • NODE_OPTIONS: tokenize the value and apply the same flag handling as the command line.
  • Command words: also check package/node_modules/.bin/<word>, and the file a bundled package's bin entry points to.

Keep the bundled dotenv/config case clean when its contents are benign. Bundled dependencies are rare, so the false-positive risk is the main thing to test.

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

    needs-triageNew issue awaiting triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions