@pyrokine/mcp-ssh 2.4.2 → 3.0.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.
package/dist/utf8.d.ts CHANGED
@@ -1,3 +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
+ export declare function retainUtf8Suffix(buffer: Buffer, maxBytes: number): Buffer;
3
4
  export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean): number;
package/dist/utf8.js CHANGED
@@ -21,6 +21,16 @@ export function ensureUtf8Boundary(buffer, offset, field) {
21
21
  throw new Error(`${field} must point to a UTF-8 character boundary`);
22
22
  }
23
23
  }
24
+ export function retainUtf8Suffix(buffer, maxBytes) {
25
+ if (buffer.length <= maxBytes) {
26
+ return buffer;
27
+ }
28
+ let start = buffer.length - maxBytes;
29
+ while (start < buffer.length && isUtf8ContinuationByte(buffer[start])) {
30
+ ++start;
31
+ }
32
+ return buffer.subarray(start);
33
+ }
24
34
  export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length) {
25
35
  let end = requestedEnd;
26
36
  if (limitedByMaxBytes) {
@@ -0,0 +1,4 @@
1
+ export type AclStatus = 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
2
+ export declare function windowsAclScript(filePath: string, apply: boolean): string;
3
+ export declare function windowsTemporaryPathScript(name: string): string;
4
+ export declare function checkWindowsAcl(filePath: string, apply?: boolean): AclStatus;
@@ -0,0 +1,109 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { encodedPowershell, quotePowershell } from './remote-platform.js';
3
+ export function windowsAclScript(filePath, apply) {
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
+ `;
50
+ }
51
+ 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
76
+ }
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
+ }
84
+ }
85
+ $current = $current.Parent
86
+ }
87
+ [Console]::WriteLine([IO.Path]::Combine($directory.FullName, ${quotePowershell(name)}))
88
+ `;
89
+ }
90
+ export function checkWindowsAcl(filePath, apply = false) {
91
+ if (process.platform !== 'win32') {
92
+ throw new Error('Windows ACL verification requires a native Windows process');
93
+ }
94
+ const command = encodedPowershell(windowsAclScript(filePath, apply));
95
+ const encoded = command.split(' ').at(-1);
96
+ const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], {
97
+ timeout: 10_000,
98
+ encoding: 'utf8',
99
+ windowsHide: true,
100
+ maxBuffer: 16_384,
101
+ });
102
+ if (result.error || result.status !== 0) {
103
+ return 'key_acl_unverified';
104
+ }
105
+ if (result.stdout.trim() === 'usable') {
106
+ return 'key_path_usable';
107
+ }
108
+ return result.stdout.trim() === 'insecure' ? 'key_acl_insecure' : 'key_acl_unverified';
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyrokine/mcp-ssh",
3
- "version": "2.4.2",
3
+ "version": "3.0.0",
4
4
  "description": "A comprehensive SSH MCP Server for Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,11 +8,11 @@
8
8
  "mcp-ssh": "dist/index.js"
9
9
  },
10
10
  "scripts": {
11
- "build": "node node_modules/typescript7/bin/tsc",
11
+ "build": "npm run clean && node node_modules/typescript7/bin/tsc",
12
12
  "start": "node dist/index.js",
13
13
  "dev": "node node_modules/typescript7/bin/tsc && node dist/index.js",
14
14
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
15
- "prepublishOnly": "npm run build",
15
+ "prepack": "npm run build",
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",
@@ -33,7 +33,7 @@
33
33
  "url": "git+https://github.com/Pyrokine/claude-tools.git"
34
34
  },
35
35
  "dependencies": {
36
- "@modelcontextprotocol/sdk": "^1.30.0",
36
+ "@modelcontextprotocol/sdk": "^1.32.1",
37
37
  "@xterm/headless": "^6.0.0",
38
38
  "ssh2": "^1.17.0",
39
39
  "zod": "^4.4.3"