Skip to content

fix(gate): refuse npx <bin> when the bin is another package's npm name - #1111

Merged
sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-npx-bin-name
Nov 27, 2026
Merged

sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-npx-bin-name

Conversation

@sandstream

@sandstream sandstream commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Protected: this touches the install gate. It is the owner's to merge.

Found by kit-research note metaharness-artex-defense-vs-kit: gate-bash allows npx redblue init with exit 0. redblue is a bin of @metaharness/redblue. Without a local install, npx fetches the unrelated unscoped redblue (2017, another maintainer). npx artex-defense was blocked only because that unscoped name is unclaimed.

What changes

  • kit triage npm (src/triage-npm-bins.ts, run after the cooling check in runTriage): for each bin of the triaged version whose name differs from the package's own name, it makes one registry GET on the unscoped name. The result is one of three states:

    • same: an info line, no fetch.
    • unclaimed (404): a warning.
    • other: a warning with the owner's version, maintainers and creation date.

    It honours KIT_NPM_REGISTRY and air-gap (prints NOT CHECKED, never a clean line) and reads at most 10 bins. It reuses fetchRegistryDoc and registrySource from triage-cooling.ts; fetchJson now wraps fetchRegistryDoc so a 404 can be told apart from a failure. The package's own verdict is unchanged. The warnings count toward the score the same way cooling lines do.

  • Receipt: other and unclaimed are appended to .kit-triage.jsonl as type: "npm-bin" records whatever the verdict. Both scoped packages in the note were HELD by cooling, so a PASS-only receipt would never have reached the gate. PASS readers (check-deps, bare-install, allowScripts cross-check, skill gate) filter by npm/pip/skill and skip these records. usage-report counts them under their own type. They are written by the CLI, the MCP kit_triage tool and gateInstall (new optional GateDeps.recordBins; the read-only observation deps have none, so they do not write).

  • gate-bash (src/install-gate-npx-bin.ts; install-gate.ts grows 3 lines, from 1311 to 1314, limit 1339): for a plain npx, npm exec, pnpm dlx, yarn dlx or bunx of an unscoped name that is the fetched ref, it exits 2 when an npm-bin record names it. The message names the scoped package and npx -p @scope/pkg <bin>.

    • A local node_modules/.bin/<bin> still allows the command, decided by the existing shadowedBins, so a cd voids it as before.
    • A kit triage npm <bin> PASS newer than the record also allows it. This is the escape hatch for someone who really means the unscoped package.
    • npm init foo is not read as foo.
    • Names with shell expansion are already refused by the parser as unverifiable; a test pins that.
  • Docs: a new section in docs/INSTALL_GATE.md, the triage npm rows in docs/COMMANDS.md and docs/FEATURES.md, and changes/npx-bin-name.md. No flag-surface change, so the contracts are not regenerated.

Verification

  • New tests, offline with stubbed fetch and example names. 7 gate tests in install-gate-npx-bin.test.ts: 5 of them fail on main's gate. The other 2 are false-positive guards (npx prettier, npx -p @scope/pkg, npm init redblue, expansion fail-closed), and they pass both before and after. 7 triage tests in triage-npm-bins.test.ts, which is a new module. After the change, all 14 pass. 257 net new test lines (cap 400).
  • node --test over install-gate*, triage*, mcp-server, commands/triage, changelog-fragments and gate-bash-refusal: 1577/1577 pass.
  • node dist/cli.js adr check: 4 enforced ADRs, no new violations. No new dependency, no model call.
  • scripts/prepush.mjs --allow "enforcement gate liveness": everything passes except the known local-only kit review --enforce (no gh auth or jscpd/scc/hadolint here) and Semgrep (not installed).
  • End-to-end against the live registry in an empty directory:
    • Before triage, npx redblue init → exit 0.
    • After kit triage npm @metaharness/redblue, it → exit 2 ("the npm name 'redblue' is another package (redblue@0.0.1, maintainers , created 2017-10-30)").
    • npx artex-defense → exit 2 (unclaimed).
    • npx prettier --version → exit 0.

Limits

  • Without a record, nothing changes. If no one has triaged the scoped package in this directory, the gate cannot know a README meant it.
  • Records do not expire. A stale record can only block, and the message gives the scoped way round.
  • The gate reads records from the hook's cwd, as with other receipts.
  • The pnpm dlx and yarn dlx local-bin allow uses the existing shadow rule unchanged.
  • Cross-platform: paths use node:path. The local-bin test writes both <bin> and <bin>.cmd, so it holds on Windows CI. macOS is unverified, since no CI job runs it.

Generated by Claude Code

`@metaharness/redblue` ships a bin `redblue`. Without a local install,
`npx redblue init` fetches the unrelated unscoped `redblue` (2017, another
maintainer), and gate-bash allowed it with exit 0. `artex-defense` is an
unclaimed name that the gate blocked only because it does not exist yet.

kit triage npm now reads the triaged version's `bin` and asks the
registry about each bin whose name is not the package's own: `same`,
`unclaimed` (404) or `other` (owner's version, maintainers, created). The
last two print a warning and an `npm-bin` record in .kit-triage.jsonl,
whatever the verdict. gate-bash refuses npx / npm exec / pnpm dlx /
yarn dlx / bunx of such a name and names the scoped package, or
`npx -p @scope/pkg <bin>`. A local bin, or a newer PASS for the unscoped
name, still allows it. New modules: triage-npm-bins.ts,
install-gate-npx-bin.ts; install-gate.ts grows by 3 lines.

Found by kit-research metaharness-artex-defense-vs-kit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer Bot 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.

kit review gate at dd418ee2931c: not approved.

  • checks did not pass: build-and-test, checks (format, lint, build, gates)
  • touches protected paths (permissions), which the owner approves: src/install-gate-npx-bin.test.ts, src/install-gate-npx-bin.ts, src/install-gate.ts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer Bot 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.

kit review gate at 517d53a425c1: not approved.

  • touches protected paths (permissions), which the owner approves: src/install-gate-npx-bin.test.ts, src/install-gate-npx-bin.ts, src/install-gate.ts

@sandstream
sandstream merged commit cbbaf70 into main Nov 27, 2026
33 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a-protected-npx-bin-name branch November 27, 2026 11:27
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.

2 participants