@linxin666/dsh-ssh 0.4.7 → 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
@@ -216,6 +216,7 @@ function validateHostPayload(payload) {
216
216
  const proxyJump = Array.isArray(p.proxyJump) ? p.proxyJump : [];
217
217
  if (proxyCommand !== void 0 && proxyJump.length > 0) return "proxyCommand and proxyJump cannot be combined — pick one transport per host";
218
218
  if (p.tags !== void 0 && (!Array.isArray(p.tags) || p.tags.some((x) => typeof x !== "string"))) return "tags must be an array of strings";
219
+ if (p.forwardAgent !== void 0 && typeof p.forwardAgent !== "boolean") return "forwardAgent must be a boolean";
219
220
  }
220
221
  /** Alias grammar: letters/digits plus dots, hyphens, underscores (IP/domain aliases included). */
221
222
  const ALIAS_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
@@ -265,6 +266,7 @@ var HostStore = class {
265
266
  ...entry.environment !== void 0 ? { environment: entry.environment } : {},
266
267
  tags: [...entry.tags],
267
268
  ...entry.location !== void 0 ? { location: entry.location } : {},
269
+ forwardAgent: entry.forwardAgent === true,
268
270
  createdAt: entry.createdAt,
269
271
  updatedAt: entry.updatedAt
270
272
  };
@@ -299,6 +301,7 @@ var HostStore = class {
299
301
  environment: payload.environment?.trim() || void 0,
300
302
  tags: [...payload.tags ?? []].map((tag) => tag.trim()).filter((tag) => tag !== ""),
301
303
  location: payload.location?.trim() || void 0,
304
+ forwardAgent: payload.forwardAgent === true ? true : void 0,
302
305
  createdAt: now,
303
306
  updatedAt: now
304
307
  };
@@ -316,6 +319,7 @@ var HostStore = class {
316
319
  if (patch.port !== void 0 && (typeof patch.port !== "number" || !Number.isInteger(patch.port) || patch.port < 1 || patch.port > 65535)) throw new Error("port must be an integer in 1..65535");
317
320
  if (patch.proxyJump !== void 0 && (!Array.isArray(patch.proxyJump) || patch.proxyJump.some((x) => typeof x !== "string" || x === ""))) throw new Error("proxyJump must be an array of alias strings");
318
321
  if (patch.proxyCommand !== void 0 && typeof patch.proxyCommand !== "string") throw new Error("proxyCommand must be a string when provided");
322
+ if (patch.forwardAgent !== void 0 && typeof patch.forwardAgent !== "boolean") throw new Error("forwardAgent must be a boolean");
319
323
  const mergedProxyCommand = patch.proxyCommand !== void 0 ? normalizeProxyCommand(patch.proxyCommand) : entry.proxyCommand;
320
324
  if (mergedProxyCommand !== void 0 && (patch.proxyJump ?? entry.proxyJump).length > 0) throw new Error("proxyCommand and proxyJump cannot be combined — pick one transport per host");
321
325
  if (patch.tags !== void 0 && (!Array.isArray(patch.tags) || patch.tags.some((x) => typeof x !== "string"))) throw new Error("tags must be an array of strings");
@@ -343,6 +347,7 @@ var HostStore = class {
343
347
  if (patch.environment !== void 0) entry.environment = patch.environment.trim() || void 0;
344
348
  if (patch.tags !== void 0) entry.tags = [...patch.tags].map((tag) => tag.trim()).filter((tag) => tag !== "");
345
349
  if (patch.location !== void 0) entry.location = patch.location.trim() || void 0;
350
+ if (patch.forwardAgent !== void 0) entry.forwardAgent = patch.forwardAgent === true ? true : void 0;
346
351
  entry.updatedAt = Date.now();
347
352
  this.save(file);
348
353
  return entry;
@@ -410,7 +415,8 @@ var HostStore = class {
410
415
  description: block.props.description,
411
416
  environment: block.props.environment,
412
417
  tags: (block.props.tags ?? "").split(",").map((tag) => tag.trim()).filter((tag) => tag !== ""),
413
- location: block.props.location
418
+ location: block.props.location,
419
+ forwardAgent: parseForwardAgentValue(block.props.forwardagent)
414
420
  };
415
421
  try {
416
422
  this.create(payload);
@@ -500,6 +506,16 @@ function normalizeProxyCommand(raw) {
500
506
  if (trimmed.toLowerCase() === "none") return void 0;
501
507
  return trimmed;
502
508
  }
509
+ /**
510
+ * Read an ssh_config `ForwardAgent` value into the stored boolean flag. Only
511
+ * an explicit yes/true/on enables forwarding; an absent value, no/false/off,
512
+ * and anything unrecognized leave it off instead of failing the import — an
513
+ * unknown keyword must never cost the user the whole Host block.
514
+ */
515
+ function parseForwardAgentValue(raw) {
516
+ const value = raw?.trim().toLowerCase();
517
+ return value === "yes" || value === "true" || value === "on";
518
+ }
503
519
  /** Expand a leading `~` in a filesystem path. */
504
520
  function expandHome(path) {
505
521
  if (path === "~") return homedir();
@@ -713,10 +729,16 @@ function startProxyCommand(rawCommand, target) {
713
729
  * Connection pool: per-alias persistent ssh2 connections with multi-hop jump
714
730
  * support, the acquire / dispose / sweep lifecycle, and the pooled exec path.
715
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;
716
738
  /** Default engine knobs (applied when an option is omitted). */
717
739
  const DEFAULTS = {
718
740
  idleTimeoutMs: 30 * 6e4,
719
- connectTimeoutMs: 15e3,
741
+ connectTimeoutMs: DEFAULT_CONNECT_TIMEOUT_MS,
720
742
  keepaliveIntervalMs: 15e3,
721
743
  maxOutputBytes: 2 * 1024 * 1024,
722
744
  defaultExecTimeoutMs: 6e4,
@@ -746,21 +768,71 @@ function buildConnectConfig(entry, sock, opts) {
746
768
  config.privateKey = readFileSync(keyPath, "utf8");
747
769
  if (entry.auth.passphrase !== void 0 && entry.auth.passphrase !== "") config.passphrase = entry.auth.passphrase;
748
770
  }
771
+ if (entry.forwardAgent === true) {
772
+ const agentPath = typeof config.agent === "string" ? config.agent : resolveForwardAgentPath(entry.auth.agentPath);
773
+ if (agentPath === void 0) throw new Error("agent forwarding is enabled for this host but no ssh-agent endpoint is available: set SSH_AUTH_SOCK, start Pageant on Windows, or configure an agent path");
774
+ config.agent = agentPath;
775
+ config.agentForward = true;
776
+ }
749
777
  return config;
750
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";
751
788
  /** Resolve the ssh2 agent path for 'agent' auth. */
752
789
  function resolveAgentPath(agentPath) {
753
790
  const explicit = normalizeAgentPath(agentPath);
754
791
  if (explicit !== void 0) return explicit;
755
792
  const sock = process.env.SSH_AUTH_SOCK;
756
793
  if (sock !== void 0 && sock !== "") return sock;
757
- if (process.platform === "win32") return "pageant";
794
+ if (process.platform === "win32") return WINDOWS_AGENT_PIPE;
795
+ }
796
+ /**
797
+ * Resolve the ssh-agent endpoint that forwarding brokers signatures through:
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.
801
+ *
802
+ * Forwarding shares the auth resolution on purpose — the endpoint a host
803
+ * signs through is the same one it authenticates with — but it is a separate
804
+ * name so the forwarding path can evolve without touching auth.
805
+ */
806
+ function resolveForwardAgentPath(agentPath) {
807
+ return resolveAgentPath(agentPath);
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";
758
829
  }
759
830
  /** Connect one ssh2 client (resolve on ready, reject on error/close). */
760
831
  function connectClient(config, onKeyboardInteractive) {
761
832
  return new Promise((resolve, reject) => {
762
833
  const client = new Client();
763
834
  let settled = false;
835
+ let handshakeComplete = false;
764
836
  const fail = (error) => {
765
837
  if (settled) return;
766
838
  settled = true;
@@ -771,8 +843,12 @@ function connectClient(config, onKeyboardInteractive) {
771
843
  try {
772
844
  client.destroy();
773
845
  } catch {}
774
- 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);
775
848
  };
849
+ client.once("handshake", () => {
850
+ handshakeComplete = true;
851
+ });
776
852
  client.once("ready", () => {
777
853
  if (settled) return;
778
854
  settled = true;
@@ -865,6 +941,12 @@ function parseJumpSpec(spec) {
865
941
  * Resolve one ProxyJump spec: an alias configured in this plugin wins, and any
866
942
  * other value is read as an OpenSSH address whose credentials come from the
867
943
  * target entry (an ad-hoc hop has no stored auth of its own).
944
+ *
945
+ * An address hop deliberately carries no forwardAgent flag: OpenSSH's
946
+ * ForwardAgent is a per-Host setting and an ad-hoc address was never
947
+ * configured, so it must never inherit the target's opt-in. A hop written as
948
+ * an alias uses that alias's own entry, which is how a user forwards on a
949
+ * bastion on purpose.
868
950
  */
869
951
  function resolveHop(engine, entry, spec) {
870
952
  const configured = engine.store.find(spec);
@@ -1663,6 +1745,15 @@ var SshEngine = class {
1663
1745
  this.sweepTimer = setInterval(() => sweepPool(this), Math.max(1e4, this.opts.idleTimeoutMs / 4));
1664
1746
  this.sweepTimer.unref?.();
1665
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
+ }
1666
1757
  /** Secret-free host list (filtered by the optional query). */
1667
1758
  list(query) {
1668
1759
  const needle = query?.trim().toLowerCase();
@@ -2088,12 +2179,26 @@ function isLoopbackHostname(hostname) {
2088
2179
  return isIPv4Loopback(hostname);
2089
2180
  }
2090
2181
  /**
2182
+ * Whether a reverse proxy stood between the client and this host: the request
2183
+ * carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
2184
+ * hop that forwards traffic, so the request did not originate on this machine.
2185
+ * @param request - node HTTP request.
2186
+ * @returns true when a forwarding header is present.
2187
+ */
2188
+ function isProxiedRequest(request) {
2189
+ return request.headers["cf-connecting-ip"] !== void 0 || request.headers["x-forwarded-for"] !== void 0;
2190
+ }
2191
+ /**
2091
2192
  * Request-level trust fence: a loopback socket address AND a loopback Host
2092
2193
  * header, plus browser same-origin markers. The socket address is
2093
- * authoritative; X-Forwarded-For is never trusted.
2194
+ * authoritative for a direct connection; a request that carries a forwarding
2195
+ * header is refused outright, because a proxy in front of the host makes both
2196
+ * the socket address and the Host header describe the proxy rather than the
2197
+ * client. X-Forwarded-For is therefore never evidence *for* loopback.
2094
2198
  */
2095
2199
  function isLoopbackRequest(request) {
2096
2200
  if (!isLoopbackAddress(request.socket.remoteAddress)) return false;
2201
+ if (isProxiedRequest(request)) return false;
2097
2202
  const host = request.headers.host;
2098
2203
  if (typeof host !== "string") return false;
2099
2204
  let hostUrl;
@@ -2227,7 +2332,8 @@ function makeRoutes(deps) {
2227
2332
  "user",
2228
2333
  "auth",
2229
2334
  "proxyJump",
2230
- "proxyCommand"
2335
+ "proxyCommand",
2336
+ "forwardAgent"
2231
2337
  ].some((key) => patch[key] !== void 0)) engine.dropAlias(alias);
2232
2338
  writeJson(res, 200, { host: store.summarize(entry) });
2233
2339
  } catch (error) {
@@ -2632,8 +2738,8 @@ function toAgentHostRow(host) {
2632
2738
  function renderHosts(hosts) {
2633
2739
  if (hosts.length === 0) return "no hosts configured";
2634
2740
  return [
2635
- "alias | host | port | user | auth | proxy | environment | tags | description",
2636
- "--- | --- | --- | --- | --- | --- | --- | --- | ---",
2741
+ "alias | host | port | user | auth | proxy | forward | environment | tags | description",
2742
+ "--- | --- | --- | --- | --- | --- | --- | --- | --- | ---",
2637
2743
  ...hosts.map((host) => [
2638
2744
  host.alias,
2639
2745
  host.host,
@@ -2641,6 +2747,7 @@ function renderHosts(hosts) {
2641
2747
  host.user,
2642
2748
  host.auth,
2643
2749
  host.proxyJump.length > 0 ? "jump:" + host.proxyJump.join(",") : host.proxyCommandConfigured ? "proxy-command" : "-",
2750
+ host.forwardAgent ? "yes" : "-",
2644
2751
  host.environment ?? "-",
2645
2752
  host.tags.length > 0 ? host.tags.join(",") : "-",
2646
2753
  host.description ?? ""
@@ -2673,7 +2780,7 @@ function renderTunnel(tunnel) {
2673
2780
  function sshListTool(engine) {
2674
2781
  return defineTool({
2675
2782
  name: "ssh_list",
2676
- description: "List configured SSH hosts (alias, host, user, auth, environment, tags, description). Use ssh_exec etc. with the alias.",
2783
+ description: "List configured SSH hosts (alias, host, user, auth, agent forwarding, environment, tags, description). Use ssh_exec etc. with the alias.",
2677
2784
  parameters: { query: {
2678
2785
  type: "string",
2679
2786
  description: "Optional fuzzy match against alias, description, host, and tags."
@@ -2727,6 +2834,10 @@ function sshListTool(engine) {
2727
2834
  type: "boolean",
2728
2835
  required: true
2729
2836
  },
2837
+ forwardAgent: {
2838
+ type: "boolean",
2839
+ required: true
2840
+ },
2730
2841
  description: { type: "string" },
2731
2842
  environment: { type: "string" },
2732
2843
  tags: {
@@ -2773,7 +2884,7 @@ function sshExecTool(engine) {
2773
2884
  },
2774
2885
  timeoutMs: {
2775
2886
  type: "integer",
2776
- 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."
2777
2888
  }
2778
2889
  },
2779
2890
  output: {
@@ -3156,7 +3267,7 @@ function sshClusterTool(engine) {
3156
3267
  },
3157
3268
  timeoutMs: {
3158
3269
  type: "integer",
3159
- 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)."
3160
3271
  },
3161
3272
  maxWorkers: {
3162
3273
  type: "integer",
@@ -3350,7 +3461,8 @@ function mountOnce(packageName, fn) {
3350
3461
  */
3351
3462
  const PLUGIN_TOOL_SECTION_ORDERS = {
3352
3463
  ssh: 150,
3353
- "task-board": 200
3464
+ "task-board": 200,
3465
+ agents: 220
3354
3466
  };
3355
3467
  /**
3356
3468
  * Build a section provider that renders \`text\` only while at least one of
@@ -3398,7 +3510,8 @@ const inject = [
3398
3510
  const Config = z.object({
3399
3511
  announceToAgent: z.boolean().default(false).volatile(),
3400
3512
  enabled: z.boolean().default(true).volatile(),
3401
- 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.")
3402
3515
  });
3403
3516
  /** Schema defaults, re-read for hand-built test contexts (the loader applies them normally). */
3404
3517
  const DEFAULT_ANNOUNCE = false;
@@ -3439,7 +3552,7 @@ const SSH_GUIDANCE = "本机已安装 dsh-ssh 插件(DSH 远程 SSH 运维)
3439
3552
  const apply = mountOnce("@linxin666/dsh-ssh", applyImpl);
3440
3553
  function applyImpl(ctx, config) {
3441
3554
  const store = new HostStore();
3442
- const engine = new SshEngine(store);
3555
+ const engine = new SshEngine(store, { connectTimeoutMs: readConfigField(config?.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS) });
3443
3556
  ctx.effect(() => () => {
3444
3557
  engine.dispose();
3445
3558
  }, "dsh-ssh: engine");
@@ -3467,6 +3580,7 @@ function applyImpl(ctx, config) {
3467
3580
  let disposeTools;
3468
3581
  let disposeSection;
3469
3582
  const sync = () => {
3583
+ engine.setConnectTimeout(readConfigField(config?.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS));
3470
3584
  const value = resolve();
3471
3585
  if (disposeSection !== void 0) {
3472
3586
  disposeSection();
@@ -37,6 +37,8 @@ export declare const zh: {
37
37
  readonly 'hosts.deleteConfirm': "确定删除主机「{alias}」?将同时停止其隧道。";
38
38
  readonly 'hosts.imported': "解析 {parsed} 个配置块,新增 {added} 台主机,跳过 {skipped} 个。";
39
39
  readonly 'hosts.proxyBadge': "代理";
40
+ readonly 'hosts.forwardAgentBadge': "Agent 转发";
41
+ readonly 'hosts.forwardAgentHint': "仅对可信主机开启:远端可用本机私钥签名(等价 ssh -A)。";
40
42
  readonly 'import.reason.wildcard': "通配符 pattern,需手动配置";
41
43
  readonly 'import.reason.existing': "别名已存在";
42
44
  readonly 'import.reason.match': "Match 条件块,不支持";
@@ -59,8 +61,8 @@ export declare const zh: {
59
61
  readonly 'form.auth.password': "密码";
60
62
  readonly 'form.auth.agent': "SSH Agent";
61
63
  readonly 'form.agentPath': "Agent 路径";
62
- readonly 'form.agentPathHint': "留空自动检测(SSH_AUTH_SOCK / Windows Pageant);也可填 socket 路径或 pageant";
63
- readonly 'form.authKeepHint': "编辑时密钥/密码/Agent 留空将保留原认证方式与已存凭据;如需更换认证方式请填写新凭据。";
64
+ readonly 'form.agentPathHint': "留空自动检测(SSH_AUTH_SOCK;Windows 上为原生 ssh-agent 命名管道);也可填 socket 路径或 pageant";
65
+ readonly 'form.authKeepHint': "编辑时密码 / 私钥留空将保留已存凭据;Agent 路径留空是合法的自动检测,选「SSH Agent」即切换到 agent 认证。";
64
66
  readonly 'form.keyPath': "私钥路径";
65
67
  readonly 'form.keyPathHint': "如 ~/.ssh/id_ed25519";
66
68
  readonly 'form.passphrase': "密钥口令";
@@ -71,6 +73,8 @@ export declare const zh: {
71
73
  readonly 'form.proxyJumpHint': "逗号分隔的本地主机别名,或 [user@]host[:port] 地址,按顺序连接";
72
74
  readonly 'form.proxyCommand': "ProxyCommand";
73
75
  readonly 'form.proxyCommandHint': "OpenSSH ProxyCommand:%h 主机、%p 端口、%r 用户、%n 别名;留空或填 none 表示不使用。与跳板机别名互斥。";
76
+ readonly 'form.forwardAgent': "启用 Agent 转发";
77
+ readonly 'form.forwardAgentHint': "把本机 SSH Agent 转发到该主机(等价 ssh -A):远端可用本机私钥签名。仅对可信主机开启。";
74
78
  readonly 'form.description': "备注";
75
79
  readonly 'form.environment': "环境";
76
80
  readonly 'form.environmentHint': "如 development / production";
@@ -6,8 +6,12 @@
6
6
  * The payload carries no conversation data and no identifiers beyond a random
7
7
  * UUID generated in localStorage; the server hashes it with a deployment salt
8
8
  * before storage and never persists IP addresses. Sends are fire-and-forget:
9
- * failures stay silent and simply retry on a later mount or day. The system
10
- * is documented in docs/telemetry.md.
9
+ * failures stay silent and simply retry on a later mount or day. Frames where
10
+ * storage is unavailable report nothing.
11
+ *
12
+ * The family-wide opt-out and the browser's Do Not Track signal both suppress
13
+ * the heartbeat; the Web Plugins settings switch writes the same localStorage
14
+ * key. The system is documented in docs/telemetry.md.
11
15
  */
12
16
  export type TelemetryChannel = 'market' | 'npm' | 'unknown';
13
17
  export interface TelemetryItem {
@@ -18,6 +22,14 @@ export interface TelemetryItem {
18
22
  /** Install channel when determinable (market = Workshop install). */
19
23
  channel?: TelemetryChannel;
20
24
  }
25
+ /** localStorage key carrying the family-wide telemetry opt-out ('1' = off). */
26
+ export declare const TELEMETRY_OPT_OUT_KEY = "dsh-web-ui-telemetry-opt-out";
27
+ /** Whether the user switched the family-wide opt-out on (reads storage only). */
28
+ export declare function isTelemetryOptedOut(): boolean;
29
+ /** Turn the family-wide opt-out on or off (writing '1' / removing the key); never throws. */
30
+ export declare function setTelemetryOptedOut(optedOut: boolean): void;
31
+ /** Whether a heartbeat must be suppressed right now: opt-out stored, or the browser asks not to be tracked. */
32
+ export declare function isTelemetrySuppressed(): boolean;
21
33
  /**
22
34
  * Fire the daily heartbeat for the given items at most once per UTC day per
23
35
  * browser. Never throws and never blocks the caller. Items without an explicit
@@ -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,13 +57,49 @@ 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;
71
+ /**
72
+ * Resolve the ssh-agent endpoint that forwarding brokers signatures through:
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.
76
+ *
77
+ * Forwarding shares the auth resolution on purpose — the endpoint a host
78
+ * signs through is the same one it authenticates with — but it is a separate
79
+ * name so the forwarding path can evolve without touching auth.
80
+ */
81
+ export declare function resolveForwardAgentPath(agentPath?: string): string | undefined;
53
82
  /** Keyboard-interactive handler callback for 2FA / dynamic prompt flow. */
54
83
  export type KeyboardInteractiveHandler = (name: string, instructions: string, instructionsLang: string, prompts: Array<{
55
84
  prompt: string;
56
85
  echo: boolean;
57
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;
58
103
  /** Connect one ssh2 client (resolve on ready, reject on error/close). */
59
104
  export declare function connectClient(config: ConnectConfig, onKeyboardInteractive?: KeyboardInteractiveHandler): Promise<Client>;
60
105
  /** Cap captured output at the configured byte budget (marks truncation). */
@@ -76,6 +121,12 @@ export declare function parseJumpSpec(spec: string): {
76
121
  * Resolve one ProxyJump spec: an alias configured in this plugin wins, and any
77
122
  * other value is read as an OpenSSH address whose credentials come from the
78
123
  * target entry (an ad-hoc hop has no stored auth of its own).
124
+ *
125
+ * An address hop deliberately carries no forwardAgent flag: OpenSSH's
126
+ * ForwardAgent is a per-Host setting and an ad-hoc address was never
127
+ * configured, so it must never inherit the target's opt-in. A hop written as
128
+ * an alias uses that alias's own entry, which is how a user forwards on a
129
+ * bastion on purpose.
79
130
  */
80
131
  export declare function resolveHop(engine: PoolEngine, entry: SshHostEntry, spec: string): SshHostEntry;
81
132
  /**
@@ -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";
@@ -7,6 +7,19 @@
7
7
  * Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8 (matching the
8
8
  * remote-web-ui gate), localhost hostnames, plus the browser same-origin
9
9
  * markers (sec-fetch-site and Origin) for the request-level fence.
10
+ *
11
+ * A reverse proxy in front of the host rewrites the Host header to its own
12
+ * upstream literal (a Cloudflare tunnel, frp and an nginx reverse proxy all
13
+ * dial 127.0.0.1:<port>), and the socket the origin sees is the proxy's, which
14
+ * is loopback by construction. Both halves of the fence then hold for a public
15
+ * request. Forwarding headers are the signal that a hop stands in between: a
16
+ * request that carries CF-Connecting-IP or X-Forwarded-For is answered through
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).
10
23
  * @module dsh-web-shared/host/loopback
11
24
  */
12
25
  import type { IncomingMessage } from 'node:http';
@@ -16,9 +29,36 @@ export declare function isIPv4Loopback(v4: string): boolean;
16
29
  export declare function isLoopbackAddress(address: string | undefined): boolean;
17
30
  /** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
18
31
  export declare function isLoopbackHostname(hostname: string): boolean;
32
+ /**
33
+ * Whether a reverse proxy stood between the client and this host: the request
34
+ * carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
35
+ * hop that forwards traffic, so the request did not originate on this machine.
36
+ * @param request - node HTTP request.
37
+ * @returns true when a forwarding header is present.
38
+ */
39
+ export declare function isProxiedRequest(request: IncomingMessage): boolean;
19
40
  /**
20
41
  * Request-level trust fence: a loopback socket address AND a loopback Host
21
42
  * header, plus browser same-origin markers. The socket address is
22
- * authoritative; X-Forwarded-For is never trusted.
43
+ * authoritative for a direct connection; a request that carries a forwarding
44
+ * header is refused outright, because a proxy in front of the host makes both
45
+ * the socket address and the Host header describe the proxy rather than the
46
+ * client. X-Forwarded-For is therefore never evidence *for* loopback.
23
47
  */
24
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
  };
@@ -48,6 +48,12 @@ export interface SshHostEntry {
48
48
  tags: string[];
49
49
  /** Physical location note. */
50
50
  location?: string;
51
+ /**
52
+ * Opt-in ssh-agent forwarding (OpenSSH ForwardAgent / ssh -A): the host's
53
+ * sessions request agent forwarding so the remote can sign with this
54
+ * machine's agent. Default off; stored only when enabled.
55
+ */
56
+ forwardAgent?: boolean;
51
57
  createdAt: number;
52
58
  updatedAt: number;
53
59
  }
@@ -67,6 +73,12 @@ export interface SshHostSummary {
67
73
  environment?: string;
68
74
  tags: string[];
69
75
  location?: string;
76
+ /**
77
+ * Whether agent forwarding is enabled. Always projected as a definite
78
+ * boolean: the browser and the tool bridge need a value even for entries
79
+ * stored before the feature existed.
80
+ */
81
+ forwardAgent: boolean;
70
82
  createdAt: number;
71
83
  updatedAt: number;
72
84
  }
@@ -150,6 +162,11 @@ export interface HostPayload {
150
162
  environment?: string;
151
163
  tags?: string[];
152
164
  location?: string;
165
+ /**
166
+ * Agent forwarding for this host. Omitted on update keeps the stored value;
167
+ * false clears it (PATCH semantics).
168
+ */
169
+ forwardAgent?: boolean;
153
170
  }
154
171
  /** Why one ssh_config Host block was not imported. */
155
172
  export type ImportSkipReason = 'wildcard' | 'existing' | 'match' | 'invalid';
@@ -67,5 +67,12 @@ export declare function normalizeAgentPath(agentPath: string | undefined): strin
67
67
  * OpenSSH's `none` keyword as "no proxy command" (an explicit clear).
68
68
  */
69
69
  export declare function normalizeProxyCommand(raw: string | undefined): string | undefined;
70
+ /**
71
+ * Read an ssh_config `ForwardAgent` value into the stored boolean flag. Only
72
+ * an explicit yes/true/on enables forwarding; an absent value, no/false/off,
73
+ * and anything unrecognized leave it off instead of failing the import — an
74
+ * unknown keyword must never cost the user the whole Host block.
75
+ */
76
+ export declare function parseForwardAgentValue(raw: string | undefined): boolean;
70
77
  /** Expand a leading `~` in a filesystem path. */
71
78
  export declare function expandHome(path: string): string;
@@ -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;