Repository navigation
Stop leading flags from routing installs past the gate - #231
Open
juangaitanv wants to merge 13 commits into
Open
juangaitanv wants to merge 13 commits into
juangaitanv wants to merge 13 commits into
Conversation
juangaitanv
requested review from
Ibrahimrahhal,
corgea-security,
leenk7991 and
yhoztak
as code owners
December 3, 2026 19:48
corgea-security
left a comment
There was a problem hiding this comment.
Automated review risk: 2/5.
The leading-flag walk is fail-closed in the direction that matters: an unknown or dash-valued flag becomes unverifiable whenever any alternate reading lands on a different gated verb, and the npm/uv paths are covered by unit and e2e tests. I do not see a proven bypass, panic, or wrong argv in the diff.
No critical or high-priority changes were found.
corgea-security
approved these changes
Dec 3, 2026
corgea-security
left a comment
There was a problem hiding this comment.
Approved by Dennis: high policy risk and automated risk 2/5.
yhoztak
reviewed
Dec 3, 2026
yhoztak
left a comment
Contributor
There was a problem hiding this comment.
Nearly ready to approve. One gap is left in the class this PR closes; details inline.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
corgea npm <leading flags> <verb> <pkg>no longer runs npm unchecked when npm would read the flags differently from the gate.trueorfalseafter any bare flag as that flag's value, and npm readsnullafter a[null, Boolean]flag (--yes,--workspaces).corgea npm --yes null install xnow gatesx.corgea npm --yes true install xnow gatesx, andcorgea npm --yes true exec xroutes likecorgea npm exec x.--package x). npm hands path, url and array flags the next token even when it looks like a flag (npm --package --registry install xsetspackage=--registryand installsx), so a dash token forks the reading too, after both unknown and known value flags. uv's clap parser rejects a dash value (error: a value is required for '--directory <DIRECTORY>'), so for uv the fork only over-blocks. When that other reading reaches an install,ciorexecverb, the command is one unverifiable target: it blocks under fail-closed, warns and runs in fail-open mode, and runs under--force.corgea npm --package x install yand--package x exec yno longer run unchecked.Why
find_subcommandrouted on the first non-flag word, skipping a value only for flags inparse::takes_value. npm's parser (nopt) disagrees in two ways, and each disagreement sent an install to the ungated passthrough even withinstall_gate_fail_closedon. The npm shim calls the same code, so it had the same hole.Growing the npm flag list would close today's two cases and reopen on the next string flag npm adds. Instead the walk follows every reading a flag of unknown arity allows and refuses when one of them reaches a gated verb, so the hole stays closed without a list of npm value flags. It adds two lists of flags that never take a value, one for npm and one for uv, so common booleans do not fork. An entry that takes a value would reopen the hole. A missing entry makes the command unverifiable: it blocks under fail-closed, and in the default fail-open mode it warns and runs unchecked where main may have gated it (
uv --some-unlisted-bool pip install x). uv rejects unknown flags, so its list only has to cover uv's own global booleans. Every entry was checked against uv 0.13.12 to take no value, but no one checked that the list is complete.Invariants
--loglevel silent install x,--version,-- install x,--silent install x,-g install x,-s run ci,--package=x install y.What can go wrong
npm --unknown-flag install add). Common npm booleans (-s,-g,-D,--if-present, …) are listed inNPM_BOOLEANS(read byis_boolean_flag) and never fork, sonpm -s run cistill runs theciscript. A missing flag makes such a command unverifiable: it blocks fail-closed, and warns and runs unchecked fail-open. A flag that takes a value must never be added to the list.npm --yes true install x(and--yes null install x) also looks up a package namedtrue(ornull), becauseparse.rsreads a word after an unknown flag as a spec. It never under-checks, but under fail-closed a failed lookup oftrueover-blocks.trueafter a flag (bun --silent true pm bin→Script not found "true", bun 1.4.5), sobun --silent true install xis unverifiable. pnpm 12.25.1 does (pnpm --frozen-lockfile true rootprints the root). yarn was not installed to probe; it goes through the same fork rule.find_subcommand, so the fix covers them too. Fail-closed probes against fake binaries:pnpm --package x add y,bun --package x add y,yarn --package x add y,pip --resume-retries 3 install yandpip --package x install yall spawned unchecked on main and block on this branch.parse::uv_subcommand), now a thin wrapper overfind_subcommand, used both before uv's subcommand and betweenpipand its verb.uv --python-preference only-system add y(a real uv flag missing fromtakes_value) ran unchecked on main and blocks here. The listed uv booleans (-q,-qq,--offline,--no-color, …) never fork, souv --quiet pip install xgates as before.pipcounts as a gated uv verb whatever follows, souv --python-preference only-system pip listalso blocks under fail-closed.Compatibility
No config or migration. Merges cleanly with #229 (
git merge-tree --write-treeagainst #229 head fe61ef9 exits 0; the merged tree was not built).is_gated_verbalready counts npmexec/x, so its gated exec stays covered.Validation
Built binary, fail-closed on, fake
npmthat records its argv, registry and vuln-api on a closed local port:corgea npm --yes true install zzevilnpm --yes true install zzevilzzevil, exit 1, only the lockfile-only resolution runcorgea npm --package x install zzevil--package x, exit 1, nothing spawnedcorgea npm --package x exec zzevil--package x, exit 1, nothing spawnedcorgea npm --package --registry install zzevil--package --registry, exit 1, nothing spawnedcorgea npm --yes true exec zzeviltrue)exec, which main passes through ungated. This case closes with #229, whose exec grammar reports it as unverifiable (read from #229's code, not run)npm --package x install zzevilvia the bash shimcorgea uv --python-preference only-system add zzevilcorgea uv pip --python-preference only-system install zzevilNot in this PR
parse.rschanges onlyuv_subcommand(now a wrapper overfind_subcommand) and addsUvCommand::Ambiguous;--packageis not added totakes_value, to stay clear of Gate npx and npm exec on vuln verdicts before the package runs #229's exec grammar. Until it is,npm --package x exec yblocks under fail-closed whilenpm exec --package=x ypasses through on main; Gate npx and npm exec on vuln verdicts before the package runs #229 gates exec.true/nullspec for trailingnpm install --yes true xpredates this PR and lives inparse.rs.