mcp-ssh-manager 4.0.0 → 4.0.2

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.
@@ -47,6 +47,9 @@ export const RELEASES_PAGE = 'https://github.com/bvisible/mcp-ssh-manager/releas
47
47
  /** Release assets live under `<this>/v<version>/<file>`. */
48
48
  const RELEASE_BASE_URL = `${RELEASES_PAGE}/download`;
49
49
 
50
+ /** A version this project releases: 4.0.0, 4.0.0-beta.3. Nothing else reaches a URL. */
51
+ const RELEASE_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*)?$/;
52
+
50
53
  /** The Developer ID team of bVisible Sarl, which signs and notarizes the macOS build. */
51
54
  const TEAM_ID = 'BT249938WK';
52
55
 
@@ -645,6 +648,11 @@ export async function installDesktop({
645
648
  if (root.protocol !== 'https:' && !allowLoopbackHttp) {
646
649
  throw desktopError('DOWNLOAD', `Refusing to download from ${root.origin}: HTTPS only`);
647
650
  }
651
+ // The version comes from a file (the engine's own package.json) and becomes
652
+ // part of the download URL and of the file name: only a release version may.
653
+ if (!RELEASE_VERSION.test(version)) {
654
+ throw desktopError('NOT_FOUND', `Not a release version: ${JSON.stringify(version)}. See ${RELEASES_PAGE}`);
655
+ }
648
656
  const base = new URL(`v${encodeURIComponent(version)}/`, root);
649
657
  const name = `${ARTIFACT_PREFIX}-${version}-${target.suffix}`;
650
658
 
package/src/index.js CHANGED
@@ -151,7 +151,7 @@ import {
151
151
  import { loadToolConfig, isToolEnabled } from './tool-config-manager.js';
152
152
  import { evaluatePolicy } from './policy.js';
153
153
  import { needsApproval, isControlPlaneListening, requestDecision, buildRequest, isApprovalExempt, isReadOnlyAction, HANDLER_GATED_TOOLS } from './approval.js';
154
- import { shellQuote, shellPath, safeInteger } from './shell-quote.js';
154
+ import { shellQuote, shellPath, safeInteger, withRemoteTimeout } from './shell-quote.js';
155
155
  import { openStream } from './live-stream.js';
156
156
  import { auditLog, sanitize } from './audit.js';
157
157
 
@@ -163,7 +163,8 @@ const envFilePath = envChoice.path;
163
163
  // Said at startup and repeated wherever a missing server would otherwise be
164
164
  // the only clue: an empty configuration used to fail without a word (#90).
165
165
  const envProblem = envFileProblem(envChoice);
166
- const envFile = dotenv.config({ path: envFilePath, processEnv: {} });
166
+ // quiet: since dotenv 17 every load is announced on the log otherwise.
167
+ const envFile = dotenv.config({ path: envFilePath, processEnv: {}, quiet: true });
167
168
  const envFileValues = envFile.parsed || {};
168
169
 
169
170
  function getRuntimeEnv(name) {
@@ -365,9 +366,10 @@ async function execCommandWithTimeout(ssh, command, options = {}, timeoutMs = 30
365
366
  const useSystemTimeout = timeoutMs > 0 && timeoutMs < 300000 && !rawCommand; // Max 5 minutes, not for raw commands
366
367
 
367
368
  if (useSystemTimeout) {
368
- // Wrap command with timeout command (works on Linux/Mac)
369
- const timeoutSeconds = Math.ceil(timeoutMs / 1000);
370
- const wrappedCommand = `timeout ${timeoutSeconds} sh -c '${command.replace(/'/g, '\'\\\'\'')}'`;
369
+ // The remote host's own `timeout` (or Homebrew's `gtimeout`), found on the
370
+ // target rather than assumed: a stock Mac has neither, and every wrapped
371
+ // command failed there with exit 127 (#115). See withRemoteTimeout.
372
+ const wrappedCommand = withRemoteTimeout(command, Math.ceil(timeoutMs / 1000));
371
373
 
372
374
  try {
373
375
  const result = await ssh.execCommand(wrappedCommand, {
@@ -399,6 +401,12 @@ async function execCommandWithTimeout(ssh, command, options = {}, timeoutMs = 30
399
401
  }
400
402
  }
401
403
  }
404
+ // On a target with no timeout binary (a stock Mac) it is the client-side
405
+ // limit that stops the command, and its message would name the wrapper and
406
+ // the grace period: say what the caller sent and the limit they asked for.
407
+ if (error.message.startsWith('Command timeout after')) {
408
+ throw new Error(`Command timeout after ${timeoutMs}ms: ${command.substring(0, 100)}...`);
409
+ }
402
410
  throw error;
403
411
  }
404
412
  } else {
@@ -36,6 +36,32 @@ export function shellPath(value) {
36
36
  return shellQuote(text);
37
37
  }
38
38
 
39
+ // Finds the timeout binary on the target, then runs the command under it. Run by
40
+ // `sh` with the seconds as $1 and the command as $2, so neither is ever spliced
41
+ // into this text. Stock Linux has `timeout`; macOS has neither unless Homebrew's
42
+ // coreutils adds `gtimeout`; with neither, the command still runs (the local SSH
43
+ // exec timeout bounds it) instead of failing with exit 127 (#115).
44
+ const REMOTE_TIMEOUT_SCRIPT = 'if t=$(command -v timeout 2>/dev/null || command -v gtimeout 2>/dev/null);'
45
+ + ' then exec "$t" "$1" sh -c "$2"; else exec sh -c "$2"; fi';
46
+
47
+ /**
48
+ * Wrap a command so the remote host kills it after `seconds`.
49
+ *
50
+ * The result is a single simple command made only of single-quoted words
51
+ * (`sh -c '<script>' sh <seconds> '<command>'`), because the SSH server hands it
52
+ * to the account's login shell, which is not always a POSIX one: csh and tcsh
53
+ * (FreeBSD's root, some old accounts) reject `$(...)` and `if ... fi` written at
54
+ * the top level, and a wrapper that resolves the binary there failed on them
55
+ * where the old bare `timeout ...` worked. The probing happens inside `sh`.
56
+ *
57
+ * @param {string} command - The command as the user wrote it, run by `sh -c`
58
+ * @param {number} seconds - Whole seconds before the remote side kills it
59
+ * @returns {string} The wrapped command
60
+ */
61
+ export function withRemoteTimeout(command, seconds) {
62
+ return `sh -c ${shellQuote(REMOTE_TIMEOUT_SCRIPT)} sh ${safeInteger(seconds, 1)} ${shellQuote(command)}`;
63
+ }
64
+
39
65
  /**
40
66
  * Coerce a value to a safe non-negative integer for use in a command.
41
67
  *
@@ -48,7 +74,14 @@ export function shellPath(value) {
48
74
  * @returns {number} A non-negative integer
49
75
  */
50
76
  export function safeInteger(value, fallback) {
51
- const n = Number(value);
77
+ let n;
78
+ try {
79
+ n = Number(value);
80
+ } catch {
81
+ return fallback; // an object that cannot become a number at all (found by the property test)
82
+ }
52
83
  if (!Number.isFinite(n)) return fallback;
53
- return Math.max(0, Math.trunc(n));
84
+ // Capped: above 2^53 a number is no longer exact, and from 1e21 up it prints
85
+ // as "1e+21", which no command reads as a count (found by the property test).
86
+ return Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, Math.trunc(n)));
54
87
  }