mcp-ssh-manager 3.8.5 → 3.8.6

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,86 @@ 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.6] - 2026-10-08
9
+
10
+ ### Security
11
+
12
+ Six advisories, five reported to us and one found while replacing our previous
13
+ tool with this one. **Upgrade.**
14
+
15
+ - **Command injection on the machine running mcp-ssh-manager, through the
16
+ default `on-error` hook** (GHSA-759m-wfpq-xmx3, high). The hook ran
17
+ `echo "… {error}" >> errors.log` through a shell, with the connection error
18
+ pasted inside double quotes. That text comes from the server: an SSH server
19
+ that disconnects with `$(…)` in its reason, before any key exchange, ran a
20
+ command on your machine. Hook values never become command text any more:
21
+ each `{placeholder}` becomes a reference to a shell variable holding the value
22
+ (`SSH_MANAGER_HOOK_SERVER`, …), and the default `on-error` hook is a `log`
23
+ action written without a shell, to `~/.ssh-manager/errors.log`.
24
+ - **`restricted` mode only checked how a line started** (GHSA-rfxw-26h6-7w42,
25
+ high, reported by @uozergit). The allow patterns were tested against the
26
+ whole line, so `^echo ` let `echo hi; id` through, and `^rm ` as a deny pattern
27
+ missed `echo x; rm -rf /data`. Every command in a list or pipeline must now
28
+ match, deny patterns apply to each, and command substitution and redirections
29
+ that write a file are refused. `readonly` also checks the commands inside
30
+ `$(…)` and backticks.
31
+ - **`cwd` reached the shell unquoted, past the security policy**
32
+ (GHSA-37fv-fcpc-j236, high, reported by @uozergit). `ssh_execute`,
33
+ `ssh_execute_group` and `ssh_execute_sudo` built `cd ${cwd} && …`; the
34
+ directory is now quoted, `~/` still expanding to the remote home.
35
+ - **`ssh_db_query` could write** (GHSA-9w6j-vg8f-hp8g, medium, reported by
36
+ @zaara2004; GHSA-q37w-vhpx-q5q9, high, reported by @davutselcuk). On MySQL,
37
+ `SELECT … INTO OUTFILE` wrote a file on the database server; on PostgreSQL,
38
+ `SELECT … INTO` created a table; on MongoDB, the collection and the query were
39
+ pasted into JavaScript, so `drop()` or `run()` ran on a tool documented as
40
+ read-only. SQL is now one `SELECT`, without `INTO` or the server-file
41
+ functions, run inside a read-only transaction — which also stops a stored
42
+ function that writes; a MySQL error no longer comes back as an empty result.
43
+ A MongoDB query must be a filter document (JSON or mongo shell syntax such as
44
+ `ObjectId("…")`), `$where`, `$function` and `$accumulator` are refused, and the
45
+ collection is passed as a string. Checked against MariaDB 11, PostgreSQL 16
46
+ and MongoDB 5.
47
+ - **Host keys were never compared** (GHSA-cwg3-pfmm-w8rm, high, reported by
48
+ Francesco Canovi (@TheDarkMist), Black Studio Solutions). The key a server presented was
49
+ accepted for known and unknown hosts alike. It is now compared with
50
+ `known_hosts` (hashed entries, `[host]:port`, wildcards and `@revoked`
51
+ included): an unknown host is trusted on first use and recorded, **a changed
52
+ key is refused** before any credential is sent.
53
+ - **`ssh_deploy` and `ssh_backup_schedule` still spliced values into commands**,
54
+ the class fixed in 3.8.5 (GHSA-qwwm-vrm9-4mw8) but missed here: the remote path
55
+ sat in double quotes, where `$(…)` runs; owner, permissions and the temporary
56
+ file name were bare; the scheduled script pasted the database and the paths.
57
+ And quoting the crontab line was not enough: cron runs whatever follows the
58
+ fifth field, so a schedule such as `* * * * * curl … | sh #` installed a job of
59
+ the caller's choosing. A schedule must now be five cron fields or an `@` macro.
60
+
61
+ Each fix carries a test that fails without it.
62
+
63
+ ### Behaviour changes
64
+
65
+ - **A changed host key is refused.** A server reinstalled since its key was
66
+ recorded stops connecting until the old entry is removed
67
+ (`ssh-keygen -R <host>`) — this is what an interception looks like, so it is
68
+ the one change that cannot be opt-in. `SSH_MANAGER_KNOWN_HOSTS` points at a
69
+ separate file.
70
+ - **A `restricted` allowlist is now checked per command.** A pipe into a
71
+ command you never allowed, a `;` followed by another command, a `$(…)`, a `>`
72
+ into a file: each is refused, and the refusal names the command. Add a pattern
73
+ for each command you do want.
74
+ - **Hook settings, aliases, the active profile, the log and the command
75
+ history live in `~/.ssh-manager/`** (or `SSH_MANAGER_HOME`), readable by you
76
+ alone, instead of inside the installed package, where every upgrade lost them
77
+ and the log was readable by any local user
78
+ ([#87](https://github.com/bvisible/mcp-ssh-manager/issues/87)). Nothing is
79
+ written on start; a log needs `~/.ssh-manager` to exist. An old file in the
80
+ package is still read until your next change writes the new one.
81
+ - **The package no longer ships a `.hooks-config.json`.** The one it carried
82
+ was a development copy that turned Frappe hooks on for every npm user: each
83
+ `ssh_deploy` ran `git status` and `npm test` in your working directory, and any
84
+ command containing `bench update` first ran a full `bench backup` on the
85
+ server. The hooks now come from your profile, as documented; the `frappe`
86
+ profile still has them.
87
+
8
88
  ## [3.8.5] - 2026-08-28
9
89
 
10
90
  ### 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**:
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.6",
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: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 && 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",
@@ -36,6 +37,7 @@
36
37
  "test:dbinjection": "node tests/test-database-injection.js",
37
38
  "test:backupinjection": "node tests/test-backup-monitor-injection.js",
38
39
  "test:dbrowcount": "node tests/test-database-row-count.js",
40
+ "test:cli-edit": "node tests/test-cli-edit-server.js",
39
41
  "test:all": "npm test && npm run typecheck && ./scripts/validate.sh",
40
42
  "validate": "./scripts/validate.sh",
41
43
  "typecheck": "tsc -p tsconfig.json",
@@ -93,7 +95,7 @@
93
95
  "homepage": "https://github.com/bvisible/mcp-ssh-manager#readme",
94
96
  "dependencies": {
95
97
  "@iarna/toml": "^2.2.5",
96
- "@modelcontextprotocol/sdk": "^1.30.0",
98
+ "@modelcontextprotocol/sdk": "^1.32.1",
97
99
  "dotenv": "^16.4.5",
98
100
  "ssh2": "^1.17.0",
99
101
  "zod": "^4.4.3"
@@ -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.6",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "mcp-ssh-manager",
14
- "version": "3.8.5",
14
+ "version": "3.8.6",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -442,6 +442,29 @@ export function buildCronScheduleCommand(schedule, backupCommand, cronComment) {
442
442
  // through shellQuote so a schedule or comment carrying quotes cannot break
443
443
  // out of the echo and run something else. backupCommand is built by the
444
444
  // builders above, which quote their own arguments.
445
- const cronLine = `${schedule} ${backupCommand} # ${cronComment}`;
445
+ //
446
+ // Quoting the echo was the 3.8.5 fix, and it was not enough: cron reads
447
+ // everything after the fifth field as the command to run, and a line break
448
+ // as the start of another job, so `* * * * * curl … | sh #` installed a job
449
+ // of the caller's choosing. The schedule must now be a schedule.
450
+ if (!isCronSchedule(schedule)) {
451
+ throw new Error('Schedule must be five cron fields (e.g. "0 2 * * *") or a macro such as @daily');
452
+ }
453
+ const comment = String(cronComment).replace(/[\r\n]+/g, ' ');
454
+ const cronLine = `${schedule.trim()} ${backupCommand} # ${comment}`;
446
455
  return `(crontab -l 2>/dev/null; echo ${shellQuote(cronLine)}) | crontab -`;
447
456
  }
457
+
458
+ /**
459
+ * Whether a string is a crontab schedule and nothing more: five time fields,
460
+ * or one of cron's @ macros.
461
+ * @param {any} schedule
462
+ * @returns {boolean}
463
+ */
464
+ export function isCronSchedule(schedule) {
465
+ if (typeof schedule !== 'string') return false;
466
+ const text = schedule.trim();
467
+ if (/^@(yearly|annually|monthly|weekly|daily|midnight|hourly|reboot)$/.test(text)) return true;
468
+ const fields = text.split(/[ \t]+/);
469
+ return fields.length === 5 && fields.every(field => /^[0-9A-Za-z*/,-]+$/.test(field));
470
+ }
@@ -3,15 +3,18 @@
3
3
  * Provides shortcuts for frequently used commands
4
4
  */
5
5
 
6
- import fs from 'fs';
7
6
  import path from 'path';
8
7
  import { fileURLToPath } from 'url';
9
8
  import { loadProfile } from './profile-loader.js';
9
+ import { readUserState, writeUserState } from './user-state.js';
10
10
 
11
11
  const __filename = fileURLToPath(import.meta.url);
12
12
  const __dirname = path.dirname(__filename);
13
13
 
14
- const ALIASES_FILE = path.join(__dirname, '..', '.command-aliases.json');
14
+ // Custom aliases live in the manager home; the package copy is read only as a
15
+ // fallback for a source checkout (see user-state.js, issue #87).
16
+ const ALIASES_NAME = 'command-aliases.json';
17
+ const LEGACY_ALIASES_FILE = path.join(__dirname, '..', '.command-aliases.json');
15
18
 
16
19
  // Get aliases from the active profile
17
20
  let profileAliases = {};
@@ -31,9 +34,9 @@ export function loadCommandAliases() {
31
34
  let aliases = { ...profileAliases };
32
35
 
33
36
  // Merge with custom aliases from file
34
- if (fs.existsSync(ALIASES_FILE)) {
35
- const data = fs.readFileSync(ALIASES_FILE, 'utf8');
36
- aliases = { ...aliases, ...JSON.parse(data) };
37
+ const state = readUserState(ALIASES_NAME, LEGACY_ALIASES_FILE);
38
+ if (state) {
39
+ aliases = { ...aliases, ...JSON.parse(state.text) };
37
40
  }
38
41
 
39
42
  return aliases;
@@ -56,7 +59,7 @@ function saveCommandAliases(aliases) {
56
59
  }
57
60
  }
58
61
 
59
- fs.writeFileSync(ALIASES_FILE, JSON.stringify(customAliases, null, 2));
62
+ writeUserState(ALIASES_NAME, JSON.stringify(customAliases, null, 2));
60
63
  return true;
61
64
  } catch (error) {
62
65
  console.error(`Error saving command aliases: ${error.message}`);
@@ -0,0 +1,12 @@
1
+ import os from 'os';
2
+ import path from 'path';
3
+
4
+ /**
5
+ * The directory that holds this user's settings and state: SSH_MANAGER_HOME,
6
+ * or ~/.ssh-manager. Read at call time so a test or a host that sets the
7
+ * variable after import still gets its own directory.
8
+ * @returns {string}
9
+ */
10
+ export function managerHome() {
11
+ return process.env.SSH_MANAGER_HOME || path.join(os.homedir(), '.ssh-manager');
12
+ }