ssh-mcp 2.0.2 → 2.0.4
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/build/policy/classifier.js +19 -1
- package/build/ssh/connection.js +19 -6
- package/package.json +1 -1
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anything through which the shell can start a second command.
|
|
3
|
+
*
|
|
4
|
+
* This gate decides whether an allowlisted binary counts as read-only, and the
|
|
5
|
+
* allowlist only vouches for the binary — never for what a shell might run
|
|
6
|
+
* beside it. It used to test /[>;|]/, which let `ls $(touch /tmp/x)` through as
|
|
7
|
+
* read-only: `ls` is allowlisted, no listed metacharacter appears, and the
|
|
8
|
+
* remote shell expands the substitution and runs the inner command anyway
|
|
9
|
+
* (GHSA-r8hm-vpm8-cfh6).
|
|
10
|
+
*
|
|
11
|
+
* Listing every dangerous construct is a losing game — `$()`, backticks,
|
|
12
|
+
* `<(...)`, `${x:=...}`, `&&`, a bare newline — so this refuses every character
|
|
13
|
+
* with syntactic meaning to the shell instead, and `$` wholesale rather than
|
|
14
|
+
* just `$(`. The cost is that `echo $HOME` is no longer classified read-only.
|
|
15
|
+
* That is the right trade for the tool whose entire promise is that it cannot
|
|
16
|
+
* write: run-command still accepts it under policy.
|
|
17
|
+
*/
|
|
18
|
+
const SHELL_CONTROL_CHARS = /[;&|<>`$(){}\n\r]/;
|
|
1
19
|
const READ_ONLY_ALLOWLIST = new Set([
|
|
2
20
|
'ls', 'cat', 'grep', 'find', 'stat', 'df', 'du', 'head', 'tail', 'wc',
|
|
3
21
|
'ps', 'uname', 'uptime', 'hostname', 'id', 'who', 'whoami', 'date',
|
|
@@ -98,7 +116,7 @@ export function classifyCommand(command) {
|
|
|
98
116
|
}
|
|
99
117
|
const twoWordPrefix = fullCommand.split(/\s+/).slice(0, 2).join(' ');
|
|
100
118
|
if (READ_ONLY_ALLOWLIST.has(binary) || READ_ONLY_ALLOWLIST.has(twoWordPrefix)) {
|
|
101
|
-
if (
|
|
119
|
+
if (SHELL_CONTROL_CHARS.test(trimmed)) {
|
|
102
120
|
return { binary, fullCommand, class: 'safe' };
|
|
103
121
|
}
|
|
104
122
|
return { binary, fullCommand, class: 'read-only' };
|
package/build/ssh/connection.js
CHANGED
|
@@ -28,12 +28,25 @@ export class SSHConnection {
|
|
|
28
28
|
this.sessions = new SessionManager({
|
|
29
29
|
// Live read: the profile object can be replaced after construction.
|
|
30
30
|
profile: () => this.profile,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
// ensureConnected inside the callback, not just before the retry: these
|
|
32
|
+
// run under openWithRetry, and Dropbear drops the whole connection under
|
|
33
|
+
// channel churn rather than merely refusing the channel. openSession does
|
|
34
|
+
// check the link first, but the link can die between that check and the
|
|
35
|
+
// channel opening — and then every retry reached getClient() on a dead
|
|
36
|
+
// client and threw the same "SSH connection not established", so the retry
|
|
37
|
+
// re-ran a corpse three times. SftpClient already did it this way.
|
|
38
|
+
openShell: async () => {
|
|
39
|
+
await this.ensureConnected();
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
this.getClient().shell({ term: 'xterm-256color', cols: 200, rows: 50 }, (err, stream) => (err ? reject(err) : resolve(stream)));
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
openExec: async (command) => {
|
|
45
|
+
await this.ensureConnected();
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
this.getClient().exec(this.applyWorkdir(command), (err, stream) => (err ? reject(err) : resolve(stream)));
|
|
48
|
+
});
|
|
49
|
+
},
|
|
37
50
|
onChannelOpened: () => { this.activeChannels++; },
|
|
38
51
|
onChannelClosed: () => { this.activeChannels--; },
|
|
39
52
|
});
|
package/package.json
CHANGED