@wonderwhy-er/desktop-commander 0.3.2-alpha.3 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command-manager.d.ts +4 -4
- package/dist/command-manager.js +58 -21
- package/dist/remote-device/device-authenticator.js +2 -0
- package/dist/remote-device/device.d.ts +2 -1
- package/dist/remote-device/device.js +46 -29
- package/dist/remote-device/remote-channel.js +1 -1
- package/dist/remote-device/remote-utils.d.ts +20 -0
- package/dist/remote-device/remote-utils.js +79 -5
- package/dist/remote-device/rollouts.js +1 -0
- package/dist/ui/config-editor/config-editor-runtime.js +80 -61
- package/dist/ui/file-preview/preview-runtime.js +226 -215
- package/dist/utils/brace-expansion.d.ts +6 -1
- package/dist/utils/brace-expansion.js +33 -12
- package/dist/utils/cmd-commands.d.ts +2 -2
- package/dist/utils/cmd-commands.js +57 -9
- package/dist/utils/command-reading.d.ts +17 -3
- package/dist/utils/command-reading.js +8 -1
- package/dist/utils/command-wrappers.d.ts +3 -3
- package/dist/utils/command-wrappers.js +37 -14
- package/dist/utils/inline-shells.d.ts +5 -2
- package/dist/utils/inline-shells.js +30 -10
- package/dist/utils/posix-commands.d.ts +5 -2
- package/dist/utils/posix-commands.js +68 -32
- package/dist/utils/posix-shell-capabilities.d.ts +8 -0
- package/dist/utils/posix-shell-capabilities.js +120 -0
- package/dist/utils/powershell-commands.d.ts +2 -1
- package/dist/utils/powershell-commands.js +54 -6
- package/dist/utils/shell-script-files.d.ts +5 -1
- package/dist/utils/shell-script-files.js +38 -19
- package/dist/utils/shell.d.ts +4 -3
- package/dist/utils/shell.js +9 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/bootstrap.js.map +0 -1
- package/dist/command-manager.js.map +0 -1
- package/dist/config-field-definitions.js.map +0 -1
- package/dist/config-manager.js.map +0 -1
- package/dist/config-recovery.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/custom-stdio.js.map +0 -1
- package/dist/error-handlers.js.map +0 -1
- package/dist/handlers/edit-search-handlers.js.map +0 -1
- package/dist/handlers/filesystem-handlers.js.map +0 -1
- package/dist/handlers/history-handlers.js.map +0 -1
- package/dist/handlers/index.js.map +0 -1
- package/dist/handlers/process-handlers.js.map +0 -1
- package/dist/handlers/search-answers.js.map +0 -1
- package/dist/handlers/search-handlers.js.map +0 -1
- package/dist/handlers/terminal-handlers.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/npm-scripts/remote.js.map +0 -1
- package/dist/npm-scripts/setup.js.map +0 -1
- package/dist/npm-scripts/uninstall.js.map +0 -1
- package/dist/npm-scripts/verify-ripgrep.js.map +0 -1
- package/dist/remote-device/desktop-commander-integration.js.map +0 -1
- package/dist/remote-device/device-authenticator.js.map +0 -1
- package/dist/remote-device/device.js.map +0 -1
- package/dist/remote-device/diagnostics/device-log.js.map +0 -1
- package/dist/remote-device/diagnostics/redact.js.map +0 -1
- package/dist/remote-device/diagnostics/report.js.map +0 -1
- package/dist/remote-device/diagnostics/upload.js.map +0 -1
- package/dist/remote-device/mqtt/config.js.map +0 -1
- package/dist/remote-device/mqtt/mqtt-enrollment.js.map +0 -1
- package/dist/remote-device/mqtt/mqtt-transport.js.map +0 -1
- package/dist/remote-device/realtime-health-telemetry.js.map +0 -1
- package/dist/remote-device/remote-channel.js.map +0 -1
- package/dist/remote-device/remote-utils.js.map +0 -1
- package/dist/remote-device/rollouts.js.map +0 -1
- package/dist/remote-device/transport-telemetry.js.map +0 -1
- package/dist/search-manager.js.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/terminal-manager.js.map +0 -1
- package/dist/tools/config.js.map +0 -1
- package/dist/tools/edit.js.map +0 -1
- package/dist/tools/feedback.js.map +0 -1
- package/dist/tools/filesystem.js.map +0 -1
- package/dist/tools/fuzzySearch.js.map +0 -1
- package/dist/tools/fuzzySearchCore.js.map +0 -1
- package/dist/tools/improved-process-tools.js.map +0 -1
- package/dist/tools/mime-types.js.map +0 -1
- package/dist/tools/pdf/extract-images.js.map +0 -1
- package/dist/tools/pdf/index.js.map +0 -1
- package/dist/tools/pdf/lib/pdf2md.js.map +0 -1
- package/dist/tools/pdf/manipulations.js.map +0 -1
- package/dist/tools/pdf/markdown.js.map +0 -1
- package/dist/tools/pdf/utils.js.map +0 -1
- package/dist/tools/process.js.map +0 -1
- package/dist/tools/prompts.js.map +0 -1
- package/dist/tools/schemas.js.map +0 -1
- package/dist/tools/usage.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/ui/config-editor/src/app.js.map +0 -1
- package/dist/ui/config-editor/src/array-modal.js.map +0 -1
- package/dist/ui/config-editor/src/main.js.map +0 -1
- package/dist/ui/contracts.js.map +0 -1
- package/dist/ui/file-preview/shared/preview-file-types.js.map +0 -1
- package/dist/ui/file-preview/src/app.js.map +0 -1
- package/dist/ui/file-preview/src/components/code-viewer.js.map +0 -1
- package/dist/ui/file-preview/src/components/highlighting.js.map +0 -1
- package/dist/ui/file-preview/src/components/html-renderer.js.map +0 -1
- package/dist/ui/file-preview/src/components/markdown-renderer.js.map +0 -1
- package/dist/ui/file-preview/src/directory-controller.js.map +0 -1
- package/dist/ui/file-preview/src/document-layout.js.map +0 -1
- package/dist/ui/file-preview/src/document-outline.js.map +0 -1
- package/dist/ui/file-preview/src/document-workspace.js.map +0 -1
- package/dist/ui/file-preview/src/file-type-handlers.js.map +0 -1
- package/dist/ui/file-preview/src/host/external-actions.js.map +0 -1
- package/dist/ui/file-preview/src/host/selection-context.js.map +0 -1
- package/dist/ui/file-preview/src/image-preview.js.map +0 -1
- package/dist/ui/file-preview/src/main.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/controller.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/editor.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/linking.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/outline.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/parser.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/preview.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/slugify.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/utils.js.map +0 -1
- package/dist/ui/file-preview/src/model.js.map +0 -1
- package/dist/ui/file-preview/src/panel-actions.js.map +0 -1
- package/dist/ui/file-preview/src/path-utils.js.map +0 -1
- package/dist/ui/file-preview/src/payload-utils.js.map +0 -1
- package/dist/ui/file-preview/src/types.js.map +0 -1
- package/dist/ui/resources.js.map +0 -1
- package/dist/ui/shared/compact-row.js.map +0 -1
- package/dist/ui/shared/escape-html.js.map +0 -1
- package/dist/ui/shared/host-context.js.map +0 -1
- package/dist/ui/shared/tool-bridge.js.map +0 -1
- package/dist/ui/shared/tool-shell.js.map +0 -1
- package/dist/ui/shared/ui-event-tracker.js.map +0 -1
- package/dist/ui/shared/widget-state.js.map +0 -1
- package/dist/utils/ab-test.js.map +0 -1
- package/dist/utils/atomic-write.js.map +0 -1
- package/dist/utils/capture.js.map +0 -1
- package/dist/utils/dockerPrompt.js.map +0 -1
- package/dist/utils/exit-process.js.map +0 -1
- package/dist/utils/feature-flags.js.map +0 -1
- package/dist/utils/files/base.js.map +0 -1
- package/dist/utils/files/binary.js.map +0 -1
- package/dist/utils/files/docx.js.map +0 -1
- package/dist/utils/files/excel.js.map +0 -1
- package/dist/utils/files/factory.js.map +0 -1
- package/dist/utils/files/image.js.map +0 -1
- package/dist/utils/files/index.js.map +0 -1
- package/dist/utils/files/pdf.js.map +0 -1
- package/dist/utils/files/text.js.map +0 -1
- package/dist/utils/fuzzySearchLogger.js.map +0 -1
- package/dist/utils/internal-facts.js.map +0 -1
- package/dist/utils/lazy-package.js.map +0 -1
- package/dist/utils/lineEndingHandler.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/mcp-ui-ab-test.js.map +0 -1
- package/dist/utils/open-browser.js.map +0 -1
- package/dist/utils/process-detection.js.map +0 -1
- package/dist/utils/process-tree.js.map +0 -1
- package/dist/utils/rename.js.map +0 -1
- package/dist/utils/ripgrep-resolver.js.map +0 -1
- package/dist/utils/shell.js.map +0 -1
- package/dist/utils/system-info.js.map +0 -1
- package/dist/utils/terminal-timestamps.js.map +0 -1
- package/dist/utils/toolHistory.js.map +0 -1
- package/dist/utils/trackTools.js.map +0 -1
- package/dist/utils/unsupportedParams.js.map +0 -1
- package/dist/utils/usageTracker.js.map +0 -1
- package/dist/utils/welcome-onboarding.js.map +0 -1
- package/dist/utils/withTimeout.js.map +0 -1
- package/dist/version.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CommandReadOptions, type CommandReading } from './utils/command-reading.js';
|
|
2
2
|
/**
|
|
3
3
|
* The check's answer for one command.
|
|
4
4
|
* - allowed: no blocked program runs.
|
|
@@ -43,7 +43,7 @@ declare class CommandManager {
|
|
|
43
43
|
* bash reader, and where that can't parse fish's own syntax (for … end,
|
|
44
44
|
* echo (date)), as main reads it: by the names extractCommands() finds.
|
|
45
45
|
*/
|
|
46
|
-
readCommands(command: string, shell: string): Promise<CommandReading>;
|
|
46
|
+
readCommands(command: string, shell: string, options?: CommandReadOptions): Promise<CommandReading>;
|
|
47
47
|
/**
|
|
48
48
|
* The commands of a reading that run a program: the calls to the script's
|
|
49
49
|
* own functions are left out. A script can define a function with a
|
|
@@ -63,7 +63,7 @@ declare class CommandManager {
|
|
|
63
63
|
* - a program chosen only when the command runs: a name that is a variable
|
|
64
64
|
* or another command's output (& $tool), or eval and Invoke-Expression,
|
|
65
65
|
* which run text the command builds (eval "$CMD");
|
|
66
|
-
* - a script file given to a shell (bash deploy.sh): the commands in it
|
|
66
|
+
* - a script file given to a shell (bash deploy.sh, or forwarded by runuser): the commands in it
|
|
67
67
|
* aren't in the text. A file named only when the command runs ("$SCRIPT")
|
|
68
68
|
* counts as a program chosen at run time, named by the shell.
|
|
69
69
|
*/
|
|
@@ -90,7 +90,7 @@ declare class CommandManager {
|
|
|
90
90
|
* error or a missing PowerShell is allowed instead: nothing runs, and
|
|
91
91
|
* PowerShell or start_process answers.
|
|
92
92
|
*/
|
|
93
|
-
checkCommand(command: string, shell: string): Promise<CommandCheck>;
|
|
93
|
+
checkCommand(command: string, shell: string, options?: CommandReadOptions): Promise<CommandCheck>;
|
|
94
94
|
/**
|
|
95
95
|
* checkCommand() for a command, or for a command text in it: each text is
|
|
96
96
|
* checked once per command in each shell, however many readings give it.
|
package/dist/command-manager.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import { configManager } from './config-manager.js';
|
|
3
4
|
import { capture } from "./utils/capture.js";
|
|
4
|
-
import { getShellType, isShellAvailable, programName } from './utils/shell.js';
|
|
5
|
+
import { getShellType, isShellAvailable, programName, resolveShellPath } from './utils/shell.js';
|
|
5
6
|
import { sameShellTexts, shellRuns } from './utils/inline-shells.js';
|
|
6
7
|
import { shellScriptFiles } from './utils/shell-script-files.js';
|
|
7
8
|
import { readPosixCommands } from './utils/posix-commands.js';
|
|
8
9
|
import { readPowerShellCommands } from './utils/powershell-commands.js';
|
|
9
10
|
import { readCmdCommands } from './utils/cmd-commands.js';
|
|
10
11
|
import { withStartedPrograms } from './utils/command-wrappers.js';
|
|
12
|
+
import { IncompleteArgumentsError, requireCompleteArguments } from './utils/command-reading.js';
|
|
11
13
|
class CommandManager {
|
|
12
14
|
getBaseCommand(command) {
|
|
13
15
|
return command.split(' ')[0].toLowerCase().trim();
|
|
@@ -224,14 +226,24 @@ class CommandManager {
|
|
|
224
226
|
* bash reader, and where that can't parse fish's own syntax (for … end,
|
|
225
227
|
* echo (date)), as main reads it: by the names extractCommands() finds.
|
|
226
228
|
*/
|
|
227
|
-
async readCommands(command, shell) {
|
|
229
|
+
async readCommands(command, shell, options = {}) {
|
|
228
230
|
switch (getShellType(shell)) {
|
|
229
231
|
case 'powershell':
|
|
230
232
|
return readPowerShellCommands(command, shell);
|
|
231
233
|
case 'cmd':
|
|
232
|
-
return readCmdCommands(command);
|
|
234
|
+
return readCmdCommands(command, options);
|
|
233
235
|
}
|
|
234
|
-
|
|
236
|
+
// Resolve the actual caller selection, not the adapter's anchored launch alias.
|
|
237
|
+
// Only filesystem identity is read here; unknown endpoints keep the legacy reading.
|
|
238
|
+
let selectedEndpoint;
|
|
239
|
+
const selected = resolveShellPath(shell);
|
|
240
|
+
if (selected !== null) {
|
|
241
|
+
try {
|
|
242
|
+
selectedEndpoint = fs.realpathSync(selected);
|
|
243
|
+
}
|
|
244
|
+
catch { /* Missing identity stays unsupported. */ }
|
|
245
|
+
}
|
|
246
|
+
const reading = await readPosixCommands(command, selectedEndpoint);
|
|
235
247
|
// fish's name, as getShellSpawnArgs() finds it
|
|
236
248
|
if (reading.parseError === undefined || !path.basename(shell).toLowerCase().includes('fish'))
|
|
237
249
|
return reading;
|
|
@@ -272,7 +284,7 @@ class CommandManager {
|
|
|
272
284
|
* - a program chosen only when the command runs: a name that is a variable
|
|
273
285
|
* or another command's output (& $tool), or eval and Invoke-Expression,
|
|
274
286
|
* which run text the command builds (eval "$CMD");
|
|
275
|
-
* - a script file given to a shell (bash deploy.sh): the commands in it
|
|
287
|
+
* - a script file given to a shell (bash deploy.sh, or forwarded by runuser): the commands in it
|
|
276
288
|
* aren't in the text. A file named only when the command runs ("$SCRIPT")
|
|
277
289
|
* counts as a program chosen at run time, named by the shell.
|
|
278
290
|
*/
|
|
@@ -283,8 +295,14 @@ class CommandManager {
|
|
|
283
295
|
unseen.push({ what: cmd.name, inFile: false });
|
|
284
296
|
continue;
|
|
285
297
|
}
|
|
286
|
-
|
|
287
|
-
|
|
298
|
+
const files = this.scriptFiles(cmd, shellType);
|
|
299
|
+
unseen.push(...files);
|
|
300
|
+
const run = shellRuns(cmd, shellType);
|
|
301
|
+
// A text-program shell can identify a script that the ordinary file reader does not handle.
|
|
302
|
+
if (files.length === 0 && run.shell !== undefined && typeof run.file === 'string') {
|
|
303
|
+
unseen.push({ what: run.file, inFile: true });
|
|
304
|
+
}
|
|
305
|
+
const unknown = sameShellTexts(cmd, shellType).file === null || run.file === null;
|
|
288
306
|
if (unknown && !unseen.some((item) => item.what === cmd.name && !item.inFile)) {
|
|
289
307
|
unseen.push({ what: cmd.name, inFile: false });
|
|
290
308
|
}
|
|
@@ -306,18 +324,23 @@ class CommandManager {
|
|
|
306
324
|
return file === null ? { what: cmd.name, inFile: false } : { what: file, inFile: true };
|
|
307
325
|
};
|
|
308
326
|
if (shellType === 'posix' && (program === 'source' || program === '.')) {
|
|
327
|
+
requireCompleteArguments(cmd);
|
|
309
328
|
return args[0] === undefined ? [] : [hidden(args[0])];
|
|
310
329
|
}
|
|
311
330
|
// PowerShell runs a .ps1 named as the command (./deploy.ps1, & ./deploy.ps1) as a script file
|
|
312
331
|
if (shellType === 'powershell' && /\.ps1$/i.test(cmd.name)) {
|
|
332
|
+
requireCompleteArguments(cmd);
|
|
313
333
|
return [hidden(cmd.name)];
|
|
314
334
|
}
|
|
315
335
|
// PowerShell text and file modes use the same host-option readings.
|
|
316
336
|
if (getShellType(cmd.name) === 'powershell') {
|
|
317
|
-
const file = shellRuns(cmd).file;
|
|
337
|
+
const file = shellRuns(cmd, shellType).file;
|
|
318
338
|
return file === undefined ? [] : [hidden(file)];
|
|
319
339
|
}
|
|
320
|
-
return shellScriptFiles(program, args
|
|
340
|
+
return shellScriptFiles(program, args, {
|
|
341
|
+
written: cmd.written.slice(1),
|
|
342
|
+
...(cmd.argumentError === undefined ? {} : { argumentError: cmd.argumentError }),
|
|
343
|
+
}).map(hidden);
|
|
321
344
|
}
|
|
322
345
|
/**
|
|
323
346
|
* The check's answer for `command` run by `shell`:
|
|
@@ -332,8 +355,8 @@ class CommandManager {
|
|
|
332
355
|
* error or a missing PowerShell is allowed instead: nothing runs, and
|
|
333
356
|
* PowerShell or start_process answers.
|
|
334
357
|
*/
|
|
335
|
-
checkCommand(command, shell) {
|
|
336
|
-
return this.checkText(command, shell, new Map());
|
|
358
|
+
checkCommand(command, shell, options = {}) {
|
|
359
|
+
return this.checkText(command, shell, new Map(), options);
|
|
337
360
|
}
|
|
338
361
|
/**
|
|
339
362
|
* checkCommand() for a command, or for a command text in it: each text is
|
|
@@ -341,16 +364,19 @@ class CommandManager {
|
|
|
341
364
|
* In pwsh $a pwsh $a … each text gives every later one again, so without
|
|
342
365
|
* this the work doubled with each pair.
|
|
343
366
|
*/
|
|
344
|
-
checkText(command, shell, checked) {
|
|
345
|
-
const
|
|
367
|
+
checkText(command, shell, checked, options) {
|
|
368
|
+
const optionsForShell = {
|
|
369
|
+
cmdDelayedExpansion: getShellType(shell) === 'cmd' ? options.cmdDelayedExpansion ?? 'unknown' : 'unknown',
|
|
370
|
+
};
|
|
371
|
+
const key = `${shell}\0${optionsForShell.cmdDelayedExpansion}\0${command}`;
|
|
346
372
|
let check = checked.get(key);
|
|
347
373
|
if (check === undefined) {
|
|
348
|
-
check = this.checkOnce(command, shell, checked);
|
|
374
|
+
check = this.checkOnce(command, shell, checked, optionsForShell);
|
|
349
375
|
checked.set(key, check);
|
|
350
376
|
}
|
|
351
377
|
return check;
|
|
352
378
|
}
|
|
353
|
-
async checkOnce(command, shell, checked) {
|
|
379
|
+
async checkOnce(command, shell, checked, options) {
|
|
354
380
|
try {
|
|
355
381
|
const config = await configManager.getConfig();
|
|
356
382
|
const blockedCommands = config.blockedCommands || [];
|
|
@@ -358,7 +384,8 @@ class CommandManager {
|
|
|
358
384
|
// PowerShell runs nothing when it isn't there or can't parse the command: it, or start_process, answers
|
|
359
385
|
if (shellType === 'powershell' && !isShellAvailable(shell))
|
|
360
386
|
return { verdict: 'allowed' };
|
|
361
|
-
const
|
|
387
|
+
const { cmdDelayedExpansion } = options;
|
|
388
|
+
const reading = await this.readCommands(command, shell, options);
|
|
362
389
|
// A parse error is the command's fault, not the server's, so it isn't logged or sent
|
|
363
390
|
if (reading.parseError !== undefined) {
|
|
364
391
|
return shellType === 'powershell'
|
|
@@ -381,20 +408,28 @@ class CommandManager {
|
|
|
381
408
|
let unreadable;
|
|
382
409
|
for (const found of running) {
|
|
383
410
|
unseen.push(...this.findUnseen([found], shellType));
|
|
384
|
-
const run = shellRuns(found);
|
|
411
|
+
const run = shellRuns(found, shellType);
|
|
385
412
|
const texts = [
|
|
386
|
-
...sameShellTexts(found, shellType).texts.map((text) => ({
|
|
413
|
+
...sameShellTexts(found, shellType).texts.map((text) => ({
|
|
414
|
+
text,
|
|
415
|
+
runs: shell,
|
|
416
|
+
cmdDelayedExpansion,
|
|
417
|
+
})),
|
|
387
418
|
// su -c's text runs in sh, runas's command line as cmd reads it
|
|
388
|
-
...run.texts.map((text) => ({
|
|
419
|
+
...run.texts.map((text) => ({
|
|
420
|
+
text,
|
|
421
|
+
runs: run.shell ?? found.name,
|
|
422
|
+
cmdDelayedExpansion: run.cmdDelayedExpansion ?? 'unknown',
|
|
423
|
+
})),
|
|
389
424
|
];
|
|
390
|
-
for (const { text, runs } of texts) {
|
|
425
|
+
for (const { text, runs, cmdDelayedExpansion: innerMode } of texts) {
|
|
391
426
|
// The shell that runs the command looks a PowerShell's name up itself, in its working folder
|
|
392
427
|
// too: one the check can't find is read by the PowerShell running the command, when that is one
|
|
393
428
|
const reader = getShellType(runs) !== 'powershell' ? runs
|
|
394
429
|
: [runs, shell].find((candidate) => getShellType(candidate) === 'powershell' && isShellAvailable(candidate));
|
|
395
430
|
const inner = reader === undefined
|
|
396
431
|
? { verdict: 'failed', reason: `${runs} isn't installed here, so the command given to it can't be read` }
|
|
397
|
-
: await this.checkText(text, reader, checked);
|
|
432
|
+
: await this.checkText(text, reader, checked, { cmdDelayedExpansion: innerMode });
|
|
398
433
|
if (inner.verdict === 'blocked')
|
|
399
434
|
return inner;
|
|
400
435
|
if (inner.verdict === 'failed')
|
|
@@ -408,6 +443,8 @@ class CommandManager {
|
|
|
408
443
|
return unseen.length > 0 ? { verdict: 'unseen', unseen } : { verdict: 'allowed' };
|
|
409
444
|
}
|
|
410
445
|
catch (error) {
|
|
446
|
+
if (error instanceof IncompleteArgumentsError)
|
|
447
|
+
return { verdict: 'failed', reason: error.message };
|
|
411
448
|
const reason = error instanceof Error ? error.message : String(error);
|
|
412
449
|
console.error('Error validating command:', error);
|
|
413
450
|
capture('server_validate_command_error', {
|
|
@@ -40,6 +40,7 @@ export class DeviceAuthenticator {
|
|
|
40
40
|
try {
|
|
41
41
|
response = await this.fetchFn(`${this.baseServerUrl}/device/start`, {
|
|
42
42
|
method: 'POST',
|
|
43
|
+
redirect: 'error',
|
|
43
44
|
headers: { 'Content-Type': 'application/json' },
|
|
44
45
|
body: JSON.stringify({
|
|
45
46
|
client_id: CLIENT_ID,
|
|
@@ -116,6 +117,7 @@ export class DeviceAuthenticator {
|
|
|
116
117
|
try {
|
|
117
118
|
response = await this.fetchFn(`${this.baseServerUrl}/device/poll`, {
|
|
118
119
|
method: 'POST',
|
|
120
|
+
redirect: 'error',
|
|
119
121
|
headers: { 'Content-Type': 'application/json' },
|
|
120
122
|
body: JSON.stringify({
|
|
121
123
|
device_code: deviceAuth.device_code,
|
|
@@ -13,6 +13,7 @@ export declare class MCPDevice {
|
|
|
13
13
|
private deviceId?;
|
|
14
14
|
private isShuttingDown;
|
|
15
15
|
private configPath;
|
|
16
|
+
private trustedAuthContext;
|
|
16
17
|
private persistSession;
|
|
17
18
|
private desktop;
|
|
18
19
|
/**
|
|
@@ -47,7 +48,7 @@ export declare class MCPDevice {
|
|
|
47
48
|
savePersistedConfig(rotated?: AuthSession): Promise<void>;
|
|
48
49
|
private writePersistedConfig;
|
|
49
50
|
fetchSupabaseConfig(): Promise<{
|
|
50
|
-
supabaseUrl:
|
|
51
|
+
supabaseUrl: string;
|
|
51
52
|
anonKey: any;
|
|
52
53
|
}>;
|
|
53
54
|
/**
|
|
@@ -15,7 +15,7 @@ import { observeTransport } from './transport-telemetry.js';
|
|
|
15
15
|
import { startTerminalTimestamps } from '../utils/terminal-timestamps.js';
|
|
16
16
|
import { VERSION } from '../version.js';
|
|
17
17
|
import { rolloutManager } from './rollouts.js';
|
|
18
|
-
import { getRemoteDeviceConfigPath,
|
|
18
|
+
import { DEFAULT_REMOTE_SERVER_URL, getRemoteDeviceConfigPath, savedSessionMatchesContext, validateRemoteAuthContext, validateRemoteServerUrl } from './remote-utils.js';
|
|
19
19
|
export { getRemoteDeviceConfigPath };
|
|
20
20
|
/**
|
|
21
21
|
* How many recently-handled call ids to remember for duplicate-delivery
|
|
@@ -76,14 +76,14 @@ export async function logoutRemoteDevice(configPath = getRemoteDeviceConfigPath(
|
|
|
76
76
|
!config.session?.access_token) {
|
|
77
77
|
throw new Error("No usable saved device session. Revoke this device in the dashboard; local credentials were kept");
|
|
78
78
|
}
|
|
79
|
-
const backend =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
backend.
|
|
85
|
-
|
|
86
|
-
throw new Error("
|
|
79
|
+
const backend = validateRemoteServerUrl(process.env.MCP_SERVER_URL || DEFAULT_REMOTE_SERVER_URL);
|
|
80
|
+
// Logout sends a bearer token too: refuse to send a saved session to
|
|
81
|
+
// a different MCP backend. Only the pinned hosted origin may use an
|
|
82
|
+
// old, unbound device.json from before this security fix.
|
|
83
|
+
if (config.authContext === undefined
|
|
84
|
+
? backend.origin !== DEFAULT_REMOTE_SERVER_URL
|
|
85
|
+
: config.authContext?.serverOrigin !== backend.origin) {
|
|
86
|
+
throw new Error("Saved session belongs to another or unknown backend; credentials were kept");
|
|
87
87
|
}
|
|
88
88
|
const revoke = () => fetch(new URL("/device/revoke", backend), {
|
|
89
89
|
method: "POST",
|
|
@@ -104,13 +104,11 @@ export async function logoutRemoteDevice(configPath = getRemoteDeviceConfigPath(
|
|
|
104
104
|
if (!infoResponse.ok)
|
|
105
105
|
throw new Error("Could not refresh the saved session; credentials were kept");
|
|
106
106
|
const info = await infoResponse.json();
|
|
107
|
-
const
|
|
108
|
-
if ((
|
|
109
|
-
|
|
110
|
-
authUrl.password) {
|
|
111
|
-
throw new Error("Session refresh requires HTTPS or local HTTP; credentials were kept");
|
|
107
|
+
const authContext = validateRemoteAuthContext(backend.origin, info?.supabaseUrl);
|
|
108
|
+
if (!savedSessionMatchesContext(config.authContext, authContext)) {
|
|
109
|
+
throw new Error("Refusing to refresh credentials with a different Supabase backend");
|
|
112
110
|
}
|
|
113
|
-
const client = createClient(
|
|
111
|
+
const client = createClient(authContext.supabaseUrl, info.supabasePublishableKey, {
|
|
114
112
|
auth: {
|
|
115
113
|
persistSession: false,
|
|
116
114
|
autoRefreshToken: false,
|
|
@@ -159,6 +157,7 @@ export async function logoutRemoteDevice(configPath = getRemoteDeviceConfigPath(
|
|
|
159
157
|
}
|
|
160
158
|
export class MCPDevice {
|
|
161
159
|
constructor(options = {}) {
|
|
160
|
+
this.trustedAuthContext = null;
|
|
162
161
|
/**
|
|
163
162
|
* Serialises config writes. Rotations are 45 minutes apart in normal
|
|
164
163
|
* running, but a save that stalls must not land after a newer one and
|
|
@@ -170,7 +169,7 @@ export class MCPDevice {
|
|
|
170
169
|
this.loggedOutLocally = false;
|
|
171
170
|
/** Call ids already handled by THIS process (insertion-ordered, bounded). */
|
|
172
171
|
this.seenCallIds = new Set();
|
|
173
|
-
this.baseServerUrl = process.env.MCP_SERVER_URL ||
|
|
172
|
+
this.baseServerUrl = validateRemoteServerUrl(process.env.MCP_SERVER_URL || DEFAULT_REMOTE_SERVER_URL).origin;
|
|
174
173
|
this.deviceId = undefined;
|
|
175
174
|
this.isShuttingDown = false;
|
|
176
175
|
this.configPath = getRemoteDeviceConfigPath();
|
|
@@ -424,6 +423,14 @@ export class MCPDevice {
|
|
|
424
423
|
return null;
|
|
425
424
|
}
|
|
426
425
|
if (config.session && this.persistSession) {
|
|
426
|
+
if (!this.trustedAuthContext ||
|
|
427
|
+
!savedSessionMatchesContext(config.authContext, this.trustedAuthContext)) {
|
|
428
|
+
// Preserve the old file until new authorization succeeds, but
|
|
429
|
+
// never send its tokens or reuse its device id on this backend.
|
|
430
|
+
console.warn('⚠️ Saved Remote MCP session belongs to another or unknown backend; re-authorization required');
|
|
431
|
+
this.deviceId = undefined;
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
427
434
|
console.log('💾 Found persisted session for device ' + this.deviceId);
|
|
428
435
|
console.debug('[DEBUG] Session found in config, returning session');
|
|
429
436
|
return config.session;
|
|
@@ -438,6 +445,7 @@ export class MCPDevice {
|
|
|
438
445
|
else {
|
|
439
446
|
console.debug('[DEBUG] No session in config');
|
|
440
447
|
}
|
|
448
|
+
this.deviceId = undefined;
|
|
441
449
|
return null;
|
|
442
450
|
}
|
|
443
451
|
catch (error) {
|
|
@@ -482,6 +490,10 @@ export class MCPDevice {
|
|
|
482
490
|
* outlive it - shutdown() - can await it.
|
|
483
491
|
*/
|
|
484
492
|
async savePersistedConfig(rotated) {
|
|
493
|
+
if (!this.trustedAuthContext) {
|
|
494
|
+
console.error('Refusing to persist a session before validating the remote backend');
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
485
497
|
this.configWriteChain = this.configWriteChain.then(() => this.writePersistedConfig(rotated));
|
|
486
498
|
return this.configWriteChain;
|
|
487
499
|
}
|
|
@@ -503,6 +515,7 @@ export class MCPDevice {
|
|
|
503
515
|
}
|
|
504
516
|
const config = {
|
|
505
517
|
deviceId: this.deviceId,
|
|
518
|
+
authContext: this.trustedAuthContext,
|
|
506
519
|
// Only save session if --persist-session flag is set
|
|
507
520
|
session: (session && this.persistSession) ? {
|
|
508
521
|
access_token: session.access_token,
|
|
@@ -551,24 +564,28 @@ export class MCPDevice {
|
|
|
551
564
|
}
|
|
552
565
|
}
|
|
553
566
|
async fetchSupabaseConfig() {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
567
|
+
const backend = validateRemoteServerUrl(this.baseServerUrl);
|
|
568
|
+
this.trustedAuthContext = null;
|
|
569
|
+
// Reject redirects before any saved credentials are passed to Supabase.
|
|
570
|
+
console.debug('[DEBUG] Fetching Supabase config from:', new URL('/api/mcp-info', backend).href);
|
|
571
|
+
const response = await fetch(new URL('/api/mcp-info', backend), {
|
|
572
|
+
redirect: 'error',
|
|
573
|
+
signal: AbortSignal.timeout(30000),
|
|
574
|
+
});
|
|
575
|
+
// auth-js checks token expiry against Date.now(), which may be skewed.
|
|
576
|
+
// Observe the trusted server's Date header before restoring a session.
|
|
561
577
|
observeServerDate(response.headers.get('date'));
|
|
562
578
|
if (!response.ok) {
|
|
563
|
-
console.debug('[DEBUG] Supabase config fetch failed, status:', response.status, response.statusText);
|
|
564
579
|
throw new Error(`Failed to fetch Supabase config: ${response.statusText}`);
|
|
565
580
|
}
|
|
566
581
|
const config = await response.json();
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
582
|
+
const trusted = validateRemoteAuthContext(backend.origin, config?.supabaseUrl);
|
|
583
|
+
if (typeof config?.supabasePublishableKey !== 'string' || !config.supabasePublishableKey.trim()) {
|
|
584
|
+
throw new Error('Missing Supabase publishable key from Remote MCP configuration');
|
|
585
|
+
}
|
|
586
|
+
this.trustedAuthContext = trusted;
|
|
587
|
+
console.debug('[DEBUG] Validated Supabase backend:', trusted.supabaseUrl);
|
|
588
|
+
return { supabaseUrl: trusted.supabaseUrl, anonKey: config.supabasePublishableKey };
|
|
572
589
|
}
|
|
573
590
|
// Methods moved to RemoteChannel
|
|
574
591
|
/**
|
|
@@ -177,7 +177,7 @@ export function observeServerDate(dateHeader) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
async function clockAwareFetch(input, init) {
|
|
180
|
-
const response = await fetch(input, init);
|
|
180
|
+
const response = await fetch(input, { ...init, redirect: 'error' });
|
|
181
181
|
observeServerDate(response.headers.get('date'));
|
|
182
182
|
return response;
|
|
183
183
|
}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
/** This is the hosted MCP API, not a value learned from /api/mcp-info. */
|
|
2
|
+
export declare const DEFAULT_REMOTE_SERVER_URL = "https://mcp.desktopcommander.app";
|
|
3
|
+
/** Trusted project endpoints; never learned from /api/mcp-info. */
|
|
4
|
+
export declare const SUPABASE1_ORIGIN = "https://olvbkozcufcbptfogatw.supabase.co";
|
|
5
|
+
export declare const SUPABASE2_ORIGIN = "https://xnalhwxchxhthlmzkhal.supabase.co";
|
|
6
|
+
export declare const SUPABASE3_ORIGIN = "https://example.supabase.co";
|
|
7
|
+
export interface RemoteAuthContext {
|
|
8
|
+
serverOrigin: string;
|
|
9
|
+
supabaseUrl: string;
|
|
10
|
+
}
|
|
1
11
|
export declare function isBackendLocal(url: URL): boolean;
|
|
12
|
+
/** Validate before requesting configuration or sending any device credentials. */
|
|
13
|
+
export declare function validateRemoteServerUrl(value: string): URL;
|
|
14
|
+
/**
|
|
15
|
+
* Validate the Supabase endpoint BEFORE setSession() can send persisted tokens.
|
|
16
|
+
* Accept only the explicitly listed project endpoints. Saved sessions are
|
|
17
|
+
* separately bound to their exact MCP and Supabase endpoints before restoration.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateRemoteAuthContext(serverUrl: string, supabaseUrl: unknown): RemoteAuthContext;
|
|
20
|
+
/** Legacy unbound sessions may be restored ONLY against the original default MCP/supabase1 pair. */
|
|
21
|
+
export declare function savedSessionMatchesContext(saved: unknown, expected: RemoteAuthContext): boolean;
|
|
2
22
|
export declare function getRemoteDeviceConfigDirectory(home?: string): string;
|
|
3
23
|
export declare function getRemoteDeviceConfigPath(home?: string): string;
|
|
@@ -1,17 +1,91 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
|
|
3
|
+
/** This is the hosted MCP API, not a value learned from /api/mcp-info. */
|
|
4
|
+
export const DEFAULT_REMOTE_SERVER_URL = "https://mcp.desktopcommander.app";
|
|
5
|
+
/** Trusted project endpoints; never learned from /api/mcp-info. */
|
|
6
|
+
export const SUPABASE1_ORIGIN = "https://olvbkozcufcbptfogatw.supabase.co";
|
|
7
|
+
export const SUPABASE2_ORIGIN = "https://xnalhwxchxhthlmzkhal.supabase.co";
|
|
8
|
+
export const SUPABASE3_ORIGIN = "https://example.supabase.co";
|
|
9
|
+
const LOCAL_BACKEND_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]", "mcp.localhost"];
|
|
10
|
+
// This checks the hostname, not its resolved address. HTTP is only for the
|
|
11
|
+
// explicit local development hosts below; all remote endpoints require TLS.
|
|
4
12
|
export function isBackendLocal(url) {
|
|
5
13
|
return (url.protocol === "http:" &&
|
|
6
|
-
|
|
14
|
+
LOCAL_BACKEND_HOSTNAMES.includes(url.hostname));
|
|
15
|
+
}
|
|
16
|
+
function parseTrustedEndpoint(value, label) {
|
|
17
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
18
|
+
throw new Error(`Invalid ${label}: expected a URL`);
|
|
19
|
+
}
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(value);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new Error(`Invalid ${label}: expected a URL`);
|
|
26
|
+
}
|
|
27
|
+
if ((url.protocol !== "https:" && !isBackendLocal(url)) ||
|
|
28
|
+
url.username ||
|
|
29
|
+
url.password ||
|
|
30
|
+
url.search ||
|
|
31
|
+
url.hash) {
|
|
32
|
+
throw new Error(`Unsafe ${label}: HTTPS or local HTTP required, without credentials, query, or fragment`);
|
|
33
|
+
}
|
|
34
|
+
return url;
|
|
35
|
+
}
|
|
36
|
+
/** Validate before requesting configuration or sending any device credentials. */
|
|
37
|
+
export function validateRemoteServerUrl(value) {
|
|
38
|
+
const url = parseTrustedEndpoint(value, "MCP_SERVER_URL");
|
|
39
|
+
// Match a complete DNS label so lookalikes such as evildesktopcommander.app
|
|
40
|
+
// and desktopcommander.app.example.com cannot become credential recipients.
|
|
41
|
+
const isDesktopCommanderHost = url.hostname === "desktopcommander.app" ||
|
|
42
|
+
url.hostname.endsWith(".desktopcommander.app");
|
|
43
|
+
if (!isDesktopCommanderHost && !LOCAL_BACKEND_HOSTNAMES.includes(url.hostname)) {
|
|
44
|
+
throw new Error("Unsafe MCP_SERVER_URL: use desktopcommander.app, one of its subdomains, or a supported local host");
|
|
45
|
+
}
|
|
46
|
+
if (url.pathname !== "/") {
|
|
47
|
+
throw new Error("Unsafe MCP_SERVER_URL: paths are not supported");
|
|
48
|
+
}
|
|
49
|
+
return url;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validate the Supabase endpoint BEFORE setSession() can send persisted tokens.
|
|
53
|
+
* Accept only the explicitly listed project endpoints. Saved sessions are
|
|
54
|
+
* separately bound to their exact MCP and Supabase endpoints before restoration.
|
|
55
|
+
*/
|
|
56
|
+
export function validateRemoteAuthContext(serverUrl, supabaseUrl) {
|
|
57
|
+
const server = validateRemoteServerUrl(serverUrl);
|
|
58
|
+
const auth = parseTrustedEndpoint(supabaseUrl, "Supabase URL");
|
|
59
|
+
// Compare the complete origin, including scheme and port; paths are never endpoints.
|
|
60
|
+
if ((auth.origin !== SUPABASE1_ORIGIN && auth.origin !== SUPABASE2_ORIGIN &&
|
|
61
|
+
auth.origin !== SUPABASE3_ORIGIN) ||
|
|
62
|
+
auth.pathname !== "/") {
|
|
63
|
+
throw new Error("Unsafe Supabase URL: only the supabase1, supabase2, and supabase3 project URLs are allowed, without paths");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
serverOrigin: server.origin,
|
|
67
|
+
supabaseUrl: auth.origin,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Legacy unbound sessions may be restored ONLY against the original default MCP/supabase1 pair. */
|
|
71
|
+
export function savedSessionMatchesContext(saved, expected) {
|
|
72
|
+
if (saved === undefined) {
|
|
73
|
+
return expected.serverOrigin === DEFAULT_REMOTE_SERVER_URL &&
|
|
74
|
+
expected.supabaseUrl === SUPABASE1_ORIGIN;
|
|
75
|
+
}
|
|
76
|
+
if (!saved || typeof saved !== "object" || Array.isArray(saved))
|
|
77
|
+
return false;
|
|
78
|
+
const previous = saved;
|
|
79
|
+
return previous.serverOrigin === expected.serverOrigin &&
|
|
80
|
+
previous.supabaseUrl === expected.supabaseUrl;
|
|
7
81
|
}
|
|
8
82
|
export function getRemoteDeviceConfigDirectory(home = os.homedir()) {
|
|
9
83
|
const suffix = "";
|
|
10
|
-
// TODO: uncomment
|
|
84
|
+
// TODO: uncomment when staging/dev profiles are fully isolated
|
|
11
85
|
// if (process.env.DC_ENV === "staging") {
|
|
12
|
-
//
|
|
86
|
+
// suffix = "-staging";
|
|
13
87
|
// } else if (process.env.DC_ENV === "development") {
|
|
14
|
-
//
|
|
88
|
+
// suffix = "-dev";
|
|
15
89
|
// }
|
|
16
90
|
return path.join(home, `.desktop-commander-device${suffix}`);
|
|
17
91
|
}
|
|
@@ -82,6 +82,7 @@ class RolloutManager {
|
|
|
82
82
|
throw new Error('No session token');
|
|
83
83
|
const response = await fetch(`${this.serverUrl}/device/rollouts`, {
|
|
84
84
|
headers: { Authorization: `Bearer ${token}` },
|
|
85
|
+
redirect: 'error',
|
|
85
86
|
});
|
|
86
87
|
if (!response.ok)
|
|
87
88
|
throw new Error(`HTTP ${response.status}`);
|