mcp-ssh-manager 3.8.5 → 3.8.7

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/CHANGELOG.md CHANGED
@@ -5,6 +5,122 @@ All notable changes to MCP SSH Manager will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.8.7] - 2026-10-25
9
+
10
+ ### Security
11
+
12
+ Two advisories, both reported to us. **Upgrade.**
13
+
14
+ - **A partial server name or an alias escaped `readonly` and `restricted`
15
+ mode** (GHSA-mq9f-5385-rjf4, high, reported by @nikhilagrawalsf). The policy
16
+ looked a server up by its exact name, while the connection resolved aliases,
17
+ case, a unique part of a name and host matches. So `"p"` instead of `"prod"`,
18
+ an alias the agent had just created with `ssh_alias`, or the host itself
19
+ found no policy — unrestricted — and the command then ran on the protected
20
+ server. The policy now resolves the name exactly as the connection does; an
21
+ ambiguous name is refused by both. A session keeps the server's own name, not
22
+ what was typed to open it.
23
+ - **Remote command execution through `ssh_backup_restore`'s `backupId`**
24
+ (GHSA-2wjh-xm9c-7qf9, high, reported by @NYBaywatch). The metadata path built
25
+ from it went to the server inside `cat "…"`, where `$(…)` and backticks still
26
+ run — through a tool that was only meant to restore. `ssh_backup_create`'s
27
+ `mkdir -p "…"` had the same flaw with `backupDir`, the half of
28
+ GHSA-qwwm-vrm9-4mw8 the earlier fix missed. Both are quoted now, a backup ID
29
+ must be a plain file name (no separator, no `..`, no control character), and
30
+ a test fails if any remote command in `index.js` splices a value inside double
31
+ quotes again.
32
+ - Dependencies: `zod` 4.6.7, `body-parser` 2.4.0, `fast-uri` 3.1.9,
33
+ `ip-address` 10.7.5, for the advisories published since 3.8.6.
34
+ `npm audit` is clean.
35
+
36
+ ### Added
37
+
38
+ - **Per-server OpenSSH user certificates: `CERTPATH` / `cert_path`.** The
39
+ certificate is passed to `ssh2` as `publicKey` next to `privateKey`, read on
40
+ every connection (renewed short-lived certificates need no restart), and a
41
+ missing file fails the connection. Needs an `ssh2` release with certificate
42
+ support (mscdex/ssh2#1495); with `ssh2` 1.17.0 the option has no effect.
43
+
44
+ ## [3.8.6] - 2026-10-08
45
+
46
+ ### Security
47
+
48
+ Six advisories, five reported to us and one found while replacing our previous
49
+ tool with this one. **Upgrade.**
50
+
51
+ - **Command injection on the machine running mcp-ssh-manager, through the
52
+ default `on-error` hook** (GHSA-759m-wfpq-xmx3, high). The hook ran
53
+ `echo "… {error}" >> errors.log` through a shell, with the connection error
54
+ pasted inside double quotes. That text comes from the server: an SSH server
55
+ that disconnects with `$(…)` in its reason, before any key exchange, ran a
56
+ command on your machine. Hook values never become command text any more:
57
+ each `{placeholder}` becomes a reference to a shell variable holding the value
58
+ (`SSH_MANAGER_HOOK_SERVER`, …), and the default `on-error` hook is a `log`
59
+ action written without a shell, to `~/.ssh-manager/errors.log`.
60
+ - **`restricted` mode only checked how a line started** (GHSA-rfxw-26h6-7w42,
61
+ high, reported by @uozergit). The allow patterns were tested against the
62
+ whole line, so `^echo ` let `echo hi; id` through, and `^rm ` as a deny pattern
63
+ missed `echo x; rm -rf /data`. Every command in a list or pipeline must now
64
+ match, deny patterns apply to each, and command substitution and redirections
65
+ that write a file are refused. `readonly` also checks the commands inside
66
+ `$(…)` and backticks.
67
+ - **`cwd` reached the shell unquoted, past the security policy**
68
+ (GHSA-37fv-fcpc-j236, high, reported by @uozergit). `ssh_execute`,
69
+ `ssh_execute_group` and `ssh_execute_sudo` built `cd ${cwd} && …`; the
70
+ directory is now quoted, `~/` still expanding to the remote home.
71
+ - **`ssh_db_query` could write** (GHSA-9w6j-vg8f-hp8g, medium, reported by
72
+ @zaara2004; GHSA-q37w-vhpx-q5q9, high, reported by @davutselcuk). On MySQL,
73
+ `SELECT … INTO OUTFILE` wrote a file on the database server; on PostgreSQL,
74
+ `SELECT … INTO` created a table; on MongoDB, the collection and the query were
75
+ pasted into JavaScript, so `drop()` or `run()` ran on a tool documented as
76
+ read-only. SQL is now one `SELECT`, without `INTO` or the server-file
77
+ functions, run inside a read-only transaction — which also stops a stored
78
+ function that writes; a MySQL error no longer comes back as an empty result.
79
+ A MongoDB query must be a filter document (JSON or mongo shell syntax such as
80
+ `ObjectId("…")`), `$where`, `$function` and `$accumulator` are refused, and the
81
+ collection is passed as a string. Checked against MariaDB 11, PostgreSQL 16
82
+ and MongoDB 5.
83
+ - **Host keys were never compared** (GHSA-cwg3-pfmm-w8rm, high, reported by
84
+ Francesco Canovi (@TheDarkMist), Black Studio Solutions). The key a server presented was
85
+ accepted for known and unknown hosts alike. It is now compared with
86
+ `known_hosts` (hashed entries, `[host]:port`, wildcards and `@revoked`
87
+ included): an unknown host is trusted on first use and recorded, **a changed
88
+ key is refused** before any credential is sent.
89
+ - **`ssh_deploy` and `ssh_backup_schedule` still spliced values into commands**,
90
+ the class fixed in 3.8.5 (GHSA-qwwm-vrm9-4mw8) but missed here: the remote path
91
+ sat in double quotes, where `$(…)` runs; owner, permissions and the temporary
92
+ file name were bare; the scheduled script pasted the database and the paths.
93
+ And quoting the crontab line was not enough: cron runs whatever follows the
94
+ fifth field, so a schedule such as `* * * * * curl … | sh #` installed a job of
95
+ the caller's choosing. A schedule must now be five cron fields or an `@` macro.
96
+
97
+ Each fix carries a test that fails without it.
98
+
99
+ ### Behaviour changes
100
+
101
+ - **A changed host key is refused.** A server reinstalled since its key was
102
+ recorded stops connecting until the old entry is removed
103
+ (`ssh-keygen -R <host>`) — this is what an interception looks like, so it is
104
+ the one change that cannot be opt-in. `SSH_MANAGER_KNOWN_HOSTS` points at a
105
+ separate file.
106
+ - **A `restricted` allowlist is now checked per command.** A pipe into a
107
+ command you never allowed, a `;` followed by another command, a `$(…)`, a `>`
108
+ into a file: each is refused, and the refusal names the command. Add a pattern
109
+ for each command you do want.
110
+ - **Hook settings, aliases, the active profile, the log and the command
111
+ history live in `~/.ssh-manager/`** (or `SSH_MANAGER_HOME`), readable by you
112
+ alone, instead of inside the installed package, where every upgrade lost them
113
+ and the log was readable by any local user
114
+ ([#87](https://github.com/bvisible/mcp-ssh-manager/issues/87)). Nothing is
115
+ written on start; a log needs `~/.ssh-manager` to exist. An old file in the
116
+ package is still read until your next change writes the new one.
117
+ - **The package no longer ships a `.hooks-config.json`.** The one it carried
118
+ was a development copy that turned Frappe hooks on for every npm user: each
119
+ `ssh_deploy` ran `git status` and `npm test` in your working directory, and any
120
+ command containing `bench update` first ran a full `bench backup` on the
121
+ server. The hooks now come from your profile, as documented; the `frappe`
122
+ profile still has them.
123
+
8
124
  ## [3.8.5] - 2026-08-28
9
125
 
10
126
  ### Security
package/README.md CHANGED
@@ -6,7 +6,7 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
8
8
  [![npm downloads](https://img.shields.io/npm/dt/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
9
- [![Version](https://img.shields.io/badge/Version-3.8.5-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.8.5)
9
+ [![Version](https://img.shields.io/badge/Version-3.8.6-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.8.6)
10
10
  [![Claude Code](https://img.shields.io/badge/Claude_Code-Compatible-5A67D8?style=for-the-badge&logo=anthropic)](https://claude.ai/code)
11
11
  [![OpenAI Codex](https://img.shields.io/badge/OpenAI_Codex-Compatible-00A67E?style=for-the-badge&logo=openai)](https://openai.com/codex)
12
12
  [![MCP](https://img.shields.io/badge/MCP-Server-orange?style=for-the-badge)](https://modelcontextprotocol.io)
@@ -23,19 +23,20 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
23
23
 
24
24
  ---
25
25
 
26
- ## 🎉 What's New in v3.8.5
26
+ ## 🎉 What's New in v3.8.6
27
27
 
28
- **🔒 Security release — three command-injection advisories fixed, one of which defeated `readonly` mode** (Released: August 28, 2026)
28
+ **🔒 Security release — six advisories fixed. Upgrade.** (Released: October 8, 2026)
29
29
 
30
- **Upgrade if you use `ssh_backup_*`, `ssh_db_dump`, `ssh_service_status` or `ssh_tail` — and especially if you rely on the `readonly` / `restricted` security modes.**
30
+ - **🔴 Command injection on your own machine through the default `on-error` hook** (GHSA-759m-wfpq-xmx3) — the connection error, whose text a server chooses, was pasted into a shell command. Any SSH server you connected to could run a command on the machine running mcp-ssh-manager. Hook values now reach commands as shell variables, never as command text, and the default hook writes its log without a shell.
31
+ - **🔴 `restricted` mode only checked how a line started** (GHSA-rfxw-26h6-7w42) — `^echo ` let `echo hi; id` through. Every command in a list or pipeline must now match your allowlist; command substitution and writes to files are refused.
32
+ - **🔴 `cwd` reached the shell unquoted** (GHSA-37fv-fcpc-j236), past the security policy.
33
+ - **🔴 `ssh_db_query` could write** (GHSA-9w6j-vg8f-hp8g, GHSA-q37w-vhpx-q5q9) — `SELECT … INTO OUTFILE`, `SELECT … INTO` a new table, and JavaScript in MongoDB queries. Queries now run in a read-only transaction, and a MongoDB query must be a filter document.
34
+ - **🟠 Host keys were never compared** (GHSA-cwg3-pfmm-w8rm) — **a changed host key is now refused**, as OpenSSH does. A server reinstalled since its key was recorded needs `ssh-keygen -R <host>` once.
35
+ - `ssh_deploy` and `ssh_backup_schedule` quote every value, and a cron schedule must be a schedule.
31
36
 
32
- - **🔴 RCE bypassing `readonly` / `restricted`** (GHSA-m793-whw6-f537) — `ssh_service_status` and `ssh_tail` are read-only, so they stay enabled on servers you locked down, and neither quoted its arguments nor consulted the policy layer. A service name like `nginx; id > /tmp/pwned` executed. This defeated the exact control those modes exist to provide.
33
- - **🔴 RCE through `ssh_db_dump`** (GHSA-796j-h5q5-jx6p) — the `stat` command run after the dump interpolated the output path raw. The v3.6.7 patch had stopped one line short.
34
- - **🟠 RCE through every `ssh_backup_*` tool** (GHSA-qwwm-vrm9-4mw8) — `backup-manager.js` had **zero** shell escaping across its 9 builders, while `database-manager.js` had 95. The v3.6.7 fix was never extended to it.
37
+ Hook settings, aliases, the active profile and the logs now live in `~/.ssh-manager/`, readable by you alone, instead of inside the installed package, where every upgrade lost them.
35
38
 
36
- The quoting helper now lives in one module (`src/shell-quote.js`) so "did this builder quote its inputs?" has a single answer, and a new test drives **340 builder × argument × payload combinations** through a real shell to prove none of them execute.
37
-
38
- [Read full changelog →](CHANGELOG.md#385---2026-08-28)
39
+ [Read full changelog →](CHANGELOG.md#386---2026-10-08) · Previous: [v3.8.5](CHANGELOG.md#385---2026-08-28), three command-injection advisories.
39
40
 
40
41
  ---
41
42
 
@@ -717,7 +718,7 @@ SSH Manager uses profiles to configure aliases and hooks for different project t
717
718
 
718
719
  1. **Set active profile**:
719
720
  - Environment variable: `export SSH_MANAGER_PROFILE=frappe`
720
- - Configuration file: Create `.ssh-manager-profile` with profile name
721
+ - Configuration file: `~/.ssh-manager/profile` holds the profile name (switching from your assistant writes it)
721
722
  - Default: Uses `default` profile if not specified
722
723
 
723
724
  2. **Available profiles**:
@@ -737,6 +738,7 @@ SSH_SERVER_[NAME]_HOST=hostname_or_ip
737
738
  SSH_SERVER_[NAME]_USER=username
738
739
  SSH_SERVER_[NAME]_PASSWORD=password # For password auth
739
740
  SSH_SERVER_[NAME]_KEYPATH=~/.ssh/key # For SSH key auth
741
+ SSH_SERVER_[NAME]_CERTPATH=~/.ssh/key-cert.pub # Optional: OpenSSH user certificate for KEYPATH (needs ssh2 with certificate support; see SSH Certificates)
740
742
  SSH_SERVER_[NAME]_PASSPHRASE=key_passphrase # Optional, for passphrase-protected keys
741
743
  SSH_SERVER_[NAME]_PORT=22 # Optional, defaults to 22
742
744
  SSH_SERVER_[NAME]_DEFAULT_DIR=/path/to/dir # Optional, default working directory
@@ -895,6 +897,29 @@ forward_agent = true
895
897
 
896
898
  > ⚠️ **Security warning:** agent forwarding lets any process that can read the forwarded agent socket on the remote host — including anyone with **root** there — use your loaded keys to impersonate you against other hosts *for the life of the connection*. Only enable it for servers you trust, mirroring the same caution `ssh_config(5)` advises for `ForwardAgent`.
897
899
 
900
+ ### 📜 SSH User Certificates
901
+
902
+ If your servers trust an OpenSSH certificate authority (`TrustedUserCAKeys` in `sshd_config`), point `CERTPATH` at the certificate signed for `KEYPATH` (usually `<key>-cert.pub`). The certificate is sent as the identity and the private key signs, like `ssh -i key -o CertificateFile=key-cert.pub`.
903
+
904
+ `.env` format:
905
+ ```env
906
+ SSH_SERVER_MYSERVER_KEYPATH=~/.ssh/id_ed25519
907
+ SSH_SERVER_MYSERVER_CERTPATH=~/.ssh/id_ed25519-cert.pub
908
+ ```
909
+
910
+ TOML format:
911
+ ```toml
912
+ [ssh_servers.myserver]
913
+ key_path = "~/.ssh/id_ed25519"
914
+ cert_path = "~/.ssh/id_ed25519-cert.pub"
915
+ ```
916
+
917
+ - The certificate file is read on every connection, so a short-lived certificate renewed on disk is used on the next connection without restarting the server.
918
+ - If `CERTPATH` is set and the file is missing, the connection fails instead of falling back to the bare key.
919
+ - `CERTPATH` is ignored without `KEYPATH`. Without `CERTPATH` nothing changes.
920
+ - **Requires an `ssh2` release with certificate support** ([mscdex/ssh2#1495](https://github.com/mscdex/ssh2/pull/1495)). With `ssh2` 1.17.0 the option is ignored and the plain key is offered.
921
+ - `ssh_sync` uses the system `rsync`/`ssh` and does not use `CERTPATH` yet; OpenSSH picks up `<key>-cert.pub` next to the key on its own.
922
+
898
923
  ## 📚 Advanced Usage
899
924
 
900
925
  ### ProxyJump / Bastion Host
package/cli/lib/menu.sh CHANGED
@@ -273,7 +273,7 @@ wizard_edit_server() {
273
273
  return 1
274
274
  fi
275
275
 
276
- local server_name="$SELECTED_SERVER"
276
+ local server_name="$selected_server"
277
277
 
278
278
  # Load existing configuration
279
279
  local current_host=$(get_server_config "$server_name" "HOST")
@@ -586,4 +586,4 @@ wizard_create_tunnel() {
586
586
 
587
587
  echo
588
588
  read -p "Press Enter to continue..."
589
- }
589
+ }
@@ -19,7 +19,8 @@ export SSH_MANAGER_PROFILE=frappe
19
19
  ```
20
20
 
21
21
  2. **Configuration File**:
22
- Create `.ssh-manager-profile` in project root:
22
+ Write the name into `profile` in your settings directory (`~/.ssh-manager/`, or
23
+ `SSH_MANAGER_HOME`), which is what switching profiles from Claude Code does:
23
24
  ```
24
25
  frappe
25
26
  ```
@@ -105,7 +106,7 @@ Hooks provide automated actions that run before, after, or on error during SSH o
105
106
  Each profile defines relevant hooks:
106
107
 
107
108
  #### Default Profile
108
- - **on-error**: Logs errors to file
109
+ - **on-error**: Logs errors to `errors.log` in your settings directory (see below)
109
110
 
110
111
  #### Frappe Profile
111
112
  - **pre-bench-update**: Creates backup, checks disk space
@@ -145,25 +146,53 @@ Each profile defines relevant hooks:
145
146
 
146
147
  ## Configuration Files
147
148
 
148
- ### Profile Selection
149
- - Location: `.ssh-manager-profile`
150
- - Contains the active profile name
151
-
152
- ### Custom Command Aliases
153
- - Location: `.command-aliases.json`
154
- - Contains custom aliases (overrides profile aliases)
155
-
156
- ### Custom Hooks Configuration
157
- - Location: `.hooks-config.json`
158
- - Contains custom hook definitions (overrides profile hooks)
159
-
160
- ### Profile Definitions
161
- - Location: `profiles/` directory
162
- - JSON files defining profile-specific configurations
163
-
164
- ### Hook Scripts
165
- - Location: `hooks/` directory
166
- - Custom scripts can be placed here
149
+ Everything you change at run time lives in your settings directory, beside your
150
+ `.env`: `~/.ssh-manager/`, or the directory named by `SSH_MANAGER_HOME`. Files
151
+ are created only when you change something, readable by you alone.
152
+
153
+ | What | File |
154
+ |---|---|
155
+ | Active profile | `profile` |
156
+ | Custom command aliases (override the profile's) | `command-aliases.json` |
157
+ | Custom hook definitions (override the profile's) | `hooks.json` |
158
+ | Server aliases | `server-aliases.json` |
159
+ | Logs written by `log` hook actions | `errors.log`, `deployments.log`, `ssh-key-changes.log` |
160
+
161
+ Up to 3.8.5 these were written inside the installed package (`.ssh-manager-profile`,
162
+ `.command-aliases.json`, `.hooks-config.json`, `.server-aliases.json`), so an
163
+ upgrade lost them, and the default `errors.log` landed in whatever directory the
164
+ server was started from. An old file there is still read until your next change
165
+ writes the new one.
166
+
167
+ Profile definitions stay in the package's `profiles/` directory.
168
+
169
+ ## Writing Hook Actions
170
+
171
+ A hook action is one of:
172
+
173
+ - **`log`** — appends a timestamped line to a file, with no shell involved:
174
+ ```json
175
+ { "type": "log", "name": "log-error", "file": "errors.log", "message": "Error on {server}: {error}" }
176
+ ```
177
+ A relative `file` lands in your settings directory, never in the working directory.
178
+ - **`command`** — a shell command run on this machine.
179
+ - **`remoteCommand`** — a shell command run on the server, for hooks fired with an
180
+ open connection (`pre-bench-update`, `post-bench-update`).
181
+
182
+ ### How `{placeholders}` reach a command
183
+
184
+ A placeholder is **never pasted into the command text**. It becomes a reference to
185
+ a shell variable that holds the value — `{server}` becomes `"${SSH_MANAGER_HOOK_SERVER}"`,
186
+ `{backupId}` becomes `"${SSH_MANAGER_HOOK_BACKUP_ID}"` — quoted to fit where it sits.
187
+ A shell does not run what a variable expands to, so a value such as a connection
188
+ error chosen by a hostile server cannot become a command. Up to 3.8.5 values were
189
+ pasted in, and the default `on-error` hook ran such an error inside double quotes
190
+ ([GHSA-759m-wfpq-xmx3](https://github.com/bvisible/mcp-ssh-manager/security/advisories/GHSA-759m-wfpq-xmx3)).
191
+
192
+ You can also read the variables directly (`$SSH_MANAGER_HOOK_SERVER`). Do not hand
193
+ them to anything that evaluates text again — `eval`, `sh -c`, arithmetic — where a
194
+ value would become code once more. On Windows, local hooks run under `cmd.exe`,
195
+ where values are inserted with every character cmd treats specially removed.
167
196
 
168
197
  ## Environment Variables for Hooks
169
198
 
@@ -272,14 +301,14 @@ Example:
272
301
  ### Hooks not executing
273
302
  - Check if hook is enabled: `"Show SSH hooks status"`
274
303
  - Verify required environment variables are set
275
- - Check `.hooks-config.json` for proper configuration
304
+ - Check `~/.ssh-manager/hooks.json` for proper configuration
276
305
 
277
306
  ### Command aliases not working
278
307
  - List aliases to verify: `"List all command aliases"`
279
- - Check `.command-aliases.json` for syntax errors
308
+ - Check `~/.ssh-manager/command-aliases.json` for syntax errors
280
309
  - Ensure the base command is valid
281
310
 
282
311
  ### Deployment failures
283
- - Check `deployments.log` for history
284
- - Review `errors.log` for error details
312
+ - Check `~/.ssh-manager/deployments.log` for history
313
+ - Review `~/.ssh-manager/errors.log` for error details
285
314
  - Verify disk space and permissions on target server
@@ -24,7 +24,27 @@ attacks, layered between the MCP client and the SSH session.
24
24
  |---|---|
25
25
  | `unrestricted` (default) | No filter. Identical to pre-v3.5.0 behavior. Zero overhead — `evaluatePolicy()` early-returns. |
26
26
  | `readonly` | Blocks mutating tools at the tool level (`ssh_upload`, `ssh_deploy`, `ssh_sync`, `ssh_execute_sudo`, `ssh_backup_create/restore/schedule`, `ssh_db_import/dump`, `ssh_key_manage` write actions, `ssh_alert_setup` set, `ssh_process_manager kill`). For `ssh_execute` / `ssh_execute_sudo` / `ssh_execute_group` / `ssh_session_send`, applies a built-in denylist (rm, mv, dd, mkfs, chmod, chown, sudo, systemctl restart/stop, docker rm/stop, pipe-to-sh, redirect outside `/tmp`, etc.). |
27
- | `restricted` | All readonly blocks plus: every command must match at least one `ALLOW_PATTERNS` regex AND no `DENY_PATTERNS` regex. **DENY wins over ALLOW**. With no `ALLOW_PATTERNS`, every command is refused (fail-closed). |
27
+ | `restricted` | All readonly blocks plus: **every command on the line** must match at least one `ALLOW_PATTERNS` regex, and neither the line nor any command in it may match a `DENY_PATTERNS` regex. **DENY wins over ALLOW**. Command substitution and redirections that write a file are refused. With no `ALLOW_PATTERNS`, every command is refused (fail-closed). |
28
+
29
+ ### How a command line is checked in `restricted` mode
30
+
31
+ The line is split into the commands it would run — at `;`, `&&`, `||`, `|`, `&`
32
+ and line breaks, outside quotes — and **each one** must match an allow pattern.
33
+ `^docker ps` therefore allows `docker ps -a`, but not `docker ps; id`, and
34
+ `docker ps | grep web` only if `grep` is allowed too. Up to 3.8.5 the patterns
35
+ were tested against the whole line, so an allowed start carried anything
36
+ appended to it ([GHSA-rfxw-26h6-7w42](https://github.com/bvisible/mcp-ssh-manager/security/advisories/GHSA-rfxw-26h6-7w42)).
37
+
38
+ Also refused, because they run or change things the patterns never see:
39
+
40
+ - command substitution: `$(…)`, backticks, `<(…)`, `>(…)`, even inside double quotes;
41
+ - redirections that write a file: `>`, `>>`, `>|`, `&>`, `<>` — except to
42
+ `/dev/null`, `/dev/stdout`, `/dev/stderr` and descriptor copies such as `2>&1`;
43
+ - a line that cannot be read with confidence (an unterminated quote, for example).
44
+
45
+ Comments are not recognised: `ls # a; b` is checked as `ls # a` and ` b`, which
46
+ refuses it rather than missing a command. `readonly` mode also checks the commands
47
+ inside `$(…)` and backticks against its built-in list.
28
48
 
29
49
  ## Configuration
30
50
 
@@ -151,7 +171,8 @@ SSH_SERVER_CLIENT_PROD_AUDIT_LOG=~/.ssh-manager/audit/client-prod.jsonl
151
171
  **Not gated** (pure reads or local-only state — no remote effect to block):
152
172
  `ssh_list_servers`, `ssh_download`, `ssh_tail`, `ssh_monitor`, `ssh_history`,
153
173
  `ssh_health_check`, `ssh_service_status`, `ssh_db_list`, `ssh_db_query`
154
- (already SELECT-only), `ssh_backup_list`, `ssh_session_start`,
174
+ (one SELECT run in a read-only transaction; for MongoDB a filter document,
175
+ never code), `ssh_backup_list`, `ssh_session_start`,
155
176
  `ssh_session_list`, `ssh_session_close`, `ssh_connection_status`,
156
177
  `ssh_tunnel_*`, `ssh_group_manage`, `ssh_command_alias`, `ssh_alias`,
157
178
  `ssh_hooks`, `ssh_profile`.
@@ -164,7 +185,9 @@ SSH_SERVER_CLIENT_PROD_AUDIT_LOG=~/.ssh-manager/audit/client-prod.jsonl
164
185
  - **Regex-based filtering can be bypassed** with creative command crafting
165
186
  (encoded payloads, indirection via shell variables, etc.). Treat `readonly`
166
187
  as protection against accidents and prompt injection of the common form,
167
- not as an unbreakable shell escape.
188
+ not as an unbreakable shell escape. `restricted` is the stronger of the two:
189
+ every command must be one you allowed, so keep its patterns narrow — an
190
+ allowed interpreter (`^python`, `^bash`, `^sh`) allows everything.
168
191
  - **Aliases are expanded before policy evaluation** — you can't bypass a DENY
169
192
  by hiding `rm` behind an alias defined via `ssh_command_alias`.
170
193
  - **No transport-level / per-client policies.** All clients see the same
@@ -187,3 +210,10 @@ A v3.4.x `.env` or TOML loads identically under v3.5.0:
187
210
  so the client never sees a new prompt.
188
211
 
189
212
  See `CHANGELOG.md` v3.5.0 for the full diff.
213
+
214
+ **One deliberate exception, in 3.8.6 and 4.0:** a `restricted` server now checks
215
+ every command on a line, so an existing allowlist refuses lines it used to let
216
+ through — a pipe into a command you never allowed, a `;` followed by another
217
+ command, a `$(…)`, a `>` into a file. That was the hole. Add a pattern for each
218
+ command you do want (`^grep `, `^head `), and the refusal names the command that
219
+ did not match. Servers without `MODE`, and `readonly` ones, are unaffected.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "3.8.5",
3
+ "version": "3.8.7",
4
4
  "mcpName": "io.github.bvisible/mcp-ssh-manager",
5
5
  "description": "MCP SSH Manager: Model Context Protocol server for SSH remote server management. Control SSH connections from Claude Code and OpenAI Codex - execute commands, transfer files, database operations, backups, health monitoring, and DevOps automation. NEW: Tool activation system reduces context usage by 92%",
6
6
  "main": "src/index.js",
@@ -14,13 +14,14 @@
14
14
  "setup": "npm install && pip install -r tools/requirements.txt",
15
15
  "configure": "python tools/server-manager.py",
16
16
  "test-connection": "python tools/test-connection.py",
17
- "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:backupinjection && npm run test:dbrowcount",
17
+ "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:hostkeys && npm run test:tools && npm run test:policy && npm run test:policynames && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:certpath && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:backupinjection && npm run test:dbrowcount && npm run test:cli-edit",
18
18
  "test:lockfile": "node tests/test-lockfile.js",
19
19
  "test:sudostdin": "node tests/test-sudo-stdin.js",
20
20
  "test:redaction": "node tests/test-logger-redaction.js",
21
21
  "test:profiles": "node tests/test-profiles.js",
22
22
  "test:aliases": "node tests/test-command-aliases.js",
23
23
  "test:hooks": "node tests/test-hooks.js",
24
+ "test:hostkeys": "node tests/test-host-key-verification.js",
24
25
  "test:tools": "node tests/test-tool-registry.js",
25
26
  "test:policy": "node tests/test-policy.js",
26
27
  "test:ping": "node tests/test-ssh-ping.js",
@@ -28,6 +29,7 @@
28
29
  "test:fieldnames": "node tests/test-config-field-names.js",
29
30
  "test:groups": "node tests/test-server-groups.js",
30
31
  "test:agentforward": "node tests/test-agent-forward.js",
32
+ "test:certpath": "node tests/test-cert-path.js",
31
33
  "test:lifecycle": "node tests/test-lifecycle.js",
32
34
  "test:tunnel": "node tests/test-tunnel-listen.js",
33
35
  "test:sync": "node tests/test-sync-stats.js",
@@ -36,11 +38,13 @@
36
38
  "test:dbinjection": "node tests/test-database-injection.js",
37
39
  "test:backupinjection": "node tests/test-backup-monitor-injection.js",
38
40
  "test:dbrowcount": "node tests/test-database-row-count.js",
41
+ "test:cli-edit": "node tests/test-cli-edit-server.js",
39
42
  "test:all": "npm test && npm run typecheck && ./scripts/validate.sh",
40
43
  "validate": "./scripts/validate.sh",
41
44
  "typecheck": "tsc -p tsconfig.json",
42
45
  "lint": "eslint src/*.js",
43
- "format": "prettier --write 'src/**/*.js' 'tests/**/*.js'"
46
+ "format": "prettier --write 'src/**/*.js' 'tests/**/*.js'",
47
+ "test:policynames": "node tests/test-policy-name-resolution.js"
44
48
  },
45
49
  "keywords": [
46
50
  "mcp",
@@ -93,10 +97,10 @@
93
97
  "homepage": "https://github.com/bvisible/mcp-ssh-manager#readme",
94
98
  "dependencies": {
95
99
  "@iarna/toml": "^2.2.5",
96
- "@modelcontextprotocol/sdk": "^1.30.0",
100
+ "@modelcontextprotocol/sdk": "^1.32.1",
97
101
  "dotenv": "^16.4.5",
98
102
  "ssh2": "^1.17.0",
99
- "zod": "^4.4.3"
103
+ "zod": "^4.6.7"
100
104
  },
101
105
  "devDependencies": {
102
106
  "eslint": "^8.56.0",
@@ -31,9 +31,10 @@
31
31
  "description": "Run after successful deployment",
32
32
  "actions": [
33
33
  {
34
- "type": "notification",
34
+ "type": "log",
35
35
  "name": "log-deployment",
36
- "command": "echo \"[$(date)] Deployment completed to {server}\" >> deployments.log"
36
+ "file": "deployments.log",
37
+ "message": "Deployment completed to {server}"
37
38
  }
38
39
  ]
39
40
  },
@@ -42,9 +43,10 @@
42
43
  "description": "Run when an error occurs",
43
44
  "actions": [
44
45
  {
45
- "type": "notification",
46
+ "type": "log",
46
47
  "name": "log-error",
47
- "command": "echo \"[$(date)] Error on {server}: {error}\" >> errors.log"
48
+ "file": "errors.log",
49
+ "message": "Error on {server}: {error}"
48
50
  }
49
51
  ]
50
52
  }
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/bvisible/mcp-ssh-manager",
7
7
  "source": "github"
8
8
  },
9
- "version": "3.8.5",
9
+ "version": "3.8.7",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "mcp-ssh-manager",
14
- "version": "3.8.5",
14
+ "version": "3.8.7",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: ssh-manager
3
+ description: |
4
+ How to use the MCP SSH Manager core tools (ssh_list_servers, ssh_execute, ssh_upload,
5
+ ssh_download, ssh_sync) without breaking a server: server names, the remote shell, time
6
+ limits and long commands, file transfer pitfalls, security modes, host keys. Use it whenever
7
+ a task runs a command or moves a file on a remote machine through these tools.
8
+ ---
9
+
10
+ # Using the SSH Manager tools
11
+
12
+ This skill covers the five **core** tools, the ones exposed in the default `minimal` mode. If
13
+ more groups are enabled (`ssh-manager tools list`), prefer the specific tool over a raw command.
14
+
15
+ | Tool | What it does | Changes the server? |
16
+ |---|---|---|
17
+ | `ssh_list_servers` | Lists configured servers: name, host, user, port, auth type, default directory, group. Never returns secrets. | no |
18
+ | `ssh_execute` | Runs one command line, returns `stdout`, `stderr`, `code`. | depends on the command |
19
+ | `ssh_upload` | Copies ONE local file over SFTP, overwriting the target. No backup, no sudo. | yes |
20
+ | `ssh_download` | Copies ONE remote file to a local path (overwrites the local file). | no |
21
+ | `ssh_sync` | rsync over SSH. One side `local:`, the other `remote:`. `dryRun` previews, `delete` removes extras at the destination. | yes |
22
+
23
+ ## Before the first command
24
+
25
+ - Call `ssh_list_servers` once and use the exact names. A name is lowercase and every character
26
+ that is not a letter or a digit became `_` (`my-site.ch` → `my_site_ch`). Several names can
27
+ share one host with different users: take the user with the rights you need and no more.
28
+ - `ssh_execute` runs `cd -- '<cwd, or the server's default directory>' && <your command>`.
29
+ Pass `cwd` when the default is wrong. A missing directory fails the whole call.
30
+ - A server can be in `readonly` mode (destructive commands and uploads refused) or `restricted`
31
+ mode (only commands matching its patterns). A refusal is the configuration working: do not
32
+ look for a way around it, ask whoever owns the server.
33
+
34
+ ## Writing the command
35
+
36
+ - Assume the remote shell is `sh`/`dash`, not bash: no `<(…)`, no `[[ … ]]`, no arrays, no
37
+ `{a,b}`, no `$'…'`. A syntax error aborts the whole line **before any part of it ran**. Pipe
38
+ instead, or wrap in `bash -c '…'`.
39
+ - Heredocs work (`<<'EOF'`). Quote the delimiter so nothing is expanded by the remote shell.
40
+ - Chain with `&&` when step two must not run after a failure.
41
+ - `pgrep -f` and `pkill -f` match every command line, including the shell that carries your
42
+ command. Bracket one letter (`pgrep -f '[n]ginx -g'`) and kill in one call, relaunch in the next.
43
+ - Never put a password or token in the command line: it ends up in the remote process list and in
44
+ logs. Use a file with mode 600 or an environment variable set on the remote side.
45
+
46
+ ## Time limits and long commands
47
+
48
+ - Default timeout 120 s, maximum 300 s (`timeout`, in ms). In practice a call can be cut after
49
+ about three minutes. A command killed halfway leaves its work half done.
50
+ - Anything long or that restarts a service (builds, migrations, big copies, restarts): start it
51
+ detached and poll with short calls.
52
+ `setsid nohup <command> > ~/job.log 2>&1 &` then `tail -n 20 ~/job.log`.
53
+ Never run a service restart straight inside `ssh_execute`: if the call is cut, the restart stops
54
+ halfway and workers stay stopped.
55
+ - `ssh_sync` has its own timeout, 30 s by default: raise it for a big tree.
56
+
57
+ ## Moving files
58
+
59
+ - `ssh_upload` replaces the target completely. On a directory other people edit (a shared git tree),
60
+ never upload a whole file over an existing one: you silently revert what changed in it since
61
+ your copy. Apply a targeted edit on the remote, or upload to your own directory.
62
+ - For trees, run `ssh_sync` with `dryRun: true` first and read the list. Never `delete: true`
63
+ without having read it.
64
+ - To read a big file (a log, a dump), `ssh_download` it instead of `cat` inside `ssh_execute`.
65
+
66
+ ## Host keys and secrets
67
+
68
+ - Hosts are checked against `known_hosts`: a changed key is refused. A rebuilt server legitimately
69
+ changes its key, but never accept it blindly: compare the new key seen from two machines
70
+ (`ssh-keyscan` from yours and from another trusted host), then replace the old line.
71
+ - Prefer key authentication. Password servers need `sshpass` locally for `ssh_sync`.
72
+ - The configuration file (`~/.ssh-manager/.env`) holds passwords and key paths: never print it
73
+ and never paste it in a message.
74
+
75
+ ## Good habits
76
+
77
+ - Look before you change (`ls -la`, `git status`, `systemctl status`) and use read-only calls to find
78
+ out what is wrong before restarting anything.
79
+ - Do not retry a destructive command that failed until you know why it failed.
80
+ - When you report back, name the servers you touched and the commands that changed something.