mcp-ssh-manager 4.3.3 → 4.3.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/CHANGELOG.md CHANGED
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.3.4] - 2026-11-23
11
+
12
+ **A security release: upgrade.** `ssh_download` wrote any local path it was given,
13
+ including for servers in `readonly` or `restricted` mode
14
+ ([GHSA-2v9g-gm8g-mxgj](https://github.com/bvisible/mcp-ssh-manager/security/advisories/GHSA-2v9g-gm8g-mxgj),
15
+ high, found by the maintainer). Every release from 3.0.0 is affected. **One thing
16
+ behaves differently on purpose:** a download from a `readonly` or `restricted`
17
+ server is now refused outside `~/.ssh-manager/transfers`; if you download to a
18
+ folder of your own, set `TRANSFER_ROOT` for that server (see below). Nothing else
19
+ changes (the release pipeline upgrades 3.8.5, 3.8.6, 3.8.7, every 4.0.x, 4.1.0,
20
+ 4.2.0, 4.3.0, 4.3.1, 4.3.2 and 4.3.3 from the registry to this version and back).
21
+
22
+ The Windows installer is still **not Authenticode-signed**, for the same reason
23
+ as 4.0.0: Windows shows *"Windows protected your PC"*, *More info → Run anyway*,
24
+ and `ssh-manager app` checks the installer against the SHA-256 in
25
+ `release-manifest-win32.json`. macOS builds are signed and notarized.
26
+
27
+ ### Security
28
+
29
+ - **A server in `readonly` or `restricted` mode can no longer have a download written
30
+ anywhere on this machine.** `ssh_download` writes a local file and never looked at
31
+ the path, in any mode, and is not blocked in `readonly` or `restricted` because it
32
+ changes nothing on the server. An agent that cannot run a command on such a server
33
+ could still create a file there (a redirect to `/tmp` is allowed in `readonly`) and
34
+ download it over `~/.zshrc`, or into `~/.ssh/authorized_keys`, which a later shell
35
+ or login then ran. The local side of a transfer now has a **transfer root**: a
36
+ `readonly` or `restricted` server downloads into `~/.ssh-manager/transfers` (made
37
+ the first time, private to you; a relative local path is read from it), and any
38
+ server can name its own folder with `SSH_SERVER_<NAME>_TRANSFER_ROOT` (TOML:
39
+ `transfer_root`), which then also holds `ssh_upload` and `ssh_sync` to it. A path is
40
+ judged by where it really is after following links, a link as the file is refused,
41
+ and a download is received beside its place and moved there, so a failed one leaves
42
+ no half file. Servers in `unrestricted` mode with no root are not filtered, as
43
+ before. **If you download from a `readonly` or `restricted` server to a folder of
44
+ your own, set `TRANSFER_ROOT` to it**: a download elsewhere is refused with a message
45
+ that names the folder. Found while comparing this project with another SSH server
46
+ for MCP that confines its transfers the same way.
47
+
10
48
  ## [4.3.3] - 2026-11-21
11
49
 
12
50
  **A security release: upgrade if you use `restricted` mode.** On a server in
package/CLAUDE.md CHANGED
@@ -193,6 +193,7 @@ SSH_SERVER_[NAME]_PLATFORM=windows # Optional: "linux" (default) or "win
193
193
  SSH_SERVER_[NAME]_PROXYJUMP=bastion # Optional: name of another server to use as jump host
194
194
  SSH_SERVER_[NAME]_PROXYCOMMAND=command # Optional: custom proxy command (ncat, ssh -W, etc.)
195
195
  SSH_SERVER_[NAME]_FORWARD_AGENT=true # Optional: forward local ssh-agent to remote (needs SSH_AUTH_SOCK; security risk)
196
+ SSH_SERVER_[NAME]_TRANSFER_ROOT=~/transfers # Optional: the only local folder the file tools may use (readonly/restricted servers default to ~/.ssh-manager/transfers for downloads)
196
197
  SSH_SERVER_[NAME]_ANNOUNCE_AGENT=true # Optional: send AI_AGENT=mcp-ssh-manager to this host (off by default; SSH_MANAGER_ANNOUNCE_AGENT=true for all)
197
198
  ```
198
199
 
@@ -213,6 +214,7 @@ proxy_jump = "bastion" # Optional: name of another server to
213
214
  proxy_command = "command" # Optional: custom proxy command (ncat, ssh -W, etc.)
214
215
  forward_agent = true # Optional: forward local ssh-agent to remote (needs SSH_AUTH_SOCK; security risk)
215
216
  announce_agent = true # Optional: send AI_AGENT=mcp-ssh-manager to this host (off by default; false keeps it silent under the global switch)
217
+ transfer_root = "~/transfers" # Optional: the only local folder the file tools may use (see docs/SECURITY_MODES.md)
216
218
  ```
217
219
 
218
220
  ### Selecting an SSH agent key
@@ -13,8 +13,8 @@
13
13
  class SshManager < Formula
14
14
  desc "SSH server management for AI agents, with approval and audit"
15
15
  homepage "https://github.com/bvisible/mcp-ssh-manager"
16
- url "https://registry.npmjs.org/mcp-ssh-manager/-/mcp-ssh-manager-4.3.2.tgz"
17
- sha256 "5463cb719c00124432b7e8a835a8254888ddecb2006c631ff3651ddba3d0e267"
16
+ url "https://registry.npmjs.org/mcp-ssh-manager/-/mcp-ssh-manager-4.3.3.tgz"
17
+ sha256 "d8ee1b01cdc8238edee9c9bf0a6f83f7be98750ccd23976d273e7ad7f65df3cf"
18
18
  license "MIT"
19
19
 
20
20
  depends_on "node"
package/README.md CHANGED
@@ -25,7 +25,7 @@
25
25
  [![Desktop app downloads](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fbvisible%2Fmcp-ssh-manager%2Fstats%2Fdesktop.json&style=flat-square)](https://github.com/bvisible/mcp-ssh-manager/releases/latest)
26
26
  [![GitHub stars](https://img.shields.io/github/stars/bvisible/mcp-ssh-manager?style=flat-square&color=c04500)](https://github.com/bvisible/mcp-ssh-manager/stargazers)
27
27
  [![MCP Toplist](https://mcptoplist.com/badge/io.github.bvisible%2Fmcp-ssh-manager.svg)](https://mcptoplist.com/server/io.github.bvisible%2Fmcp-ssh-manager)
28
- [![Version](https://img.shields.io/badge/release-4.3.3-c04500?style=flat-square)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.3)
28
+ [![Version](https://img.shields.io/badge/release-4.3.4-c04500?style=flat-square)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.4)
29
29
  [![Claude Code](https://img.shields.io/badge/Claude_Code-Compatible-5A67D8?style=flat-square&logo=anthropic)](https://claude.ai/code)
30
30
  [![OpenAI Codex](https://img.shields.io/badge/OpenAI_Codex-Compatible-00A67E?style=flat-square&logo=openai)](https://openai.com/codex)
31
31
  [![MCP](https://img.shields.io/badge/MCP-Server-orange?style=flat-square)](https://modelcontextprotocol.io)
@@ -58,9 +58,9 @@ An MCP SSH server is the most dangerous tool you can hand an agent: a shell on m
58
58
 
59
59
  ## Choose your workspace
60
60
 
61
- **Desktop application (`4.3.3`):** one installation with its own runtime,
61
+ **Desktop application (`4.3.4`):** one installation with its own runtime,
62
62
  terminal, file browser and server settings. No separate Node.js or npm
63
- installation. [Download it](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.3):
63
+ installation. [Download it](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.4):
64
64
 
65
65
  | Platform | File | Signature |
66
66
  |---|---|---|
@@ -68,7 +68,7 @@ installation. [Download it](https://github.com/bvisible/mcp-ssh-manager/releases
68
68
  | Windows x64 / arm64 | `…-setup.exe` | **Not code-signed yet.** Windows shows *"Windows protected your PC"*: *More info → Run anyway*. Check the file against the SHA-256 in `release-manifest-win32.json` on the release (`ssh-manager app` does it for you). Signing comes in a later release. |
69
69
  | Linux x64 | `.deb`, `.AppImage` | Unsigned, as Linux packages usually are |
70
70
 
71
- **Already using npm / the CLI?** `npm update -g mcp-ssh-manager` brings 4.3.3,
71
+ **Already using npm / the CLI?** `npm update -g mcp-ssh-manager` brings 4.3.4,
72
72
  and the V4 engine runs without an interface, from your existing `.env`, TOML or
73
73
  process variables — no automatic import, no forced wizard, no approval prompt
74
74
  unless you enable one per server. The one behaviour that tightens is **SSH
@@ -720,6 +720,8 @@ The hero animation ships twice, light and dark, swapped by `<picture>` on `prefe
720
720
 
721
721
  ## What's new
722
722
 
723
+ **[4.3.4](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.4) — a security fix: `ssh_download` could write any file on your machine, even from a `readonly` server.** An agent that could not run a command on a `readonly` or `restricted` server could still have a file it had put on the server downloaded over `~/.zshrc` or into `~/.ssh/authorized_keys`. The local side of a transfer now has a transfer root: `readonly` and `restricted` servers download into `~/.ssh-manager/transfers`, and any server can name its own folder with `TRANSFER_ROOT`. If you download from such a server to a folder of your own, set `TRANSFER_ROOT` to it. (GHSA-2v9g-gm8g-mxgj) See the [CHANGELOG](CHANGELOG.md#434---2026-11-23).
724
+
723
725
  **[4.3.3](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.3) — a security fix: `restricted` mode could be made to run a command its allowlist never saw.** A comment, a here-document, an ANSI-C quote (`$'…'`) or a parenthesis could hide a command from the check while the shell ran it. The allowlist now reads comments as comments and refuses those constructs, with a reason. Servers in `readonly` mode and servers without a mode are unaffected; if you use `restricted` mode, upgrade. Reported by @Fastyyy123 (GHSA-86xm-rv3h-r4f2). See the [CHANGELOG](CHANGELOG.md#433---2026-11-21).
724
726
 
725
727
  **[4.3.2](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.2) — a command that fails no longer stays "running" on the Live page.** When a call threw instead of returning (a timeout, a dropped connection), or when the engine was closed mid-command, the Live entry read "running" until the control plane restarted. It now ends, as `exit -1`. Display only: nothing about the commands themselves changes. Found and traced by @TillNano (#159). See the [CHANGELOG](CHANGELOG.md#432---2026-11-21).
package/cli/lib/config.sh CHANGED
@@ -123,7 +123,7 @@ load_servers() {
123
123
  # The settings of a server, as the engine reads them (src/config-loader.js; a test
124
124
  # keeps the two lists in step). A server's lines are found by these names and never
125
125
  # by the bare prefix: removing "prod" used to remove the lines of "prod_eu" too.
126
- SERVER_ENV_FIELDS="HOST USER PASSWORD KEYPATH CERTPATH AGENT_PUBLIC_KEY_PATH PASSPHRASE PORT DEFAULT_DIR SUDO_PASSWORD DESCRIPTION GROUP PLATFORM PROXYJUMP PROXYCOMMAND FORWARD_AGENT ANNOUNCE_AGENT MODE ALLOW_PATTERNS DENY_PATTERNS AUDIT_LOG APPROVAL"
126
+ SERVER_ENV_FIELDS="HOST USER PASSWORD KEYPATH CERTPATH AGENT_PUBLIC_KEY_PATH PASSPHRASE PORT DEFAULT_DIR SUDO_PASSWORD DESCRIPTION GROUP PLATFORM PROXYJUMP PROXYCOMMAND FORWARD_AGENT ANNOUNCE_AGENT TRANSFER_ROOT MODE ALLOW_PATTERNS DENY_PATTERNS AUDIT_LOG APPROVAL"
127
127
 
128
128
  # Copy stdin to stdout without the lines of server $1 (upper case) whose setting is
129
129
  # in $2 (space separated). With a file as $3, its lines take the place of the first
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "ssh-manager-desktop",
3
- "version": "4.3.3",
3
+ "version": "4.3.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "ssh-manager-desktop",
9
- "version": "4.3.3",
9
+ "version": "4.3.4",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "electron-updater": "^6.8.9",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ssh-manager-desktop",
3
3
  "productName": "SSH Manager",
4
- "version": "4.3.3",
4
+ "version": "4.3.4",
5
5
  "private": true,
6
6
  "description": "The SSH Manager control plane as a desktop application",
7
7
  "main": "main.js",
package/docs/MIGRATION.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Upgrading from 3.8 to 4.0
2
2
 
3
- **4.0 is released, on npm and as a desktop application**; the latest is 4.3.3 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.3)).
3
+ **4.0 is released, on npm and as a desktop application**; the latest is 4.3.4 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.3.4)).
4
4
  The last 3.8 release is 3.8.7, for anyone who pins the 3.8 line.
5
5
 
6
6
  The upgrade path preserves headless npm/CLI use. The application, vault import
@@ -95,6 +95,39 @@ audit_log = "/var/log/mcp-ssh-prod.jsonl"
95
95
  TOML arrays are preferred. A `;`-separated string is also accepted for
96
96
  parity with the `.env` form.
97
97
 
98
+ ### Where the file tools may write on this machine: the transfer root
99
+
100
+ `ssh_download` writes a file on the machine that runs the engine, and `ssh_upload`
101
+ and `ssh_sync` read from it. `readonly` and `restricted` are about what runs on the
102
+ *server*, and an agent that cannot run a command there could still put a file of its
103
+ choosing on the server (a redirect to `/tmp` is allowed in `readonly`) and have it
104
+ downloaded over `~/.zshrc` or into `~/.ssh/authorized_keys` here. Up to 4.3.3 nothing
105
+ looked at the local path. A **transfer root** is the one folder the local side of a
106
+ transfer may use:
107
+
108
+ ```bash
109
+ SSH_SERVER_PROD_TRANSFER_ROOT=~/transfers/prod # TOML: transfer_root = "~/transfers/prod"
110
+ ```
111
+
112
+ - A server with a `TRANSFER_ROOT` is held to it in every mode, by all three tools.
113
+ - A server in `readonly` or `restricted` mode with none is held to
114
+ `~/.ssh-manager/transfers` for `ssh_download` (`ssh_upload` and `ssh_sync` are refused
115
+ there already). The folder is made, private to you, the first time a download needs it.
116
+ - A server in `unrestricted` mode with none is not filtered, as before.
117
+
118
+ A relative local path is read from the root, so `ssh_download` with the local path
119
+ `logs/app.log` writes `~/.ssh-manager/transfers/logs/app.log`. A path is accepted when
120
+ its real location, after following every link, is inside the root; `..`, a sibling
121
+ folder that starts like the root, and a folder link that leads out are refused, and so
122
+ is a link as the file itself. A download is received beside its place and moved there,
123
+ so a transfer that fails leaves no half file, and a link put there meanwhile is replaced,
124
+ not followed. The check runs just before the transfer: it does not stop someone who can
125
+ already change files inside the root while it runs, and for `ssh_sync` it covers the
126
+ folder named, not what rsync does inside it.
127
+
128
+ If you download to a folder of your own from a `readonly` or `restricted` server, set
129
+ `TRANSFER_ROOT` to that folder.
130
+
98
131
  ## Audit log
99
132
 
100
133
  When `AUDIT_LOG` (`.env`) or `audit_log` (TOML) is set to a file path, every
@@ -186,7 +219,8 @@ SSH_SERVER_CLIENT_PROD_AUDIT_LOG=~/.ssh-manager/audit/client-prod.jsonl
186
219
  `ssh_key_manage` (only `accept` / `remove`), `ssh_alert_setup` (only `set`),
187
220
  `ssh_process_manager` (only `kill`).
188
221
 
189
- **Not gated** (pure reads or local-only state — no remote effect to block):
222
+ **Not gated** (pure reads or local-only state — no remote effect to block; the
223
+ local side of `ssh_download` is held to the transfer root, see above):
190
224
  `ssh_list_servers`, `ssh_download`, `ssh_tail`, `ssh_monitor`, `ssh_history`,
191
225
  `ssh_health_check`, `ssh_service_status`, `ssh_db_list`, `ssh_db_query`
192
226
  (one SELECT run in a read-only transaction; for MongoDB a filter document,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "4.3.3",
3
+ "version": "4.3.4",
4
4
  "mcpName": "io.github.bvisible/mcp-ssh-manager",
5
5
  "description": "MCP server for SSH: let AI agents (Claude Code, Codex, any MCP client) run commands, transfer files and manage servers over SSH, with human approval, an encrypted vault and a live audit trail.",
6
6
  "main": "src/index.js",
@@ -14,7 +14,7 @@
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:vault && npm run test:recovery && npm run test:upgrade && npm run test:notify && npm run test:commands && npm run test:commandlog && npm run test:portability && npm run test:approval && npm run test:controlplane && npm run test:terminal && npm run test:files && npm run test:livestream && npm run test:livefailure && npm run test:skills && 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:shellsegments && npm run test:policynames && npm run test:auditsuccess && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:agentkey && npm run test:certpath && npm run test:agentannounce && npm run test:autherrors && npm run test:envchoice && 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:quoteprops && npm run test:backupinjection && npm run test:dbrowcount && npm run test:dbclientcmds && npm run test:migration && npm run test:security && npm run test:hostkeys && npm run test:proxy && npm run test:working-directory && npm run test:groups-persistence && npm run test:release && npm run test:cli-experience && npm run test:desktop-install && npm run test:agent-clients && npm run test:appupdate && npm run test:preview && npm run test:desktop-smoke && npm run test:local-shell && npm run test:cli-edit && npm run test:timeoutwrap && npm run test:downloadstats && npm run test:remotetunnel && npm run test:connsharing && npm run test:auditcoverage && npm run test:background && npm run test:quietstderr && npm run test:sshguard && npm run test:locale && npm run test:langtool && npm run test:healthdisks && npm run test:backupintegrity && npm run test:clienvlines && npm run test:clicodex",
17
+ "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:vault && npm run test:recovery && npm run test:upgrade && npm run test:notify && npm run test:commands && npm run test:commandlog && npm run test:portability && npm run test:approval && npm run test:controlplane && npm run test:terminal && npm run test:files && npm run test:livestream && npm run test:livefailure && npm run test:transferpaths && npm run test:skills && 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:shellsegments && npm run test:policynames && npm run test:auditsuccess && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:agentkey && npm run test:certpath && npm run test:agentannounce && npm run test:autherrors && npm run test:envchoice && 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:quoteprops && npm run test:backupinjection && npm run test:dbrowcount && npm run test:dbclientcmds && npm run test:migration && npm run test:security && npm run test:hostkeys && npm run test:proxy && npm run test:working-directory && npm run test:groups-persistence && npm run test:release && npm run test:cli-experience && npm run test:desktop-install && npm run test:agent-clients && npm run test:appupdate && npm run test:preview && npm run test:desktop-smoke && npm run test:local-shell && npm run test:cli-edit && npm run test:timeoutwrap && npm run test:downloadstats && npm run test:remotetunnel && npm run test:connsharing && npm run test:auditcoverage && npm run test:background && npm run test:quietstderr && npm run test:sshguard && npm run test:locale && npm run test:langtool && npm run test:healthdisks && npm run test:backupintegrity && npm run test:clienvlines && npm run test:clicodex",
18
18
  "test:lockfile": "node tests/test-lockfile.js",
19
19
  "test:sudostdin": "node tests/test-sudo-stdin.js",
20
20
  "test:vault": "node tests/test-secret-store.js",
@@ -22,6 +22,7 @@
22
22
  "test:controlplane": "node tests/test-control-plane.js",
23
23
  "test:livestream": "node tests/test-live-stream.js",
24
24
  "test:livefailure": "node tests/test-live-stream-failure.js",
25
+ "test:transferpaths": "node tests/test-transfer-paths.js",
25
26
  "test:skills": "node tests/test-skills.js",
26
27
  "test:redaction": "node tests/test-logger-redaction.js",
27
28
  "test:profiles": "node tests/test-profiles.js",
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": "4.3.3",
9
+ "version": "4.3.4",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "mcp-ssh-manager",
14
- "version": "4.3.3",
14
+ "version": "4.3.4",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -38,6 +38,7 @@ import { resolveConfigOptions } from './config-paths.js';
38
38
  * @property {string} [proxyJump] Name of another configured server to jump through.
39
39
  * @property {string} [proxyCommand] Custom proxy command (`%h` / `%p` placeholders).
40
40
  * @property {boolean} [forwardAgent] Forward the local ssh-agent to this server.
41
+ * @property {string} [transferRoot] The only folder the local side of ssh_download, ssh_upload and ssh_sync may use. Unset: no limit in unrestricted mode, and ~/.ssh-manager/transfers for ssh_download in readonly and restricted mode.
41
42
  * @property {boolean} [announceAgent] Send AI_AGENT=mcp-ssh-manager on each command channel. Unset defers to SSH_MANAGER_ANNOUNCE_AGENT (off by default); false keeps a host silent even when that is on.
42
43
  * @property {string} [mode] Security mode: `unrestricted`, `readonly` or `restricted`.
43
44
  * @property {string} [approval] Human approval mode: `never`, `destructive` or `always`.
@@ -280,6 +281,7 @@ export class ConfigLoader {
280
281
  proxyCommand: serverConfig.proxy_command || serverConfig.proxycommand,
281
282
  forwardAgent: parseBool(serverConfig.forward_agent),
282
283
  announceAgent: parseOptionalBool(serverConfig.announce_agent),
284
+ transferRoot: serverConfig.transfer_root,
283
285
  mode,
284
286
  // approval is deliberately NOT read here — see loadEnvConfig below.
285
287
 
@@ -359,6 +361,7 @@ export class ConfigLoader {
359
361
  proxyCommand: env[`SSH_SERVER_${match[1]}_PROXYCOMMAND`],
360
362
  forwardAgent: parseBool(env[`SSH_SERVER_${match[1]}_FORWARD_AGENT`]),
361
363
  announceAgent: parseOptionalBool(env[`SSH_SERVER_${match[1]}_ANNOUNCE_AGENT`]),
364
+ transferRoot: env[`SSH_SERVER_${match[1]}_TRANSFER_ROOT`],
362
365
  mode,
363
366
  // approval is deliberately NOT read from files. It is the switch
364
367
  // that makes an agent stop and wait for a human, and a switch that
@@ -447,6 +450,7 @@ export class ConfigLoader {
447
450
  // Either explicit value is a decision worth keeping; unset is not written,
448
451
  // so the global switch still applies after a round trip.
449
452
  if (typeof server.announceAgent === 'boolean') serverConfig.announce_agent = server.announceAgent;
453
+ if (server.transferRoot) serverConfig.transfer_root = server.transferRoot;
450
454
  // Only emit security fields if they diverge from defaults — keeps generated
451
455
  // TOML files clean for users who never opted in.
452
456
  if (server.mode && server.mode !== 'unrestricted') serverConfig.mode = server.mode;
@@ -493,6 +497,7 @@ export class ConfigLoader {
493
497
  // Written whenever it was set, true or false: an explicit false has to
494
498
  // survive a round trip, or a global switch would re-enable that host.
495
499
  if (typeof server.announceAgent === 'boolean') lines.push(`SSH_SERVER_${upperName}_ANNOUNCE_AGENT=${server.announceAgent}`);
500
+ if (server.transferRoot) lines.push(`SSH_SERVER_${upperName}_TRANSFER_ROOT=${server.transferRoot}`);
496
501
  if (server.proxyJump) lines.push(`SSH_SERVER_${upperName}_PROXYJUMP=${server.proxyJump}`);
497
502
  if (server.proxyCommand) lines.push(`SSH_SERVER_${upperName}_PROXYCOMMAND=${server.proxyCommand}`);
498
503
  // Security fields — only emit when non-default to avoid clutter in
package/src/index.js CHANGED
@@ -10,6 +10,7 @@ import { connectSSH, connectServer } from './ssh-connection.js';
10
10
  import * as dotenv from 'dotenv';
11
11
  import fs from 'fs';
12
12
  import path from 'path';
13
+ import crypto from 'node:crypto';
13
14
  import { AsyncLocalStorage } from 'node:async_hooks';
14
15
  import { isDeepStrictEqual } from 'node:util';
15
16
  import { envFileChoice, envFileProblem, expandHomePath } from './config-paths.js';
@@ -158,6 +159,7 @@ import { buildBackgroundCommand, parseBackgroundStart } from './background-job.j
158
159
  import { needsApproval, isControlPlaneListening, requestDecision, buildRequest, isApprovalExempt, isReadOnlyAction, HANDLER_GATED_TOOLS } from './approval.js';
159
160
  import { shellQuote, shellPath, safeInteger, withRemoteTimeout } from './shell-quote.js';
160
161
  import { openStream } from './live-stream.js';
162
+ import { transferPolicy, confineLocalPath } from './transfer-paths.js';
161
163
  import { auditLog, sanitize } from './audit.js';
162
164
 
163
165
  const __filename = fileURLToPath(import.meta.url);
@@ -918,7 +920,7 @@ registerToolConditional(
918
920
  registerToolConditional(
919
921
  'ssh_upload',
920
922
  {
921
- description: 'Uploads one local file to a remote destination path over SFTP on the named server, overwriting any existing remote file at that path. Mutates remote state and is not idempotent beyond replacing the target. Creates no backup. Requires the local file to exist. Does not use sudo, so the remote path must be writable by the configured SSH user. This tool is blocked entirely on servers set to readonly or restricted security mode. For directory trees use ssh_sync instead.',
923
+ description: 'Uploads one local file to a remote destination path over SFTP on the named server, overwriting any existing remote file at that path. Mutates remote state and is not idempotent beyond replacing the target. Creates no backup. Requires the local file to exist. Does not use sudo, so the remote path must be writable by the configured SSH user. This tool is blocked entirely on servers set to readonly or restricted security mode. On a server with a transferRoot the local file must be inside that folder. For directory trees use ssh_sync instead.',
922
924
  inputSchema: {
923
925
  server: z.string().describe('Server name'),
924
926
  localPath: z.string().describe('Local file path'),
@@ -928,14 +930,18 @@ registerToolConditional(
928
930
  async ({ server: serverName, localPath, remotePath }) => {
929
931
 
930
932
  try {
933
+ // With a transferRoot on the server, the local file must be inside it (readonly
934
+ // and restricted servers never get here: the tool is refused for them).
935
+ const policy = transferPolicy(await getServerConfig(serverName), 'ssh_upload');
936
+ const source = policy ? confineLocalPath(policy, localPath, { direction: 'read' }) : localPath;
931
937
  const ssh = await getConnection(serverName);
932
938
 
933
939
  logger.logTransfer('upload', serverName, localPath, remotePath);
934
940
  const startTime = Date.now();
935
941
 
936
- await ssh.putFile(localPath, remotePath);
942
+ await ssh.putFile(source, remotePath);
937
943
 
938
- const fileStats = fs.statSync(localPath);
944
+ const fileStats = fs.statSync(source);
939
945
  logger.logTransfer('upload', serverName, localPath, remotePath, {
940
946
  success: true,
941
947
  size: fileStats.size,
@@ -977,7 +983,7 @@ registerToolConditional(
977
983
  registerToolConditional(
978
984
  'ssh_download',
979
985
  {
980
- description: 'Downloads one remote file from the named server to a local destination path over SFTP, overwriting any existing local file at that path. Affects only the local filesystem and is read-only on the remote side, so it stays allowed even on servers in readonly or restricted security mode. Reads the remote file using the configured SSH user, which must have permission to read it. Handles single files only; use ssh_sync for directories.',
986
+ description: 'Downloads one remote file from the named server to a local destination path over SFTP, overwriting any existing local file at that path. Affects only the local filesystem and is read-only on the remote side, so it stays allowed even on servers in readonly or restricted security mode, where the local path must be inside the transfer folder (~/.ssh-manager/transfers, or the transferRoot set on the server): a relative path is read from it, and anything outside it, or reached through a link, is refused. On other servers the local path is unrestricted unless a transferRoot is set. Reads the remote file using the configured SSH user, which must have permission to read it. Handles single files only; use ssh_sync for directories.',
981
987
  inputSchema: {
982
988
  server: z.string().describe('Server name'),
983
989
  remotePath: z.string().describe('Remote file path'),
@@ -986,15 +992,32 @@ registerToolConditional(
986
992
  },
987
993
  async ({ server: serverName, remotePath, localPath }) => {
988
994
  try {
995
+ // A server in readonly or restricted mode, or with a transferRoot, writes only
996
+ // inside that folder: the file is received beside its place and moved there, so a
997
+ // failed transfer never leaves half a file, and a link put there meanwhile is
998
+ // replaced, not followed.
999
+ const policy = transferPolicy(await getServerConfig(serverName), 'ssh_download');
1000
+ const target = policy ? confineLocalPath(policy, localPath, { direction: 'write' }) : localPath;
989
1001
  const ssh = await getConnection(serverName);
990
1002
 
991
- logger.logTransfer('download', serverName, remotePath, localPath);
1003
+ logger.logTransfer('download', serverName, remotePath, target);
992
1004
  const startTime = Date.now();
993
1005
 
994
- await ssh.getFile(localPath, remotePath);
1006
+ if (policy) {
1007
+ const partial = `${target}.part-${crypto.randomBytes(4).toString('hex')}`;
1008
+ try {
1009
+ await ssh.getFile(partial, remotePath);
1010
+ fs.renameSync(partial, target);
1011
+ } catch (error) {
1012
+ fs.rmSync(partial, { force: true });
1013
+ throw error;
1014
+ }
1015
+ } else {
1016
+ await ssh.getFile(target, remotePath);
1017
+ }
995
1018
 
996
- const fileStats = fs.statSync(localPath);
997
- logger.logTransfer('download', serverName, remotePath, localPath, {
1019
+ const fileStats = fs.statSync(target);
1020
+ logger.logTransfer('download', serverName, remotePath, target, {
998
1021
  success: true,
999
1022
  size: fileStats.size,
1000
1023
  duration: `${Date.now() - startTime}ms`
@@ -1006,7 +1029,7 @@ registerToolConditional(
1006
1029
  content: [
1007
1030
  {
1008
1031
  type: 'text',
1009
- text: `✅ File downloaded successfully\nServer: ${serverName}\nRemote: ${remotePath}\nLocal: ${localPath}`,
1032
+ text: `✅ File downloaded successfully\nServer: ${serverName}\nRemote: ${remotePath}\nLocal: ${target}`,
1010
1033
  },
1011
1034
  ],
1012
1035
  };
@@ -1035,7 +1058,7 @@ registerToolConditional(
1035
1058
  registerToolConditional(
1036
1059
  'ssh_sync',
1037
1060
  {
1038
- description: 'Synchronizes files or directories between local and remote using rsync over SSH on the named server. Each of source and destination must carry a local: or remote: prefix and one side must be local and the other remote; with no prefix it assumes a push from local to remote. On Windows MCP hosts, provide native Windows local paths such as C:\\project or .\\project; the tool converts drive-letter and UNC paths to MSYS2 format before spawning rsync. Do not pre-convert a local path to /c/project because Node performs local filesystem checks using Windows path semantics. Mutates the destination. Setting delete true removes destination files absent from source, which is destructive; dryRun true previews without changing anything. Compression is on by default. Password authentication requires sshpass installed locally. Blocked on readonly or restricted servers. Timeout defaults to 30000 ms.',
1061
+ description: 'Synchronizes files or directories between local and remote using rsync over SSH on the named server. Each of source and destination must carry a local: or remote: prefix and one side must be local and the other remote; with no prefix it assumes a push from local to remote. On Windows MCP hosts, provide native Windows local paths such as C:\\project or .\\project; the tool converts drive-letter and UNC paths to MSYS2 format before spawning rsync. Do not pre-convert a local path to /c/project because Node performs local filesystem checks using Windows path semantics. Mutates the destination. Setting delete true removes destination files absent from source, which is destructive; dryRun true previews without changing anything. Compression is on by default. Password authentication requires sshpass installed locally. Blocked on readonly or restricted servers. On a server with a transferRoot the local side must be inside that folder. Timeout defaults to 30000 ms.',
1039
1062
  inputSchema: {
1040
1063
  server: z.string().describe('Server name from configuration'),
1041
1064
  source: z.string().describe('Source path with a "local:" or "remote:" prefix. On Windows, use a native local path such as "local:C:\\project" or "local:.\\project"; do not pre-convert it to MSYS2 /c/... syntax.'),
@@ -1123,8 +1146,11 @@ registerToolConditional(
1123
1146
  let localPath;
1124
1147
  let remotePath;
1125
1148
 
1149
+ // With a transferRoot on the server, the local side stays inside it. (readonly
1150
+ // and restricted servers never get here: the tool is refused for them.)
1151
+ const syncPolicy = transferPolicy(serverConfig, 'ssh_sync');
1126
1152
  if (direction === 'push') {
1127
- localPath = cleanSource;
1153
+ localPath = syncPolicy ? confineLocalPath(syncPolicy, cleanSource, { direction: 'read', allowRoot: true }) : cleanSource;
1128
1154
  remotePath = cleanDest;
1129
1155
 
1130
1156
  // Check if local path exists
@@ -1132,7 +1158,7 @@ registerToolConditional(
1132
1158
  throw new Error(`Local path does not exist: ${localPath}`);
1133
1159
  }
1134
1160
  } else {
1135
- localPath = cleanDest;
1161
+ localPath = syncPolicy ? confineLocalPath(syncPolicy, cleanDest, { direction: 'write', allowRoot: true }) : cleanDest;
1136
1162
  remotePath = cleanSource;
1137
1163
  }
1138
1164
 
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Where the file tools may touch the local disk.
3
+ *
4
+ * `ssh_download` writes a local file, `ssh_upload` reads one, `ssh_sync` does
5
+ * either. None of them looked at the local path, so an agent that could not run
6
+ * a single command on a `readonly` server could still have `ssh_download` write
7
+ * `~/.zshrc` or `~/.ssh/authorized_keys` on this machine, with content it had
8
+ * just put on the server (`printf … > /tmp/x` is allowed in `readonly`).
9
+ *
10
+ * A transfer root is the one directory the local side of a transfer may use:
11
+ *
12
+ * - `transferRoot` on a server (`SSH_SERVER_<NAME>_TRANSFER_ROOT`,
13
+ * `transfer_root` in TOML) turns it on for that server, in every mode, for
14
+ * all three tools;
15
+ * - a server in `readonly` or `restricted` mode has one even when none is set,
16
+ * for `ssh_download` (the other two are refused there already): the
17
+ * `transfers` folder of the manager home (`~/.ssh-manager/transfers`). It is
18
+ * created, private to the user, the first time a download needs it;
19
+ * - a server in `unrestricted` mode with no `transferRoot` is exactly what it
20
+ * was: no filter at all, by design.
21
+ *
22
+ * A path is accepted when its real location, after following every link, is
23
+ * inside the root. A relative path is read from the root. A link as the file
24
+ * itself is refused, in either direction, and so is a link directory that leads
25
+ * out. The checks run just before the transfer; they do not stop somebody who
26
+ * can already change files in the root while it runs.
27
+ */
28
+
29
+ import fs from 'fs';
30
+ import path from 'path';
31
+ import { expandHomePath, managerHome } from './config-paths.js';
32
+
33
+ const CONFINED_MODES = new Set(['readonly', 'restricted']);
34
+
35
+ /**
36
+ * @typedef {object} TransferPolicy
37
+ * @property {string} root - Where the local side of a transfer must stay
38
+ * @property {boolean} explicit - The server names its own root
39
+ */
40
+
41
+ /**
42
+ * The transfer policy of a server for a tool, or null when its local paths are
43
+ * not filtered.
44
+ *
45
+ * @param {{mode?: string, transferRoot?: string}|null|undefined} serverConfig
46
+ * @param {string} toolName - ssh_download, ssh_upload or ssh_sync
47
+ * @returns {TransferPolicy|null}
48
+ */
49
+ export function transferPolicy(serverConfig, toolName) {
50
+ const configured = typeof serverConfig?.transferRoot === 'string' ? serverConfig.transferRoot.trim() : '';
51
+ if (configured) return { root: path.resolve(expandHomePath(configured)), explicit: true };
52
+ // Without a named root only the download is held to the default one: the
53
+ // upload and the sync cannot run at all in these two modes.
54
+ if (toolName === 'ssh_download' && CONFINED_MODES.has(String(serverConfig?.mode ?? '').toLowerCase())) {
55
+ return { root: path.join(managerHome(), 'transfers'), explicit: false };
56
+ }
57
+ return null;
58
+ }
59
+
60
+ /**
61
+ * True when `candidate` is `root` or below it.
62
+ * @param {string} root
63
+ * @param {string} candidate
64
+ * @param {boolean} allowRoot
65
+ */
66
+ function within(root, candidate, allowRoot) {
67
+ const relative = path.relative(root, candidate);
68
+ if (relative === '') return allowRoot;
69
+ return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
70
+ }
71
+
72
+ /** @param {string} target */
73
+ function lstatOrNull(target) {
74
+ try { return fs.lstatSync(target); } catch { return null; }
75
+ }
76
+
77
+ /**
78
+ * Where `target` really is: the part that exists with every link followed, then
79
+ * the part that does not exist yet as written.
80
+ * @param {string} target - Absolute path
81
+ * @returns {string}
82
+ */
83
+ function realLocation(target) {
84
+ const missing = [];
85
+ let current = target;
86
+ while (!lstatOrNull(current)) {
87
+ const parent = path.dirname(current);
88
+ if (parent === current) break;
89
+ missing.unshift(path.basename(current));
90
+ current = parent;
91
+ }
92
+ return path.join(fs.realpathSync.native(current), ...missing);
93
+ }
94
+
95
+ /**
96
+ * Resolve the local side of a transfer to the path the tool must use, or throw
97
+ * with the reason it may not.
98
+ *
99
+ * @param {TransferPolicy} policy
100
+ * @param {string} localPath - As the caller gave it
101
+ * @param {{direction: 'read'|'write', allowRoot?: boolean}} options
102
+ * `read`: the path must exist. `write`: its folder is made inside the root when missing.
103
+ * `allowRoot`: the root itself is acceptable (a folder for a sync).
104
+ * @returns {string} An absolute path under the real root; a trailing separator is kept
105
+ */
106
+ export function confineLocalPath(policy, localPath, { direction, allowRoot = false }) {
107
+ const given = String(localPath);
108
+ if (!given || given.includes('\0')) throw new Error('The local path is empty or not a valid path');
109
+ const hint = policy.explicit
110
+ ? 'the transfer root set for this server (transferRoot)'
111
+ : 'the transfer folder of a server in readonly or restricted mode (~/.ssh-manager/transfers, or set transferRoot on the server)';
112
+ const outside = () => new Error(`Local path "${given}" is outside ${hint}: ${policy.root}`);
113
+
114
+ fs.mkdirSync(policy.root, { recursive: true, mode: 0o700 });
115
+ const realRoot = fs.realpathSync.native(policy.root);
116
+ const trailing = /[\\/]$/.test(given) ? path.sep : '';
117
+
118
+ // A relative path is read from the root; an absolute one is taken as written. Either
119
+ // way what counts is where it really is: its folder with every link followed (so
120
+ // /tmp/x and /private/tmp/x, or the root by another name, are the same place, and a
121
+ // link folder that leads out is out). The file itself is looked at below.
122
+ const absolute = path.isAbsolute(given) ? path.resolve(given) : path.resolve(realRoot, given);
123
+ const target = path.join(realLocation(path.dirname(absolute)), path.basename(absolute));
124
+ if (!within(realRoot, target, allowRoot)) throw outside();
125
+
126
+ const existing = lstatOrNull(target);
127
+ if (existing?.isSymbolicLink()) throw new Error(`Local path "${given}" is a link; a transfer does not follow links`);
128
+ if (direction === 'read' && !existing) throw new Error(`Local path does not exist: ${given}`);
129
+ if (direction === 'write' && existing?.isDirectory() && !allowRoot) throw new Error(`Local path "${given}" is a folder`);
130
+ if (direction === 'write' && !existing) {
131
+ fs.mkdirSync(trailing ? target : path.dirname(target), { recursive: true, mode: 0o700 });
132
+ }
133
+ return trailing && !target.endsWith(path.sep) ? target + trailing : target;
134
+ }