@linxin666/dsh-ssh 0.4.8 → 0.4.9

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/lib/index.js CHANGED
@@ -729,10 +729,16 @@ function startProxyCommand(rawCommand, target) {
729
729
  * Connection pool: per-alias persistent ssh2 connections with multi-hop jump
730
730
  * support, the acquire / dispose / sweep lifecycle, and the pooled exec path.
731
731
  */
732
+ /**
733
+ * Default ceiling for TCP connect, SSH key exchange and user authentication
734
+ * together (ms). Password authentication behind PAM / LDAP can outlast the
735
+ * previous 15 s ceiling while the server still eventually accepts it.
736
+ */
737
+ const DEFAULT_CONNECT_TIMEOUT_MS = 3e4;
732
738
  /** Default engine knobs (applied when an option is omitted). */
733
739
  const DEFAULTS = {
734
740
  idleTimeoutMs: 30 * 6e4,
735
- connectTimeoutMs: 15e3,
741
+ connectTimeoutMs: DEFAULT_CONNECT_TIMEOUT_MS,
736
742
  keepaliveIntervalMs: 15e3,
737
743
  maxOutputBytes: 2 * 1024 * 1024,
738
744
  defaultExecTimeoutMs: 6e4,
@@ -770,18 +776,28 @@ function buildConnectConfig(entry, sock, opts) {
770
776
  }
771
777
  return config;
772
778
  }
779
+ /**
780
+ * The default ssh-agent endpoint on Windows: the named pipe the native
781
+ * OpenSSH ssh-agent service listens on. ssh2 connects to a named pipe for any
782
+ * path matching its Windows pipe form, so the default is a real endpoint
783
+ * rather than a protocol name (#1910). PuTTY Pageant is still reachable — it
784
+ * is what the literal `pageant` agent path selects — but it is no longer the
785
+ * assumption.
786
+ */
787
+ const WINDOWS_AGENT_PIPE = "\\\\.\\pipe\\openssh-ssh-agent";
773
788
  /** Resolve the ssh2 agent path for 'agent' auth. */
774
789
  function resolveAgentPath(agentPath) {
775
790
  const explicit = normalizeAgentPath(agentPath);
776
791
  if (explicit !== void 0) return explicit;
777
792
  const sock = process.env.SSH_AUTH_SOCK;
778
793
  if (sock !== void 0 && sock !== "") return sock;
779
- if (process.platform === "win32") return "pageant";
794
+ if (process.platform === "win32") return WINDOWS_AGENT_PIPE;
780
795
  }
781
796
  /**
782
797
  * Resolve the ssh-agent endpoint that forwarding brokers signatures through:
783
- * an explicitly configured agent path wins, then SSH_AUTH_SOCK, then Pageant
784
- * on Windows. Undefined means no endpoint exists on this machine.
798
+ * an explicitly configured agent path wins, then SSH_AUTH_SOCK, then the
799
+ * native OpenSSH named pipe on Windows. Undefined means no endpoint exists on
800
+ * this machine.
785
801
  *
786
802
  * Forwarding shares the auth resolution on purpose — the endpoint a host
787
803
  * signs through is the same one it authenticates with — but it is a separate
@@ -790,11 +806,33 @@ function resolveAgentPath(agentPath) {
790
806
  function resolveForwardAgentPath(agentPath) {
791
807
  return resolveAgentPath(agentPath);
792
808
  }
809
+ /**
810
+ * Name the phase that actually stalled. ssh2 reports every pre-ready timeout
811
+ * as "Timed out while waiting for handshake", including one that expires
812
+ * during user authentication after a completed key exchange.
813
+ *
814
+ * @param timeoutMs - the configured `readyTimeout` (0 disables it).
815
+ * @param handshakeComplete - whether ssh2 completed the key exchange.
816
+ * @returns the operator-facing timeout message.
817
+ */
818
+ function readyTimeoutMessage(timeoutMs, handshakeComplete) {
819
+ const budget = typeof timeoutMs === "number" && timeoutMs > 0 ? " after " + timeoutMs + " ms" : "";
820
+ return handshakeComplete ? "SSH authentication timed out" + budget + ": TCP connect and key exchange completed, but the server did not finish authenticating the user - raise the dsh-ssh connectTimeoutMs setting if this host is slow" : "SSH connection timed out" + budget + " before key exchange completed: TCP connect or the SSH key exchange did not finish - raise the dsh-ssh connectTimeoutMs setting if this host is slow";
821
+ }
822
+ /**
823
+ * Whether ssh2 ended the attempt with its pre-ready timeout. The level is the
824
+ * stable discriminator; the message is reused for connect, key exchange and
825
+ * authentication alike.
826
+ */
827
+ function isReadyTimeout(error) {
828
+ return error.level === "client-timeout";
829
+ }
793
830
  /** Connect one ssh2 client (resolve on ready, reject on error/close). */
794
831
  function connectClient(config, onKeyboardInteractive) {
795
832
  return new Promise((resolve, reject) => {
796
833
  const client = new Client();
797
834
  let settled = false;
835
+ let handshakeComplete = false;
798
836
  const fail = (error) => {
799
837
  if (settled) return;
800
838
  settled = true;
@@ -805,8 +843,12 @@ function connectClient(config, onKeyboardInteractive) {
805
843
  try {
806
844
  client.destroy();
807
845
  } catch {}
808
- reject(error instanceof Error ? error : new Error(String(error)));
846
+ const cause = error instanceof Error ? error : new Error(String(error));
847
+ reject(isReadyTimeout(cause) ? new Error(readyTimeoutMessage(config.readyTimeout, handshakeComplete)) : cause);
809
848
  };
849
+ client.once("handshake", () => {
850
+ handshakeComplete = true;
851
+ });
810
852
  client.once("ready", () => {
811
853
  if (settled) return;
812
854
  settled = true;
@@ -1703,6 +1745,15 @@ var SshEngine = class {
1703
1745
  this.sweepTimer = setInterval(() => sweepPool(this), Math.max(1e4, this.opts.idleTimeoutMs / 4));
1704
1746
  this.sweepTimer.unref?.();
1705
1747
  }
1748
+ /**
1749
+ * Change the pre-ready ceiling (TCP connect + key exchange + user
1750
+ * authentication) for connections opened from now on. A pooled connection
1751
+ * keeps serving until it reconnects, because the ceiling governs the
1752
+ * connect path only.
1753
+ */
1754
+ setConnectTimeout(timeoutMs) {
1755
+ this.opts.connectTimeoutMs = timeoutMs;
1756
+ }
1706
1757
  /** Secret-free host list (filtered by the optional query). */
1707
1758
  list(query) {
1708
1759
  const needle = query?.trim().toLowerCase();
@@ -2833,7 +2884,7 @@ function sshExecTool(engine) {
2833
2884
  },
2834
2885
  timeoutMs: {
2835
2886
  type: "integer",
2836
- description: "Timeout in milliseconds (default 60000)."
2887
+ description: "Remote command execution timeout in milliseconds (default 60000); it starts after the connection is ready. The connection and authentication ceiling is the dsh-ssh connectTimeoutMs setting, not this argument."
2837
2888
  }
2838
2889
  },
2839
2890
  output: {
@@ -3216,7 +3267,7 @@ function sshClusterTool(engine) {
3216
3267
  },
3217
3268
  timeoutMs: {
3218
3269
  type: "integer",
3219
- description: "Per-host timeout in milliseconds."
3270
+ description: "Per-host command execution timeout in milliseconds (default 60000); it does not extend the connection and authentication ceiling (the dsh-ssh connectTimeoutMs setting)."
3220
3271
  },
3221
3272
  maxWorkers: {
3222
3273
  type: "integer",
@@ -3410,7 +3461,8 @@ function mountOnce(packageName, fn) {
3410
3461
  */
3411
3462
  const PLUGIN_TOOL_SECTION_ORDERS = {
3412
3463
  ssh: 150,
3413
- "task-board": 200
3464
+ "task-board": 200,
3465
+ agents: 220
3414
3466
  };
3415
3467
  /**
3416
3468
  * Build a section provider that renders \`text\` only while at least one of
@@ -3458,7 +3510,8 @@ const inject = [
3458
3510
  const Config = z.object({
3459
3511
  announceToAgent: z.boolean().default(false).volatile(),
3460
3512
  enabled: z.boolean().default(true).volatile(),
3461
- terminalFontFamily: z.string().default("").volatile()
3513
+ terminalFontFamily: z.string().default("").volatile(),
3514
+ connectTimeoutMs: z.number().step(1).min(1e3).max(6e5).default(DEFAULT_CONNECT_TIMEOUT_MS).volatile().description("TCP connect, SSH key exchange and user authentication timeout in milliseconds; raise it for hosts whose authentication is slow.")
3462
3515
  });
3463
3516
  /** Schema defaults, re-read for hand-built test contexts (the loader applies them normally). */
3464
3517
  const DEFAULT_ANNOUNCE = false;
@@ -3499,7 +3552,7 @@ const SSH_GUIDANCE = "本机已安装 dsh-ssh 插件(DSH 远程 SSH 运维)
3499
3552
  const apply = mountOnce("@linxin666/dsh-ssh", applyImpl);
3500
3553
  function applyImpl(ctx, config) {
3501
3554
  const store = new HostStore();
3502
- const engine = new SshEngine(store);
3555
+ const engine = new SshEngine(store, { connectTimeoutMs: readConfigField(config?.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS) });
3503
3556
  ctx.effect(() => () => {
3504
3557
  engine.dispose();
3505
3558
  }, "dsh-ssh: engine");
@@ -3527,6 +3580,7 @@ function applyImpl(ctx, config) {
3527
3580
  let disposeTools;
3528
3581
  let disposeSection;
3529
3582
  const sync = () => {
3583
+ engine.setConnectTimeout(readConfigField(config?.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS));
3530
3584
  const value = resolve();
3531
3585
  if (disposeSection !== void 0) {
3532
3586
  disposeSection();
@@ -61,8 +61,8 @@ export declare const zh: {
61
61
  readonly 'form.auth.password': "密码";
62
62
  readonly 'form.auth.agent': "SSH Agent";
63
63
  readonly 'form.agentPath': "Agent 路径";
64
- readonly 'form.agentPathHint': "留空自动检测(SSH_AUTH_SOCK / Windows Pageant);也可填 socket 路径或 pageant";
65
- readonly 'form.authKeepHint': "编辑时密钥/密码/Agent 留空将保留原认证方式与已存凭据;如需更换认证方式请填写新凭据。";
64
+ readonly 'form.agentPathHint': "留空自动检测(SSH_AUTH_SOCK;Windows 上为原生 ssh-agent 命名管道);也可填 socket 路径或 pageant";
65
+ readonly 'form.authKeepHint': "编辑时密码 / 私钥留空将保留已存凭据;Agent 路径留空是合法的自动检测,选「SSH Agent」即切换到 agent 认证。";
66
66
  readonly 'form.keyPath': "私钥路径";
67
67
  readonly 'form.keyPathHint': "如 ~/.ssh/id_ed25519";
68
68
  readonly 'form.passphrase': "密钥口令";
@@ -9,7 +9,10 @@ import { type HostStore } from '../store.ts';
9
9
  export interface EngineOptions {
10
10
  /** Connections idle longer than this are closed (ms). */
11
11
  idleTimeoutMs?: number;
12
- /** SSH handshake timeout (ms). */
12
+ /**
13
+ * Ceiling for the whole pre-ready sequence (ms): TCP connect, SSH key
14
+ * exchange and user authentication. Passed to ssh2's `readyTimeout`.
15
+ */
13
16
  connectTimeoutMs?: number;
14
17
  /** Keepalive ping interval (ms). */
15
18
  keepaliveIntervalMs?: number;
@@ -22,6 +25,12 @@ export interface EngineOptions {
22
25
  /** SFTP concurrent channel count for transfers. */
23
26
  sftpConcurrency?: number;
24
27
  }
28
+ /**
29
+ * Default ceiling for TCP connect, SSH key exchange and user authentication
30
+ * together (ms). Password authentication behind PAM / LDAP can outlast the
31
+ * previous 15 s ceiling while the server still eventually accepts it.
32
+ */
33
+ export declare const DEFAULT_CONNECT_TIMEOUT_MS = 30000;
25
34
  /** Default engine knobs (applied when an option is omitted). */
26
35
  export declare const DEFAULTS: Required<EngineOptions>;
27
36
  /** One pooled connection record. */
@@ -48,12 +57,22 @@ export interface PoolEngine {
48
57
  }
49
58
  /** Build the ssh2 connect config for one entry (key read from disk). */
50
59
  export declare function buildConnectConfig(entry: SshHostEntry, sock: ConnectConfig['sock'] | undefined, opts: Required<EngineOptions>): ConnectConfig;
60
+ /**
61
+ * The default ssh-agent endpoint on Windows: the named pipe the native
62
+ * OpenSSH ssh-agent service listens on. ssh2 connects to a named pipe for any
63
+ * path matching its Windows pipe form, so the default is a real endpoint
64
+ * rather than a protocol name (#1910). PuTTY Pageant is still reachable — it
65
+ * is what the literal `pageant` agent path selects — but it is no longer the
66
+ * assumption.
67
+ */
68
+ export declare const WINDOWS_AGENT_PIPE = "\\\\.\\pipe\\openssh-ssh-agent";
51
69
  /** Resolve the ssh2 agent path for 'agent' auth. */
52
70
  export declare function resolveAgentPath(agentPath?: string): string | undefined;
53
71
  /**
54
72
  * Resolve the ssh-agent endpoint that forwarding brokers signatures through:
55
- * an explicitly configured agent path wins, then SSH_AUTH_SOCK, then Pageant
56
- * on Windows. Undefined means no endpoint exists on this machine.
73
+ * an explicitly configured agent path wins, then SSH_AUTH_SOCK, then the
74
+ * native OpenSSH named pipe on Windows. Undefined means no endpoint exists on
75
+ * this machine.
57
76
  *
58
77
  * Forwarding shares the auth resolution on purpose — the endpoint a host
59
78
  * signs through is the same one it authenticates with — but it is a separate
@@ -65,6 +84,22 @@ export type KeyboardInteractiveHandler = (name: string, instructions: string, in
65
84
  prompt: string;
66
85
  echo: boolean;
67
86
  }>, finish: (responses: string[]) => void) => void;
87
+ /**
88
+ * Name the phase that actually stalled. ssh2 reports every pre-ready timeout
89
+ * as "Timed out while waiting for handshake", including one that expires
90
+ * during user authentication after a completed key exchange.
91
+ *
92
+ * @param timeoutMs - the configured `readyTimeout` (0 disables it).
93
+ * @param handshakeComplete - whether ssh2 completed the key exchange.
94
+ * @returns the operator-facing timeout message.
95
+ */
96
+ export declare function readyTimeoutMessage(timeoutMs: number | undefined, handshakeComplete: boolean): string;
97
+ /**
98
+ * Whether ssh2 ended the attempt with its pre-ready timeout. The level is the
99
+ * stable discriminator; the message is reused for connect, key exchange and
100
+ * authentication alike.
101
+ */
102
+ export declare function isReadyTimeout(error: Error): boolean;
68
103
  /** Connect one ssh2 client (resolve on ready, reject on error/close). */
69
104
  export declare function connectClient(config: ConnectConfig, onKeyboardInteractive?: KeyboardInteractiveHandler): Promise<Client>;
70
105
  /** Cap captured output at the configured byte budget (marks truncation). */
@@ -31,6 +31,13 @@ export declare class SshEngine {
31
31
  * @param options - engine knobs (defaults applied).
32
32
  */
33
33
  constructor(store: HostStore, options?: EngineOptions);
34
+ /**
35
+ * Change the pre-ready ceiling (TCP connect + key exchange + user
36
+ * authentication) for connections opened from now on. A pooled connection
37
+ * keeps serving until it reconnects, because the ceiling governs the
38
+ * connect path only.
39
+ */
40
+ setConnectTimeout(timeoutMs: number): void;
34
41
  /** Secret-free host list (filtered by the optional query). */
35
42
  list(query?: string): SshHostSummary[];
36
43
  /** One host summary by alias. */
@@ -40,6 +40,13 @@ export interface Config {
40
40
  * Nerd Font stack here to render powerline/Nerd glyphs.
41
41
  */
42
42
  terminalFontFamily?: string;
43
+ /**
44
+ * Ceiling for the whole pre-ready SSH sequence in milliseconds: TCP
45
+ * connect, key exchange and user authentication (default 30000). Raise it
46
+ * for hosts whose password authentication is slow (for example PAM / LDAP
47
+ * behind a distant directory service).
48
+ */
49
+ connectTimeoutMs?: number;
43
50
  }
44
51
  /** The stable reference a `volatile()` config field resolves to; its owner updates it in place. */
45
52
  interface ConfigRef<T> {
@@ -53,6 +60,7 @@ export interface ResolvedConfig {
53
60
  announceToAgent?: ConfigField<boolean>;
54
61
  enabled?: ConfigField<boolean>;
55
62
  terminalFontFamily?: ConfigField<string>;
63
+ connectTimeoutMs?: ConfigField<number>;
56
64
  }
57
65
  /**
58
66
  * Plugin config schema. Under the 0.1.7 settings model this schema IS the
@@ -66,10 +74,12 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
66
74
  announceToAgent: z<boolean, boolean, "volatile-defined">;
67
75
  enabled: z<boolean, boolean, "volatile-defined">;
68
76
  terminalFontFamily: z<string, string, "volatile-defined">;
77
+ connectTimeoutMs: z<number, number, "volatile-defined">;
69
78
  }>>, Schemastery.ObjectT<NoInfer<{
70
79
  announceToAgent: z<boolean, boolean, "volatile-defined">;
71
80
  enabled: z<boolean, boolean, "volatile-defined">;
72
81
  terminalFontFamily: z<string, string, "volatile-defined">;
82
+ connectTimeoutMs: z<number, number, "volatile-defined">;
73
83
  }>>, "plain">;
74
84
  /** Model-facing announcement: plugin presence, capabilities, and limits. */
75
85
  export declare const SSH_GUIDANCE = "\u672C\u673A\u5DF2\u5B89\u88C5 dsh-ssh \u63D2\u4EF6\uFF08DSH \u8FDC\u7A0B SSH \u8FD0\u7EF4\uFF09\uFF1A\u4FA7\u8FB9\u680F\u300CSSH\u300D\u5165\u53E3\uFF1B\u5728 dsh-web \u63D2\u4EF6\u5168\u5BB6\u6876\u4ED3\u5E93\uFF08packages/dsh-ssh\uFF09\u7EDF\u4E00\u7EF4\u62A4\u3002\u80FD\u529B\uFF1A\u4E3B\u673A\u914D\u7F6E\u5B58 $DSH_HOME/dsh-ssh.json\uFF08\u9ED8\u8BA4 ~/.dsh\uFF09\uFF08\u53EF\u4ECE ~/.ssh/config \u5BFC\u5165\uFF09\uFF1B\u6301\u4E45\u8FDE\u63A5\u6C60\u590D\u7528\u957F\u8FDE\u63A5\uFF08\u7A7A\u95F2 30 \u5206\u949F\u81EA\u52A8\u65AD\u5F00\uFF09\uFF1Bssh_list \u5217\u51FA\u4E3B\u673A\u3001ssh_exec \u6267\u884C\u8FDC\u7A0B\u547D\u4EE4\u3001ssh_upload/ssh_download \u4F20\u8F93\u6587\u4EF6\u3001ssh_tunnel \u672C\u5730\u7AEF\u53E3\u8F6C\u53D1\uFF08\u8BBF\u95EE\u8FDC\u7A0B\u6570\u636E\u5E93/\u5185\u7F51\u670D\u52A1\uFF09\u3001ssh_cluster \u6309 aliases/environment/tags \u81F3\u5C11\u4E00\u79CD\u975E\u7A7A selector \u7B5B\u9009\u540E\u96C6\u7FA4\u5E76\u53D1\u6267\u884C\uFF1B\u652F\u6301\u5BC6\u94A5/\u5BC6\u7801/ssh-agent \u8BA4\u8BC1\u3001passphrase \u5BC6\u94A5\u3001ProxyJump \u8DF3\u677F\u673A\uFF08\u522B\u540D\u6216 [user@]host[:port] \u5730\u5740\uFF09\u4E0E OpenSSH \u8BED\u4E49\u7684 ProxyCommand\uFF08\u8DF3\u8FC7\u5821\u5792\u673A\u5BA2\u6237\u7AEF\u573A\u666F\uFF0C\u53EA\u80FD\u7531\u7528\u6237\u5728 GUI \u914D\u7F6E\uFF0Cagent \u4E0D\u53EF\u5199\uFF09\uFF1BWeb \u7EC8\u7AEF\u8D70 WebSocket\u3002\u9650\u5236\uFF1A\u4E3B\u673A\u64CD\u4F5C\u7531\u7528\u6237\u5728 GUI \u4E2D\u914D\u7F6E\u540E agent \u65B9\u53EF\u4F7F\u7528\uFF1B\u5BC6\u7801\u4EE5\u660E\u6587\u5B58\u5728\u7528\u6237\u4E3B\u76EE\u5F55\u79C1\u6709\u6587\u4EF6\uFF08\u6743\u9650 0600\uFF09\uFF1B\u547D\u4EE4\u8F93\u51FA\u539F\u6837\u8FD4\u56DE\u3001\u53EF\u80FD\u542B\u654F\u611F\u4FE1\u606F\uFF1B\u65AD\u7EBF\u91CD\u8FDE\u53EF\u80FD\u91CD\u653E\u975E\u5E42\u7B49\u547D\u4EE4\uFF1B\u4F20\u8F93/\u6267\u884C\u6D88\u8017\u771F\u5B9E\u8FDC\u7A0B\u8D44\u6E90\uFF0C\u5148\u786E\u8BA4\u518D\u64CD\u4F5C\u3002\u8DEF\u5F84\u533A\u5206\uFF1A\u672C\u673A\uFF08dsh host\uFF09\u4E0A\u7684\u6587\u4EF6\u4E0E\u547D\u4EE4\u4E00\u5F8B\u7528\u672C\u5730\u5DE5\u5177\uFF08read / write / edit / bash\uFF09\uFF0Cssh_* \u5DE5\u5177\u53EA\u9488\u5BF9\u8FDC\u7A0B\u4E3B\u673A\u4E0A\u7684\u8DEF\u5F84\u3002\u7528\u6237\u63D0\u5230\u300CSSH / \u8FDC\u7A0B\u670D\u52A1\u5668 / \u670D\u52A1\u5668\u64CD\u4F5C / \u8DF3\u677F\u673A / \u96A7\u9053 / \u90E8\u7F72 / \u4E0A\u4F20\u4E0B\u8F7D\u300D\u65F6\u5373\u6307\u672C\u63D2\u4EF6\uFF0C\u8BF7\u636E\u6B64\u534F\u4F5C\u3002";
@@ -15,6 +15,11 @@
15
15
  * request. Forwarding headers are the signal that a hop stands in between: a
16
16
  * request that carries CF-Connecting-IP or X-Forwarded-For is answered through
17
17
  * a proxy and is never treated as a local one (issue #1906).
18
+ *
19
+ * An operator who runs that proxy or tunnel themselves can opt into the
20
+ * narrower case: isForwardedLoopbackRequest describes a forwarded request that
21
+ * still landed on this machine's loopback upstream, and a route family admits
22
+ * it only behind its own default-off switch (issue #1918).
18
23
  * @module dsh-web-shared/host/loopback
19
24
  */
20
25
  import type { IncomingMessage } from 'node:http';
@@ -41,3 +46,19 @@ export declare function isProxiedRequest(request: IncomingMessage): boolean;
41
46
  * client. X-Forwarded-For is therefore never evidence *for* loopback.
42
47
  */
43
48
  export declare function isLoopbackRequest(request: IncomingMessage): boolean;
49
+ /**
50
+ * Whether a forwarded request landed on this machine's loopback upstream: a
51
+ * forwarding header (the proxy's own stamp), a loopback socket address (the
52
+ * proxy dials 127.0.0.1:<port>), and a loopback Host header (the proxy rewrote
53
+ * the authority to its upstream literal).
54
+ *
55
+ * This is a fact about the route, not a trust decision. A public request to a
56
+ * tunnel satisfies all three by construction, because the proxy is the client
57
+ * of this process: only a caller that operates the proxy can decide it stands
58
+ * for the browser, which is why every consumer keeps this behind an explicit
59
+ * default-off switch and its own browser markers. isLoopbackRequest is
60
+ * unchanged and still refuses a forwarded request (issue #1906).
61
+ * @param request - node HTTP request.
62
+ * @returns true when a forwarding header, a loopback socket, and a loopback Host all hold.
63
+ */
64
+ export declare function isForwardedLoopbackRequest(request: IncomingMessage): boolean;
@@ -27,7 +27,7 @@ export interface SshHostEntry {
27
27
  /**
28
28
  * ssh-agent endpoint for 'agent' auth. A socket path, the special value
29
29
  * 'pageant' (PuTTY Pageant on Windows), or undefined for auto-detect
30
- * (SSH_AUTH_SOCK, then Pageant on Windows).
30
+ * (SSH_AUTH_SOCK, then the native OpenSSH named pipe on Windows).
31
31
  */
32
32
  agentPath?: string;
33
33
  };
@@ -30,6 +30,7 @@
30
30
  export declare const PLUGIN_TOOL_SECTION_ORDERS: {
31
31
  readonly ssh: 150;
32
32
  readonly 'task-board': 200;
33
+ readonly agents: 220;
33
34
  };
34
35
  /** One plugin id keyed by {@link PLUGIN_TOOL_SECTION_ORDERS}. */
35
36
  export type PluginToolSectionId = keyof typeof PLUGIN_TOOL_SECTION_ORDERS;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-ssh",
3
3
  "description": "Remote SSH operations for the dsh web GUI: host config store (~/.dsh/dsh-ssh.json, import from ~/.ssh/config), a persistent ssh2 connection pool with jump-host support, exec / PTY web terminal / SFTP transfer / local port-forward tunnels / cluster execution, plus agent tools (ssh_list, ssh_exec, ssh_upload, ssh_download, ssh_tunnel, ssh_cluster). Hot-pluggable — mounted via ~/.dsh/cordis.patch.yml + a profile node_modules symlink, no dsh source changes.",
4
- "version": "0.4.8",
4
+ "version": "0.4.9",
5
5
  "icon": "icon.svg",
6
6
  "type": "module",
7
7
  "engines": {
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dsh": {
25
25
  "engines": {
26
- "dsh": ">=0.2.1-rc.2"
26
+ "dsh": ">=0.2.1-rc.3"
27
27
  },
28
28
  "bundle": {
29
29
  "patch": "./cordis.patch.yml"
@@ -46,26 +46,26 @@
46
46
  "ws": "^8.18.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@deepseek-ai/dsh": ">=0.2.1-rc.2",
49
+ "@deepseek-ai/dsh": ">=0.2.1-rc.3",
50
50
  "react": "^18.2.0",
51
51
  "react-dom": "^18.2.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@deepseek-ai/cordis": "^4.0.5",
55
- "@deepseek-ai/dsh-client-connection": "^0.2.1-rc.2",
56
- "@deepseek-ai/dsh-client-locale": "^0.2.1-rc.2",
57
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.2",
58
- "@deepseek-ai/dsh-client-ui-layout": "^0.2.1-rc.2",
59
- "@deepseek-ai/dsh-client-ui-settings": "^0.2.1-rc.2",
60
- "@deepseek-ai/dsh-client-ui-sidebar": "^0.2.1-rc.2",
61
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.2",
62
- "@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.2",
63
- "@deepseek-ai/dsh-llm": "^0.2.1-rc.2",
64
- "@deepseek-ai/dsh-scope": "^0.2.1-rc.2",
65
- "@deepseek-ai/dsh-settings": "^0.2.1-rc.2",
66
- "@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.2",
67
- "@deepseek-ai/dsh-timeout": "^0.2.1-rc.2",
68
- "@deepseek-ai/dsh-tools": "^0.2.1-rc.2",
55
+ "@deepseek-ai/dsh-client-connection": "^0.2.1-rc.3",
56
+ "@deepseek-ai/dsh-client-locale": "^0.2.1-rc.3",
57
+ "@deepseek-ai/dsh-client-ui-layout": "^0.2.1-rc.3",
58
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.3",
59
+ "@deepseek-ai/dsh-client-ui-settings": "^0.2.1-rc.3",
60
+ "@deepseek-ai/dsh-client-ui-sidebar": "^0.2.1-rc.3",
61
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.3",
62
+ "@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.3",
63
+ "@deepseek-ai/dsh-llm": "^0.2.1-rc.3",
64
+ "@deepseek-ai/dsh-scope": "^0.2.1-rc.3",
65
+ "@deepseek-ai/dsh-settings": "^0.2.1-rc.3",
66
+ "@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.3",
67
+ "@deepseek-ai/dsh-timeout": "^0.2.1-rc.3",
68
+ "@deepseek-ai/dsh-tools": "^0.2.1-rc.3",
69
69
  "@types/node": "^22.20.0",
70
70
  "@types/react": "~18.3.1",
71
71
  "@types/react-dom": "^18.3.5",
@@ -64,8 +64,8 @@ export const zh = {
64
64
  'form.auth.password': '密码',
65
65
  'form.auth.agent': 'SSH Agent',
66
66
  'form.agentPath': 'Agent 路径',
67
- 'form.agentPathHint': '留空自动检测(SSH_AUTH_SOCK / Windows Pageant);也可填 socket 路径或 pageant',
68
- 'form.authKeepHint': '编辑时密钥/密码/Agent 留空将保留原认证方式与已存凭据;如需更换认证方式请填写新凭据。',
67
+ 'form.agentPathHint': '留空自动检测(SSH_AUTH_SOCK;Windows 上为原生 ssh-agent 命名管道);也可填 socket 路径或 pageant',
68
+ 'form.authKeepHint': '编辑时密码 / 私钥留空将保留已存凭据;Agent 路径留空是合法的自动检测,选「SSH Agent」即切换到 agent 认证。',
69
69
  'form.keyPath': '私钥路径',
70
70
  'form.keyPathHint': '如 ~/.ssh/id_ed25519',
71
71
  'form.passphrase': '密钥口令',
@@ -230,8 +230,8 @@ export const en: Record<keyof typeof zh, string> = {
230
230
  'form.auth.password': 'Password',
231
231
  'form.auth.agent': 'SSH Agent',
232
232
  'form.agentPath': 'Agent path',
233
- 'form.agentPathHint': 'Leave empty to auto-detect (SSH_AUTH_SOCK / Pageant on Windows), or set a socket path or "pageant"',
234
- 'form.authKeepHint': 'While editing, empty secret fields keep the stored authentication and credentials; enter new values to switch methods.',
233
+ 'form.agentPathHint': 'Leave empty to auto-detect (SSH_AUTH_SOCK; the native ssh-agent named pipe on Windows), or set a socket path or "pageant"',
234
+ 'form.authKeepHint': 'While editing, an empty password or key field keeps the stored credential; an empty agent path is a valid auto-detect, so choosing SSH Agent switches the host to agent auth.',
235
235
  'form.keyPath': 'Private key path',
236
236
  'form.keyPathHint': 'e.g. ~/.ssh/id_ed25519',
237
237
  'form.passphrase': 'Key passphrase',
@@ -106,12 +106,15 @@ export function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialo
106
106
  }
107
107
  // Secrets are never echoed back by the API: when editing and the secret
108
108
  // fields are left empty, the auth block is omitted so the stored
109
- // authentication is preserved.
109
+ // authentication is preserved. The agent path is not a secret — an empty
110
+ // one is the documented "auto-detect" choice — so an agent form always
111
+ // submits its auth block; omitting it would make the PATCH a silent no-op
112
+ // that keeps the previous auth kind (#1910).
110
113
  const secretEmpty = form.authKind === 'password'
111
114
  ? form.password === ''
112
115
  : form.authKind === 'key'
113
116
  ? form.keyPath.trim() === ''
114
- : form.agentPath.trim() === ''
117
+ : false
115
118
  const auth: HostPayload['auth'] = editing != null && secretEmpty
116
119
  ? undefined
117
120
  : form.authKind === 'password'
@@ -14,7 +14,10 @@ import { startProxyCommand, type ProxyTarget } from './proxy-command.ts'
14
14
  export interface EngineOptions {
15
15
  /** Connections idle longer than this are closed (ms). */
16
16
  idleTimeoutMs?: number
17
- /** SSH handshake timeout (ms). */
17
+ /**
18
+ * Ceiling for the whole pre-ready sequence (ms): TCP connect, SSH key
19
+ * exchange and user authentication. Passed to ssh2's `readyTimeout`.
20
+ */
18
21
  connectTimeoutMs?: number
19
22
  /** Keepalive ping interval (ms). */
20
23
  keepaliveIntervalMs?: number
@@ -28,10 +31,17 @@ export interface EngineOptions {
28
31
  sftpConcurrency?: number
29
32
  }
30
33
 
34
+ /**
35
+ * Default ceiling for TCP connect, SSH key exchange and user authentication
36
+ * together (ms). Password authentication behind PAM / LDAP can outlast the
37
+ * previous 15 s ceiling while the server still eventually accepts it.
38
+ */
39
+ export const DEFAULT_CONNECT_TIMEOUT_MS = 30_000
40
+
31
41
  /** Default engine knobs (applied when an option is omitted). */
32
42
  export const DEFAULTS: Required<EngineOptions> = {
33
43
  idleTimeoutMs: 30 * 60_000,
34
- connectTimeoutMs: 15_000,
44
+ connectTimeoutMs: DEFAULT_CONNECT_TIMEOUT_MS,
35
45
  keepaliveIntervalMs: 15_000,
36
46
  maxOutputBytes: 2 * 1024 * 1024,
37
47
  defaultExecTimeoutMs: 60_000,
@@ -115,20 +125,31 @@ export function buildConnectConfig(entry: SshHostEntry, sock: ConnectConfig['soc
115
125
  return config
116
126
  }
117
127
 
128
+ /**
129
+ * The default ssh-agent endpoint on Windows: the named pipe the native
130
+ * OpenSSH ssh-agent service listens on. ssh2 connects to a named pipe for any
131
+ * path matching its Windows pipe form, so the default is a real endpoint
132
+ * rather than a protocol name (#1910). PuTTY Pageant is still reachable — it
133
+ * is what the literal `pageant` agent path selects — but it is no longer the
134
+ * assumption.
135
+ */
136
+ export const WINDOWS_AGENT_PIPE = '\\\\.\\pipe\\openssh-ssh-agent'
137
+
118
138
  /** Resolve the ssh2 agent path for 'agent' auth. */
119
139
  export function resolveAgentPath(agentPath?: string): string | undefined {
120
140
  const explicit = normalizeAgentPath(agentPath)
121
141
  if (explicit !== undefined) return explicit
122
142
  const sock = process.env.SSH_AUTH_SOCK
123
143
  if (sock !== undefined && sock !== '') return sock
124
- if (process.platform === 'win32') return 'pageant'
144
+ if (process.platform === 'win32') return WINDOWS_AGENT_PIPE
125
145
  return undefined
126
146
  }
127
147
 
128
148
  /**
129
149
  * Resolve the ssh-agent endpoint that forwarding brokers signatures through:
130
- * an explicitly configured agent path wins, then SSH_AUTH_SOCK, then Pageant
131
- * on Windows. Undefined means no endpoint exists on this machine.
150
+ * an explicitly configured agent path wins, then SSH_AUTH_SOCK, then the
151
+ * native OpenSSH named pipe on Windows. Undefined means no endpoint exists on
152
+ * this machine.
132
153
  *
133
154
  * Forwarding shares the auth resolution on purpose — the endpoint a host
134
155
  * signs through is the same one it authenticates with — but it is a separate
@@ -147,11 +168,40 @@ export type KeyboardInteractiveHandler = (
147
168
  finish: (responses: string[]) => void,
148
169
  ) => void
149
170
 
171
+ /**
172
+ * Name the phase that actually stalled. ssh2 reports every pre-ready timeout
173
+ * as "Timed out while waiting for handshake", including one that expires
174
+ * during user authentication after a completed key exchange.
175
+ *
176
+ * @param timeoutMs - the configured `readyTimeout` (0 disables it).
177
+ * @param handshakeComplete - whether ssh2 completed the key exchange.
178
+ * @returns the operator-facing timeout message.
179
+ */
180
+ export function readyTimeoutMessage(timeoutMs: number | undefined, handshakeComplete: boolean): string {
181
+ const budget = typeof timeoutMs === 'number' && timeoutMs > 0 ? ' after ' + timeoutMs + ' ms' : ''
182
+ const hint = ' - raise the dsh-ssh connectTimeoutMs setting if this host is slow'
183
+ return handshakeComplete
184
+ ? 'SSH authentication timed out' + budget + ': TCP connect and key exchange completed, but the server did not finish authenticating the user' + hint
185
+ : 'SSH connection timed out' + budget + ' before key exchange completed: TCP connect or the SSH key exchange did not finish' + hint
186
+ }
187
+
188
+ /**
189
+ * Whether ssh2 ended the attempt with its pre-ready timeout. The level is the
190
+ * stable discriminator; the message is reused for connect, key exchange and
191
+ * authentication alike.
192
+ */
193
+ export function isReadyTimeout(error: Error): boolean {
194
+ return (error as Error & { level?: unknown }).level === 'client-timeout'
195
+ }
196
+
150
197
  /** Connect one ssh2 client (resolve on ready, reject on error/close). */
151
198
  export function connectClient(config: ConnectConfig, onKeyboardInteractive?: KeyboardInteractiveHandler): Promise<Client> {
152
199
  return new Promise((resolve, reject) => {
153
200
  const client = new Client()
154
201
  let settled = false
202
+ // Key exchange completion is the only public phase boundary ssh2 exposes
203
+ // between "TCP connect / SSH handshake" and "user authentication".
204
+ let handshakeComplete = false
155
205
  const fail = (error: unknown): void => {
156
206
  if (settled) return
157
207
  settled = true
@@ -163,8 +213,12 @@ export function connectClient(config: ConnectConfig, onKeyboardInteractive?: Key
163
213
  try { (sock as { destroy: () => void }).destroy() } catch { /* already closed */ }
164
214
  }
165
215
  try { client.destroy() } catch { /* already closed */ }
166
- reject(error instanceof Error ? error : new Error(String(error)))
216
+ const cause = error instanceof Error ? error : new Error(String(error))
217
+ reject(isReadyTimeout(cause) ? new Error(readyTimeoutMessage(config.readyTimeout, handshakeComplete)) : cause)
167
218
  }
219
+ client.once('handshake', () => {
220
+ handshakeComplete = true
221
+ })
168
222
  client.once('ready', () => {
169
223
  if (settled) return
170
224
  settled = true
package/src/engine.ts CHANGED
@@ -51,6 +51,16 @@ export class SshEngine {
51
51
  this.sweepTimer.unref?.()
52
52
  }
53
53
 
54
+ /**
55
+ * Change the pre-ready ceiling (TCP connect + key exchange + user
56
+ * authentication) for connections opened from now on. A pooled connection
57
+ * keeps serving until it reconnects, because the ceiling governs the
58
+ * connect path only.
59
+ */
60
+ setConnectTimeout(timeoutMs: number): void {
61
+ this.opts.connectTimeoutMs = timeoutMs
62
+ }
63
+
54
64
  // ---------------------------------------------------------------- config
55
65
 
56
66
  /** Secret-free host list (filtered by the optional query). */