fix(kimi-code): close pre-trust-gate bare command resolution on Windows - #2695
Open
sailist wants to merge 1 commit into
Open
fix(kimi-code): close pre-trust-gate bare command resolution on Windows#2695sailist wants to merge 1 commit into
sailist wants to merge 1 commit into
Conversation
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 detectedLatest commit: 958f23e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
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.
Related Issue
No linked issue — the problem is explained below.
Problem
On Windows,
cmd.exe/CreateProcessresolve 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 -ixoninrun-shell.ts, unconditional at startupfd --versiondetection in theKimiTUIfield initializernpm/pnpm/yarn/bun/brew,shell: trueon win32) and thenpm prefix -gprobeAdditionally, the migration branch (pending
~/.kimimigration) skipped the workspace trust prompt entirely.What changed
run-shell.ts: skip the POSIX-onlysttysave/restore entirely on win32 (it never worked there; the failure was swallowed bycatch).kimi-tui.ts:fddetection moved from the constructor field initializer tostartBackgroundFdAutocomplete(), which only runs after the trust gate; the trust prompt now also runs before the migration branch.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 throughresolveCommandPath; 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; useresolveCommandPath.resolve-command.test.ts(PATH hit, exec-bit, cwd/subdirectory refusal, win32 PATHEXT), plus updated preflight/source/run-shell/kimi-tui-startup tests.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.