Skip to content

Gate npx and npm exec on vuln verdicts before the package runs - #229

Open
juangaitanv wants to merge 12 commits into
mainfrom
gate-npm-exec
Open

juangaitanv wants to merge 12 commits into
mainfrom
gate-npm-exec

Conversation

@juangaitanv

@juangaitanv juangaitanv commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

npx foo downloads a registry package and runs it straight away, and nothing checked it. exec was not an install subcommand, so corgea npm exec passed it through unchecked, and corgea npx did not exist.

What changes

  • corgea npx <pkg> and corgea npm exec|x <pkg> work out which packages npm would fetch and check them against Corgea verdicts before anything downloads. That means the --package/-p specs, or the command spec when no --package is given. The check is the same as npm install -g <spec> and covers transitive dependencies. A flagged package blocks with the same report npm install prints. A clean one runs the real npx (or npm exec) with argv untouched and returns its exit code.
  • An argv npm could read more than one way is reported unverifiable instead of guessed at.
  • --tag, --before, --registry and --@scope:registry= are passed into the check, so it covers the version npm would actually fetch.
  • Git, URL and path specs are reported unverifiable (?) and block when the gate fails closed.
  • corgea shims install now also shims plain npx.

Invariants

  • No tarball is fetched and no package code runs before the verdict. The only npm call before the verdict is the --package-lock-only --ignore-scripts tree pass.
  • The gate reads only spellings npm reads one way: --, common switches such as -y, --package/npx's -p, -c/--call, and registry, tag and log flags with a value that is not empty, dash-led or space-padded; a package spec or the command name holds no whitespace (a -c value may). Any other argv is unverifiable: nothing in it is checked or shown as ✓, it blocks when the gate fails closed, and otherwise it runs with a warning and the hint npx --package=<pkg> -- <cmd>.

What can go wrong

  • Unverifiable spellings run in public mode. An argv outside the grammar runs unchecked with a warning when the gate fails open, as git and URL specs do today. One option for later: block these in every mode. Not done here.
  • Some ordinary spellings become unverifiable. npm exec reads flags after the command, so npm exec eslint --fix is unverifiable; npx eslint --fix is accepted. npx's --shell, -c=x, -p=x and --no-yes are unverifiable too.
  • Git or URL npx specs skip the tree pass. This follows the existing -g rule. In fail-open public mode their dependencies run unchecked, with a warning.
  • Fuzzed against npm 10.9.9 only. 34,638 argvs compared with npm's own nopt and npx-cli loop: 0 misses among the 9,857 accepted. A future npm change to flag parsing could make the grammar accept an argv npm reads differently.

Known limits

  • --prefix/-C, --cache, --offline, --prefer-offline, --userconfig, --globalconfig, --force and --legacy-peer-deps are unverifiable (corgea npx --prefix dir pkg): they change which npmrc, registry, cache or dependency tree npm installs, and the check cannot follow them. They block when the gate fails closed and warn otherwise.
  • npx runs an already-installed local or global bin (corgea npx eslint with node_modules/.bin/eslint present), and the gate checks the registry resolution of the spec, not that installed copy.
  • A project or user .npmrc that sets package= is not read (package=evil in .npmrc, then corgea npx tool): npx fetches that package unchecked.
  • Not from this PR: corgea npm --yes true exec <pkg> and corgea npm --package x exec <pkg> route on the wrong token and run unchecked, even fail-closed. install has the same hole. It gets its own PR.

Compatibility

  • New subcommand corgea npx. corgea npm exec used to be a silent passthrough and is now gated.
  • npm install -g with --tag=/--before= now keeps its tree pass. It used to fall back to checking named packages only.
  • --call/-c with no --package fetches nothing and still runs unchecked.
  • A command npm finds already installed runs that copy without a fetch. The gate checks its registry version, not the installed copy.

How to validate

Real npm 10.9.9 and 11.21.3, a fresh npm cache, spy wrappers on npm/npx, and CORGEA_INSTALL_GATE_FAIL_CLOSED=1:

  • corgea npx lodash@4.17.20 exits 1 and lists CVE-2021-23337 and others. ~/.npm/_npx stays empty and npx is never spawned.
  • corgea npx --yes cowsay@1.6.0 --no-such-flag-xyz -f nonexistent-cow checks 33 packages, then prints exactly what plain npx prints.

Fuzz: bash .cos/fuzz/run-all.sh "$PWD" (local harness, not committed: about 1 MB of corpora).

Review first:

  • src/precheck/parse.rs parse_exec_args: every accepted argv must name exactly what npm fetches; everything else returns Err.
  • src/precheck/mod.rs run_npm_exec: an Err takes the existing unverifiable path, with no ✓.
  • src/precheck/tree.rs: the global-install allowlist now includes --tag= and --before=.

Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/parse.rs Resolved
Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/mod.rs Resolved
Comment thread skills/corgea/SKILL.md Resolved
@corgea-security corgea-security added the dennis-reviewed Dennis completed an automated review label Dec 3, 2026

@corgea-security corgea-security left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review risk: 4/5.

The new npx/npm exec gate can allow a different package than the one it verdicted, and npx_as_npm_exec panics on common incomplete flags. Existing install wrappers are only signature-plumbed and look unchanged.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

@juangaitanv

Copy link
Copy Markdown
Contributor Author

Review 6168358861 (risk 4/5) addressed at b4aaf6c: the panic and the dropped scope-registry/config flags are fixed, with tests that fail on the old head. The installed-bin finding is declined as out of scope; the brief excludes re-gating locally installed packages, and the docs now say so. The shim docs name command npx.

Comment thread src/precheck/parse.rs Resolved

@corgea-security corgea-security left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review risk: 4/5.

The npx/npm exec gate is real for the common forms the new tests cover, but a non-boolean --flag=pkg spelling still skips it and runs the package. The earlier panic, registry-flag, and shim-doc comments are fixed in this diff; the installed-copy note is an accepted, documented limit.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

@juangaitanv

Copy link
Copy Markdown
Contributor Author

Review 6169043446 (risk 4/5) addressed at a370c8b. The --flag=pkg finding was real: npm runs the value of any boolean flag's --flag=value as the command (npm exec --audit=zzevil, --color=, npx --save=), and the parser knew only part of npm's boolean list. Now the value of any --flag=value is checked as a possible command, unless the flag takes a string or the value is true/false. Real-npm probes check the package npm fetches; --loglevel=silent, -C dir and --@scope:registry=url add no false checks. Known costs, listed in the PR's risks: string flags the parser does not list (--logs-dir=) are over-checked, and --flag= with an empty value makes npm fetch a package named undefined that the gate reports as an empty spec (blocks when fail-closed).

Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/parse.rs Resolved
Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/parse.rs Resolved

@corgea-security corgea-security left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review risk: 4/5.

The new npx/npm exec gate blocks the tested fetch path, including a vulnerable transitive, but it verdicts a fresh global resolution of the spec and then executes npx. A local binary that satisfies the spec is therefore not what was checked, and --userconfig/--globalconfig deliberately drops the tree pass while still running under the default fail-open policy.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

@juangaitanv

Copy link
Copy Markdown
Contributor Author

Review 6169940229 at dc6c8e6: the registry-key nitpick is fixed. The two high findings repeat documented scope decisions and are declined in their threads. Installed bins are not re-checked, per the brief. With --userconfig/--globalconfig only the named packages are checked, which is the gate's existing named-only policy: blocks when logged in or fail-closed, warns in public mode.

Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/parse.rs Resolved

@corgea-security corgea-security left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review risk: 4/5.

Ordinary npx <pkg> gating is covered and tested, but several accepted flags vet a different install than the one npx runs, so a clean verdict can still execute an attacker-chosen tree. Fail-closed does not stop those argv shapes.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

…nd npm exec

They change which npmrc, registry or cache npm installs from, and the check cannot follow them.
@juangaitanv

Copy link
Copy Markdown
Contributor Author

Review 6177098968: the high finding (--prefix/--cache/--offline vet a different install than npx runs) is fixed in f66cd73; those flags now make the argv unverifiable. Details: #229 (comment)

Comment thread src/precheck/parse.rs Resolved
Comment thread src/precheck/parse.rs Resolved
Comment thread src/precheck/parse.rs Resolved

@corgea-security corgea-security left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review risk: 4/5.

Basic npx pkg and npm exec --package=<pkg> gating, including transitive advisories, is in place, but the npx grammar vouches for a different install than npm runs. Post-command npm options are ignored, and --userconfig/--globalconfig skip the tree pass while npx still applies them.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

…exec

A config file can set the registry, cache or offline mode, and the check does not read it.
@juangaitanv

Copy link
Copy Markdown
Contributor Author

Review 6177540675: config flags (r4790718257) fixed in fe61ef9, now unverifiable; flags after the npx command (r4790717995) declined with a real-npx probe, details in the thread.

Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/mod.rs Resolved
Comment thread src/precheck/parse.rs Resolved
Comment thread src/precheck/mod.rs Resolved

@corgea-security corgea-security left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review risk: 4/5.

The main npx/npm exec path blocks a vulnerable transitive before exec, and the declined post-command npx flags plus the userconfig/globalconfig fix were not reopened. A passing verdict can still describe a different binary or tree than the one that runs, and some unambiguous npm spellings skip the check unless fail-closed is set.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

They change the dependency tree npm installs, and the tree pass does not carry them.
@juangaitanv

Copy link
Copy Markdown
Contributor Author

Review 6178120176: --force/--legacy-peer-deps (r4791166973) fixed in 97d48c7, now unverifiable. Installed local bin (r4791166795) is a stated Known limit; unverifiable-runs-in-public-mode (r4791167144) is the chosen policy, with blocking in every mode listed as an option; Debug quoting (r4791167299) kept so empty and padded tokens stay visible. Details in each thread.

Comment thread src/precheck/parse.rs Resolved
Comment thread src/precheck/uv.rs Resolved
Comment thread src/precheck/parse.rs Resolved

@corgea-security corgea-security left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review risk: 4/5.

Plain npx pkg and npm exec pkg are gated, but the new grammar rejects many argv shapes npm 10.9.9 still resolves to a single fetch, and that path runs the real binary unless fail-closed is on. Default corgea npx / npm exec can be bypassed with one unambiguous flag or shorthand.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

@juangaitanv

Copy link
Copy Markdown
Contributor Author

Review 6178798028: the one finding (r4791685612) is blocked when the gate fails closed; it concerns public-mode policy and spellings the grammar could also accept. Parked as a follow-up; details in the thread.

This branch has not been deployed

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

Labels

dennis-reviewed Dennis completed an automated review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants