@pyrokine/mcp-ssh 3.0.0 → 3.2.0

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.
@@ -110,10 +110,11 @@ async function handleOperationList(args) {
110
110
  }
111
111
  export function registerOperationTools(server) {
112
112
  server.registerTool('ssh_operation_start', {
113
- description: `启动可跟踪的长时间远端命令
114
-
115
- 返回不可预测的 operationId。channel 建立受 startTimeoutMs 限制,等待期间 record 可通过 list 查询;超时 details 返回 operationId。
116
- 输出保存在有硬上限的内存缓冲区中,完成后按 retentionMs 自动过期。普通 ssh_exec 的同步和 timeout 行为不变。`,
113
+ description: '启动可跟踪的长时间远端命令\n' +
114
+ '\n' +
115
+ '返回不可预测的 operationId。channel 建立受 startTimeoutMs 限制,等待期间 record 可通过 list ' +
116
+ '查询;超时 details 返回 operationId。\n' +
117
+ '输出保存在有硬上限的内存缓冲区中,完成后按 retentionMs 自动过期。普通 ssh_exec 的同步和 timeout 行为不变。',
117
118
  inputSchema: operationStartSchema,
118
119
  }, (args) => handleOperationStart(args));
119
120
  server.registerTool('ssh_operation_status', {
@@ -125,7 +126,8 @@ export function registerOperationTools(server) {
125
126
  inputSchema: operationReadSchema,
126
127
  }, (args) => handleOperationRead(args));
127
128
  server.registerTool('ssh_operation_cancel', {
128
- description: '校验远端 operation marker 和进程身份后执行取消;POSIX 发送 TERM,Windows 在 PID、创建时间和 marker 验证后执行 taskkill /T /F;无法证明身份时拒绝取消',
129
+ description: '校验远端 operation marker 和进程身份后执行取消;POSIX 发送 TERM,Windows 在 PID、创建时间和 ' +
130
+ 'marker 验证后执行 taskkill /T /F;无法证明身份时拒绝取消',
129
131
  inputSchema: operationIdSchema,
130
132
  }, (args) => handleOperationCancel(args));
131
133
  server.registerTool('ssh_operation_list', {
package/dist/tools/pty.js CHANGED
@@ -74,7 +74,7 @@ async function handlePtyWrite(args) {
74
74
  }
75
75
  async function handlePtyRead(args) {
76
76
  try {
77
- const readResult = sessionManager.ptyRead(args.ptyId, {
77
+ const readResult = await sessionManager.ptyRead(args.ptyId, {
78
78
  mode: args.mode ?? 'screen',
79
79
  clear: args.clear !== false,
80
80
  });
@@ -159,17 +159,19 @@ write 返回 accepted=true 表示数据已被本地 stream 接收。backpressure
159
159
  inputSchema: ptyWriteSchema,
160
160
  }, (args) => handlePtyWrite(args));
161
161
  server.registerTool('ssh_pty_read', {
162
- description: `读取 PTY 输出
163
-
164
- 两种模式:
165
- - screen(默认):返回当前屏幕内容(解析后的纯文本,适合 top/btop/htop 等全屏刷新工具)
166
- - raw:data 为 UTF-8 文本预览,dataBase64 为原始 ANSI/二进制字节的无损 base64
167
-
168
- bufferSize、unreadRawBytes 和 rawBufferLimit 均按原始字节计数。rawBufferTruncated=true 表示本次 clear 之后已有更早的 raw 输出因上限被丢弃;raw 读取使用默认 clear=true 时,响应返回清理前的计数和标志,然后重置缓冲区。
169
-
170
- 示例:
171
- - 获取 top 当前画面: ssh_pty_read(ptyId="xxx")
172
- - 获取原始输出: ssh_pty_read(ptyId="xxx", mode="raw")`,
162
+ description: '读取 PTY 输出\n' +
163
+ '\n' +
164
+ '两种模式:\n' +
165
+ '- screen(默认):返回当前屏幕内容(解析后的纯文本,适合 top/btop/htop 等全屏刷新工具)\n' +
166
+ '- raw:data 为 UTF-8 文本预览,dataBase64 为原始 ANSI/二进制字节的无损 base64\n' +
167
+ '\n' +
168
+ 'bufferSize、unreadRawBytes 和 rawBufferLimit ' +
169
+ '均按原始字节计数。rawBufferTruncated=true 表示本次 clear 之后已有更早的 raw 输出因上限被丢弃;raw ' +
170
+ '读取使用默认 clear=true 时,响应返回清理前的计数和标志,然后重置缓冲区。\n' +
171
+ '\n' +
172
+ '示例:\n' +
173
+ '- 获取 top 当前画面: ssh_pty_read(ptyId="xxx")\n' +
174
+ '- 获取原始输出: ssh_pty_read(ptyId="xxx", mode="raw")',
173
175
  inputSchema: ptyReadSchema,
174
176
  }, (args) => handlePtyRead(args));
175
177
  server.registerTool('ssh_pty_resize', {
@@ -181,7 +183,8 @@ bufferSize、unreadRawBytes 和 rawBufferLimit 均按原始字节计数。rawBuf
181
183
  inputSchema: ptyCloseSchema,
182
184
  }, (args) => handlePtyClose(args));
183
185
  server.registerTool('ssh_pty_list', {
184
- description: '列出所有 PTY 会话。bufferSize、unreadRawBytes 和 rawBufferLimit 使用原始字节,rawBufferTruncated 表示更早的 raw 输出已因缓冲区上限被丢弃。',
186
+ description: '列出所有 PTY 会话。bufferSize、unreadRawBytes 和 rawBufferLimit ' +
187
+ '使用原始字节,rawBufferTruncated 表示更早的 raw 输出已因缓冲区上限被丢弃。',
185
188
  inputSchema: ptyListSchema,
186
189
  }, () => handlePtyList());
187
190
  }
@@ -19,7 +19,7 @@ export declare function formatResult(data: unknown): {
19
19
  /**
20
20
  * 格式化错误响应
21
21
  */
22
- export declare function formatError(error: unknown): {
22
+ export declare function formatError(error: unknown, context?: Record<string, unknown>): {
23
23
  content: {
24
24
  type: 'text';
25
25
  text: string;
@@ -28,7 +28,7 @@ export function formatResult(data) {
28
28
  /**
29
29
  * 格式化错误响应
30
30
  */
31
- export function formatError(error) {
31
+ export function formatError(error, context = {}) {
32
32
  const message = error instanceof Error ? error.message : String(error);
33
33
  const details = typeof error === 'object' && error !== null && 'details' in error
34
34
  ? error.details
@@ -37,7 +37,7 @@ export function formatError(error) {
37
37
  content: [
38
38
  {
39
39
  type: 'text',
40
- text: JSON.stringify({ success: false, error: message, ...(details ? { details } : {}) }, null, 2),
40
+ text: JSON.stringify({ success: false, error: message, ...(details ? { details } : {}), ...context }, null, 2),
41
41
  },
42
42
  ],
43
43
  isError: true,
package/dist/types.d.ts CHANGED
@@ -1,6 +1,24 @@
1
1
  /**
2
2
  * SSH MCP Pro - 类型定义
3
3
  */
4
+ import type { Readable } from 'stream';
5
+ export interface CommandChannel extends Readable {
6
+ readonly stderr: Readable;
7
+ readonly ready?: Promise<void>;
8
+ close(): void;
9
+ }
10
+ export interface OpenSshMasterInfo {
11
+ backend: 'openssh';
12
+ masterReused: true;
13
+ identityStatus: 'master_trusted';
14
+ masterPid: number;
15
+ observedLogin?: {
16
+ uid: number;
17
+ username: string;
18
+ sshConnection?: string;
19
+ };
20
+ }
21
+ export declare const DEFAULT_EXEC_TIMEOUT_MS = 30000;
4
22
  export declare const DEFAULT_EXEC_MAX_OUTPUT_SIZE: number;
5
23
  export declare const HARD_EXEC_MAX_OUTPUT_SIZE: number;
6
24
  export type RemotePlatform = 'posix' | 'windows';
@@ -8,6 +26,8 @@ export type CommandShell = 'posix' | 'cmd' | 'powershell';
8
26
  export type RemotePathStyle = 'posix' | 'win32' | 'sftp-posix';
9
27
  export type RsyncProfile = 'posix' | 'native-win32' | 'msys2' | 'cygwin';
10
28
  export interface SSHConnectionConfig {
29
+ backend?: 'ssh2' | 'openssh';
30
+ controlPath?: string;
11
31
  host: string;
12
32
  port: number;
13
33
  username: string;
@@ -34,6 +54,9 @@ export interface SSHConnectionConfig {
34
54
  jumpHost?: SSHConnectionConfig;
35
55
  }
36
56
  export interface SSHSessionBrief {
57
+ backend?: 'ssh2' | 'openssh';
58
+ masterReused?: boolean;
59
+ identityStatus?: 'master_trusted';
37
60
  alias: string;
38
61
  identity: string;
39
62
  runAs?: string;
@@ -44,7 +67,7 @@ export interface SSHSessionDetail extends SSHSessionBrief {
44
67
  host: string;
45
68
  port: number;
46
69
  username: string;
47
- authMethod: 'key' | 'password' | 'agent' | 'inline-key';
70
+ authMethod: 'key' | 'password' | 'agent' | 'inline-key' | 'master';
48
71
  connectedAt: number;
49
72
  hasJumpHost: boolean;
50
73
  remotePlatform: RemotePlatform;
@@ -52,12 +75,14 @@ export interface SSHSessionDetail extends SSHSessionBrief {
52
75
  remotePathStyle: RemotePathStyle;
53
76
  }
54
77
  export interface ExternalTransferCapability {
78
+ backend?: 'ssh2' | 'openssh';
79
+ controlPath?: string;
55
80
  alias: string;
56
81
  identity: string;
57
82
  host: string;
58
83
  port: number;
59
84
  username: string;
60
- authMethod: 'key-path' | 'password' | 'agent' | 'inline-key';
85
+ authMethod: 'key-path' | 'password' | 'agent' | 'inline-key' | 'master';
61
86
  keyPath?: string;
62
87
  hasJumpHost: boolean;
63
88
  routeSafeForOpenSsh: boolean;
@@ -69,7 +94,7 @@ export interface ExternalTransferCapability {
69
94
  commandShell?: CommandShell;
70
95
  remotePathStyle?: RemotePathStyle;
71
96
  }
72
- export type ConnectionFailureStage = 'preflight' | 'authentication' | 'ready_timeout' | 'transport_or_handshake' | 'unknown';
97
+ export type ConnectionFailureStage = 'preflight' | 'authentication' | 'ready_timeout' | 'transport_or_handshake' | 'host_key' | 'unknown';
73
98
  export type ConnectionStep = 'key_read' | 'jump_connect' | 'jump_forward' | 'target_connect';
74
99
  export interface ConnectionFailureDetails {
75
100
  failureStage: ConnectionFailureStage;
@@ -77,6 +102,18 @@ export interface ConnectionFailureDetails {
77
102
  retryable: boolean;
78
103
  suggestion?: string;
79
104
  keyAclStatus?: 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
105
+ hostKey?: {
106
+ algorithm?: string;
107
+ keyType: string;
108
+ fingerprint: string;
109
+ knownKeys: {
110
+ keyType: string;
111
+ fingerprint: string;
112
+ file: string;
113
+ line: number;
114
+ revoked: boolean;
115
+ }[];
116
+ };
80
117
  }
81
118
  export interface ExecOptions {
82
119
  timeout?: number;
@@ -96,7 +133,10 @@ export interface ExecResult {
96
133
  success: boolean;
97
134
  stdout: string;
98
135
  stderr: string;
99
- exitCode: number;
136
+ exitCode: number | null;
137
+ exitSignal?: string;
138
+ operationStatus?: 'completed' | 'failed' | 'unknown';
139
+ retryable?: boolean;
100
140
  duration: number;
101
141
  failureKind?: 'remote_command' | 'ssh_transport' | 'timeout';
102
142
  stdoutTruncated?: boolean;
@@ -116,7 +156,7 @@ export interface ExecResult {
116
156
  identity?: string;
117
157
  cwd?: string;
118
158
  resolvedCwd?: string;
119
- shell?: string;
159
+ shell?: CommandShell;
120
160
  profileLoaded?: boolean;
121
161
  envInjectedKeys?: string[];
122
162
  timedOut?: boolean;
@@ -226,6 +266,7 @@ export interface PtySessionInfo {
226
266
  active: boolean;
227
267
  }
228
268
  export interface PtyReadResult {
269
+ parserError?: string;
229
270
  data: string;
230
271
  dataBase64?: string;
231
272
  active: boolean;
package/dist/types.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * SSH MCP Pro - 类型定义
3
3
  */
4
+ export const DEFAULT_EXEC_TIMEOUT_MS = 30_000;
4
5
  export const DEFAULT_EXEC_MAX_OUTPUT_SIZE = 10 * 1024 * 1024;
5
6
  export const HARD_EXEC_MAX_OUTPUT_SIZE = 50 * 1024 * 1024;
package/dist/utf8.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare function isUtf8ContinuationByte(value: number): boolean;
2
2
  export declare function ensureUtf8Boundary(buffer: Buffer, offset: number, field: string): void;
3
3
  export declare function retainUtf8Suffix(buffer: Buffer, maxBytes: number): Buffer;
4
- export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean): number;
4
+ export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean, allowEmpty?: boolean): number;
package/dist/utf8.js CHANGED
@@ -31,7 +31,7 @@ export function retainUtf8Suffix(buffer, maxBytes) {
31
31
  }
32
32
  return buffer.subarray(start);
33
33
  }
34
- export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length) {
34
+ export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length, allowEmpty = false) {
35
35
  let end = requestedEnd;
36
36
  if (limitedByMaxBytes) {
37
37
  while (end > start && isUtf8ContinuationByte(buffer[end])) {
@@ -47,7 +47,7 @@ export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxByt
47
47
  end = sequenceStart;
48
48
  }
49
49
  }
50
- if (end === start && requestedEnd > start && limitedByMaxBytes) {
50
+ if (end === start && requestedEnd > start && limitedByMaxBytes && !allowEmpty) {
51
51
  throw new Error(`maxBytes is too small to read the next UTF-8 character from ${stream}`);
52
52
  }
53
53
  return end;
@@ -1,4 +1,5 @@
1
1
  export type AclStatus = 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
2
2
  export declare function windowsAclScript(filePath: string, apply: boolean): string;
3
3
  export declare function windowsTemporaryPathScript(name: string): string;
4
+ export declare function checkWindowsKnownHostsIntegrity(filePath: string): void;
4
5
  export declare function checkWindowsAcl(filePath: string, apply?: boolean): AclStatus;
@@ -2,90 +2,177 @@ import { spawnSync } from 'node:child_process';
2
2
  import { encodedPowershell, quotePowershell } from './remote-platform.js';
3
3
  export function windowsAclScript(filePath, apply) {
4
4
  const target = quotePowershell(filePath);
5
- return `
6
- $ErrorActionPreference = 'Stop'
7
- $path = ${target}
8
- $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
9
- $system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18')
10
- $administrators = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544')
11
- $allowed = @($identity.Value, $system.Value, $administrators.Value)
12
- $acl = Get-Acl -LiteralPath $path
13
- ${apply
14
- ? `
15
- $acl.SetAccessRuleProtection($true, $false)
16
- foreach ($rule in @($acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))) {
17
- $acl.RemoveAccessRuleSpecific($rule)
18
- }
19
- foreach ($sid in @($identity, $system, $administrators)) {
20
- $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($sid, [System.Security.AccessControl.FileSystemRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow)
21
- $acl.AddAccessRule($rule)
22
- }
23
- Set-Acl -LiteralPath $path -AclObject $acl
24
- $acl = Get-Acl -LiteralPath $path
25
- `
26
- : ''}
27
- if (-not $acl.AreAccessRulesProtected -or
28
- $allowed -notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {
29
- [Console]::WriteLine('insecure'); exit 0
30
- }
31
- $own = $false
32
- foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
33
- if ($rule.AccessControlType -eq 'Allow') {
34
- if ($allowed -notcontains $rule.IdentityReference.Value) { [Console]::WriteLine('insecure'); exit 0 }
35
- if ($rule.IdentityReference.Value -eq $identity.Value) { $own = $true }
36
- }
37
- }
38
- if (-not $own) { [Console]::WriteLine('insecure'); exit 0 }
39
- $item = Get-Item -LiteralPath $path -Force
40
- if ($item -is [IO.FileInfo]) {
41
- try {
42
- $stream = [IO.File]::Open($path, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
43
- $stream.Dispose()
44
- } catch {
45
- [Console]::WriteLine('unverified'); exit 0
46
- }
47
- }
48
- [Console]::WriteLine('usable')
49
- `;
5
+ return ('\n' +
6
+ "$ErrorActionPreference = 'Stop'\n" +
7
+ '$path = ' +
8
+ `${target}` +
9
+ '\n' +
10
+ '$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().Us' +
11
+ 'er\n' +
12
+ "$system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18'" +
13
+ ')\n' +
14
+ "$administrators = [System.Security.Principal.SecurityIdentifier]::new('S" +
15
+ "-1-5-32-544')\n" +
16
+ '$allowed = @($identity.Value, $system.Value, $administrators.Value)\n' +
17
+ '$acl = Get-Acl -LiteralPath $path\n' +
18
+ `${apply
19
+ ? '\n' +
20
+ '$acl.SetAccessRuleProtection($true, $false)\n' +
21
+ 'foreach ($rule in @($acl.GetAccessRules($true, $true, ' +
22
+ '[System.Security.Principal.SecurityIdentifier]))) {\n' +
23
+ ' $acl.RemoveAccessRuleSpecific($rule)\n' +
24
+ '}\n' +
25
+ 'foreach ($sid in @($identity, $system, $administrators)) {\n' +
26
+ ' $rule = [System.Security.AccessControl.FileSystemAccessRule]::ne' +
27
+ 'w($sid, [System.Security.AccessControl.FileSystemRights]::FullContro' +
28
+ 'l, [System.Security.AccessControl.AccessControlType]::Allow)\n' +
29
+ ' $acl.AddAccessRule($rule)\n' +
30
+ '}\n' +
31
+ 'Set-Acl -LiteralPath $path -AclObject $acl\n' +
32
+ '$acl = Get-Acl -LiteralPath $path\n'
33
+ : ''}` +
34
+ '\n' +
35
+ 'if (-not $acl.AreAccessRulesProtected -or\n' +
36
+ ' $allowed -notcontains ' +
37
+ '$acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {\n' +
38
+ " [Console]::WriteLine('insecure'); exit 0\n" +
39
+ '}\n' +
40
+ '$own = $false\n' +
41
+ 'foreach ($rule in $acl.GetAccessRules($true, $true, ' +
42
+ '[System.Security.Principal.SecurityIdentifier])) {\n' +
43
+ " if ($rule.AccessControlType -eq 'Allow') {\n" +
44
+ ' if ($allowed -notcontains $rule.IdentityReference.Value) { ' +
45
+ "[Console]::WriteLine('insecure'); exit 0 }\n" +
46
+ ' if ($rule.IdentityReference.Value -eq $identity.Value) { $own = ' +
47
+ '$true }\n' +
48
+ ' }\n' +
49
+ '}\n' +
50
+ "if (-not $own) { [Console]::WriteLine('insecure'); exit 0 }\n" +
51
+ '$item = Get-Item -LiteralPath $path -Force\n' +
52
+ 'if ($item -is [IO.FileInfo]) {\n' +
53
+ ' try {\n' +
54
+ ' $stream = [IO.File]::Open($path, [IO.FileMode]::Open, ' +
55
+ '[IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)\n' +
56
+ ' $stream.Dispose()\n' +
57
+ ' } catch {\n' +
58
+ " [Console]::WriteLine('unverified'); exit 0\n" +
59
+ ' }\n' +
60
+ '}\n' +
61
+ "[Console]::WriteLine('usable')\n");
50
62
  }
51
63
  export function windowsTemporaryPathScript(name) {
52
- return `
53
- $ErrorActionPreference = 'Stop'
54
- $temp = [IO.Path]::GetTempPath()
55
- $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
56
- $system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18')
57
- $administrators = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544')
58
- $allowed = @($identity.Value, $system.Value, $administrators.Value)
59
- $directory = Get-Item -LiteralPath $temp -Force
60
- if ($directory -isnot [IO.DirectoryInfo]) { throw 'privacy_not_enforced_on_windows: temporary path is not a directory' }
61
- $current = $directory
62
- while ($null -ne $current) {
63
- if (($current.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) {
64
- throw 'privacy_not_enforced_on_windows: temporary directory has a reparse point'
65
- }
66
- $acl = Get-Acl -LiteralPath $current.FullName
67
- if ($current.FullName -eq $directory.FullName -and $allowed -notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {
68
- throw 'privacy_not_enforced_on_windows: temporary directory owner is not trusted'
69
- }
70
- $rights = [System.Security.AccessControl.FileSystemRights]::Delete -bor
71
- [System.Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesAndFiles -bor
72
- [System.Security.AccessControl.FileSystemRights]::ChangePermissions -bor
73
- [System.Security.AccessControl.FileSystemRights]::TakeOwnership
74
- if ($current.FullName -eq $directory.FullName) {
75
- $rights = $rights -bor [System.Security.AccessControl.FileSystemRights]::Write
64
+ return ('\n' +
65
+ "$ErrorActionPreference = 'Stop'\n" +
66
+ '$temp = [IO.Path]::GetTempPath()\n' +
67
+ '$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().Us' +
68
+ 'er\n' +
69
+ "$system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18'" +
70
+ ')\n' +
71
+ "$administrators = [System.Security.Principal.SecurityIdentifier]::new('S" +
72
+ "-1-5-32-544')\n" +
73
+ '$allowed = @($identity.Value, $system.Value, $administrators.Value)\n' +
74
+ '$directory = Get-Item -LiteralPath $temp -Force\n' +
75
+ 'if ($directory -isnot [IO.DirectoryInfo]) { throw ' +
76
+ "'privacy_not_enforced_on_windows: temporary path is not a directory' }\n" +
77
+ '$current = $directory\n' +
78
+ 'while ($null -ne $current) {\n' +
79
+ ' if (($current.Attributes -band [IO.FileAttributes]::ReparsePoint) ' +
80
+ '-ne 0) {\n' +
81
+ " throw 'privacy_not_enforced_on_windows: temporary directory has " +
82
+ "a reparse point'\n" +
83
+ ' }\n' +
84
+ ' $acl = Get-Acl -LiteralPath $current.FullName\n' +
85
+ ' if ($current.FullName -eq $directory.FullName -and $allowed ' +
86
+ '-notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier' +
87
+ ']).Value) {\n' +
88
+ " throw 'privacy_not_enforced_on_windows: temporary directory " +
89
+ "owner is not trusted'\n" +
90
+ ' }\n' +
91
+ ' $rights = [System.Security.AccessControl.FileSystemRights]::Delete ' +
92
+ '-bor\n' +
93
+ ' [System.Security.AccessControl.FileSystemRights]::DeleteSubdirec' +
94
+ 'toriesAndFiles -bor\n' +
95
+ ' [System.Security.AccessControl.FileSystemRights]::ChangePermissi' +
96
+ 'ons -bor\n' +
97
+ ' [System.Security.AccessControl.FileSystemRights]::TakeOwnership\n' +
98
+ ' if ($current.FullName -eq $directory.FullName) {\n' +
99
+ ' $rights = $rights -bor ' +
100
+ '[System.Security.AccessControl.FileSystemRights]::Write\n' +
101
+ ' }\n' +
102
+ ' foreach ($rule in $acl.GetAccessRules($true, $true, ' +
103
+ '[System.Security.Principal.SecurityIdentifier])) {\n' +
104
+ " if ($rule.AccessControlType -eq 'Allow' -and\n" +
105
+ ' $allowed -notcontains $rule.IdentityReference.Value -and\n' +
106
+ ' ($rule.PropagationFlags -band ' +
107
+ '[System.Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 ' +
108
+ '-and\n' +
109
+ ' ($rule.FileSystemRights -band $rights) -ne 0) {\n' +
110
+ " throw 'privacy_not_enforced_on_windows: temporary directory " +
111
+ "allows another user to replace entries'\n" +
112
+ ' }\n' +
113
+ ' }\n' +
114
+ ' $current = $current.Parent\n' +
115
+ '}\n' +
116
+ '[Console]::WriteLine([IO.Path]::Combine($directory.FullName, ' +
117
+ `${quotePowershell(name)}` +
118
+ '))\n');
119
+ }
120
+ export function checkWindowsKnownHostsIntegrity(filePath) {
121
+ if (process.platform !== 'win32') {
122
+ throw new Error('Windows ACL verification requires a native Windows process');
76
123
  }
77
- foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
78
- if ($rule.AccessControlType -eq 'Allow' -and
79
- $allowed -notcontains $rule.IdentityReference.Value -and
80
- ($rule.PropagationFlags -band [System.Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 -and
81
- ($rule.FileSystemRights -band $rights) -ne 0) {
82
- throw 'privacy_not_enforced_on_windows: temporary directory allows another user to replace entries'
83
- }
124
+ const script = "$ErrorActionPreference = 'Stop'\n" +
125
+ '$identity = [Security.Principal.WindowsIdentity]::GetCurrent().User.Valu' +
126
+ 'e\n' +
127
+ "$trustedInstaller = [Security.Principal.NTAccount]::new('NT " +
128
+ "SERVICE\\TrustedInstaller').Translate([Security.Principal.SecurityIdentif" +
129
+ 'ier]).Value\n' +
130
+ "$allowed = @($identity, 'S-1-5-18', 'S-1-5-32-544', $trustedInstaller)\n" +
131
+ '$current = Get-Item -LiteralPath ' +
132
+ `${quotePowershell(filePath)}` +
133
+ ' -Force\n' +
134
+ '$target = $current.FullName\n' +
135
+ '$container = if ($current -is [IO.DirectoryInfo]) { $current.FullName } ' +
136
+ 'else { $current.Directory.FullName }\n' +
137
+ 'while ($null -ne $current) {\n' +
138
+ ' $acl = Get-Acl -LiteralPath $current.FullName\n' +
139
+ ' if ($allowed -notcontains ' +
140
+ '$acl.GetOwner([Security.Principal.SecurityIdentifier]).Value) { throw ' +
141
+ "'untrusted owner' }\n" +
142
+ ' $rights = [Security.AccessControl.FileSystemRights]::Delete -bor\n' +
143
+ ' [Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesA' +
144
+ 'ndFiles -bor\n' +
145
+ ' [Security.AccessControl.FileSystemRights]::ChangePermissions ' +
146
+ '-bor\n' +
147
+ ' [Security.AccessControl.FileSystemRights]::TakeOwnership\n' +
148
+ ' if ($current.FullName -eq $target -or $current.FullName -eq ' +
149
+ '$container) {\n' +
150
+ ' $rights = $rights -bor ' +
151
+ '[Security.AccessControl.FileSystemRights]::Write\n' +
152
+ ' }\n' +
153
+ ' foreach ($rule in $acl.GetAccessRules($true, $true, ' +
154
+ '[Security.Principal.SecurityIdentifier])) {\n' +
155
+ " if ($rule.AccessControlType -eq 'Allow' -and\n" +
156
+ ' $allowed -notcontains $rule.IdentityReference.Value -and\n' +
157
+ ' ($rule.PropagationFlags -band ' +
158
+ '[Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 -and\n' +
159
+ ' ($rule.FileSystemRights -band $rights) -ne 0) { throw ' +
160
+ "'untrusted writer' }\n" +
161
+ ' }\n' +
162
+ ' $current = if ($current -is [IO.DirectoryInfo]) { $current.Parent } ' +
163
+ 'else { $current.Directory }\n' +
164
+ '}\n' +
165
+ "[Console]::Write('verified')";
166
+ const encoded = encodedPowershell(script).split(' ').at(-1);
167
+ const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], {
168
+ timeout: 10_000,
169
+ encoding: 'utf8',
170
+ windowsHide: true,
171
+ maxBuffer: 16_384,
172
+ });
173
+ if (result.error || result.status !== 0 || result.stdout.trim() !== 'verified') {
174
+ throw new Error('known_hosts write integrity could not be verified on Windows');
84
175
  }
85
- $current = $current.Parent
86
- }
87
- [Console]::WriteLine([IO.Path]::Combine($directory.FullName, ${quotePowershell(name)}))
88
- `;
89
176
  }
90
177
  export function checkWindowsAcl(filePath, apply = false) {
91
178
  if (process.platform !== 'win32') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyrokine/mcp-ssh",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "A comprehensive SSH MCP Server for Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,8 +16,8 @@
16
16
  "lint": "eslint \"src/**/*.ts\" \"test/**/*.mjs\"",
17
17
  "lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.mjs\" --fix",
18
18
  "test": "npm run build && node test/run-tests.mjs",
19
- "format": "prettier --write --prose-wrap always src/ test/ README.md README_zh.md TESTING.md",
20
- "format:check": "prettier --check --prose-wrap always src/ test/ README.md README_zh.md TESTING.md"
19
+ "format": "prettier --write src/ test/ README.md README_zh.md TESTING.md",
20
+ "format:check": "prettier --check src/ test/ README.md README_zh.md TESTING.md"
21
21
  },
22
22
  "keywords": [
23
23
  "mcp",
@@ -36,7 +36,7 @@
36
36
  "@modelcontextprotocol/sdk": "^1.32.1",
37
37
  "@xterm/headless": "^6.0.0",
38
38
  "ssh2": "^1.17.0",
39
- "zod": "^4.4.3"
39
+ "zod": "^4.6.7"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@eslint/js": "^10.0.1",
@@ -56,5 +56,6 @@
56
56
  "README.md",
57
57
  "README_zh.md",
58
58
  "LICENSE"
59
- ]
59
+ ],
60
+ "gitHead": "ca40950f56a051845f89c3b4b673bf5825c0e199"
60
61
  }