Skip to content

fix(kimi-code): close pre-trust-gate bare command resolution on Windows - #2695

Open
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:fix/windows-pre-trust-bare-command
Open

fix(kimi-code): close pre-trust-gate bare command resolution on Windows#2695
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:fix/windows-pre-trust-bare-command

Conversation

@sailist

@sailist sailist commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

On Windows, cmd.exe / CreateProcess resolve a bare command name from the current directory before PATH. Several child processes on the CLI startup path ran before the workspace trust prompt, so a binary planted in an untrusted workspace (stty.exe, npm.cmd, fd.exe) could be executed before the user ever confirmed trust — defeating the purpose of the trust gate:

  • stty -g / stty -ixon in run-shell.ts, unconditional at startup
  • fd --version detection in the KimiTUI field initializer
  • update-preflight package-manager spawns (npm/pnpm/yarn/bun/brew, shell: true on win32) and the npm prefix -g probe

Additionally, the migration branch (pending ~/.kimi migration) skipped the workspace trust prompt entirely.

What changed

  • run-shell.ts: skip the POSIX-only stty save/restore entirely on win32 (it never worked there; the failure was swallowed by catch).
  • kimi-tui.ts: fd detection moved from the constructor field initializer to startBackgroundFdAutocomplete(), which only runs after the trust gate; the trust prompt now also runs before the migration branch.
  • New src/utils/process/resolve-command.ts: resolveCommandPath() resolves a bare command name through PATH (PATHEXT-aware on win32) to an absolute path and refuses hits inside the cwd, since executing those would run whatever a malicious workspace planted there. Callers spawn the absolute path, so cmd.exe never searches the cwd.
  • update/preflight.ts / update/source.ts: update installs and the npm global-prefix probe go through resolveCommandPath; unresolvable commands degrade through the existing failure paths instead of spawning a bare name.
  • apps/kimi-code/AGENTS.md: documented the rule — no bare-command-name child processes before the trust gate; use resolveCommandPath.
  • Tests: new resolve-command.test.ts (PATH hit, exec-bit, cwd/subdirectory refusal, win32 PATHEXT), plus updated preflight/source/run-shell/kimi-tui-startup tests.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

On Windows, cmd.exe / CreateProcess resolve a bare command name from the
current directory before PATH. Several startup-path child processes ran
before the workspace trust prompt, so a binary planted in an untrusted
workspace (stty.exe, npm.cmd, fd.exe) could execute before the user
confirmed trust.

- skip the POSIX-only stty save/restore entirely on win32
- defer fd detection from the KimiTUI field initializer to
  startBackgroundFdAutocomplete(), which runs after the trust gate
- add resolveCommandPath(): resolve commands through PATH (PATHEXT-aware
  on win32) to an absolute path and refuse hits inside the cwd
- route update-preflight package-manager spawns and the npm global-prefix
  probe through it
- run the workspace trust prompt before the migration branch as well,
  closing the blind spot where a pending ~/.kimi migration skipped it
- document the no-bare-command-before-trust-gate rule in
  apps/kimi-code/AGENTS.md
@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 958f23e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@958f23e
npx https://pkg.pr.new/@moonshot-ai/kimi-code@958f23e

commit: 958f23e

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.

1 participant