mcp-ssh-manager 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,102 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.1.0] - 2026-11-13
11
+
12
+ **Choose the agent key per server, and sudo in the audit log.** Nothing to
13
+ change on upgrade: the new option is off unless you set it, and the audit log
14
+ only gains lines when `AUDIT_LOG` is already on (the release pipeline upgrades
15
+ 3.8.5, 3.8.6, 3.8.7 and every 4.0.x from the registry to this version and back).
16
+
17
+ The Windows installer is still **not Authenticode-signed**, for the same reason
18
+ as 4.0.0: Windows shows *"Windows protected your PC"*, *More info → Run anyway*,
19
+ and `ssh-manager app` checks the installer against the SHA-256 in
20
+ `release-manifest-win32.json`. macOS builds are signed and notarized.
21
+
22
+ ### Added
23
+
24
+ - **Pick which key of the SSH agent a server uses** (#128, thanks to
25
+ @RebornOnce). When the agent holds many keys (a password manager's agent,
26
+ say), a server can hit `MaxAuthTries` and close the connection before the
27
+ right one is offered. `agent_public_key_path` in TOML, or
28
+ `SSH_SERVER_<NAME>_AGENT_PUBLIC_KEY_PATH` in `.env`, names a public key file:
29
+ only that identity is offered and used for signing, and the private key never
30
+ leaves the agent. If the agent does not hold it, the connection fails instead
31
+ of trying the others. It cannot be combined with a key, a password, a
32
+ certificate or agent forwarding, and nothing changes for servers without it.
33
+ `ssh_sync` uses the system's `ssh`, which takes `IdentityFile` and
34
+ `IdentitiesOnly yes` from your SSH configuration instead.
35
+ - **`llms-install.md`**: the steps an agent follows to set the server up for its
36
+ user (Node, the client entry, servers described in `~/.ssh-manager/.env` with
37
+ a key and never a password typed into the conversation, then a check). It is
38
+ what the Cline MCP Marketplace asks for, and any agent can follow it.
39
+
40
+ ### Fixed
41
+
42
+ - **The audit log records what `sudo` commands did** (#133, reported by
43
+ @revert12; #134, thanks to @orshih6). With `AUDIT_LOG` set, only
44
+ `ssh_execute` and `ssh_upload` wrote their outcome: a command run through
45
+ `ssh_execute_sudo` that the policy allowed left no line at all. It now records
46
+ the exit code and success (the logged arguments are the command and the
47
+ working directory, never the password), and so do `ssh_download`,
48
+ `ssh_execute_group` (one line per server) and commands sent to a persistent
49
+ session (success only: sessions report no exit code). Other tools still record
50
+ only a denial or an approval decision.
51
+
52
+ ### Security
53
+
54
+ - **The desktop build uses a fixed `minimatch`.** `electron-builder`, the tool
55
+ that builds the desktop app, pulled `minimatch` 10.2.6 and 9.0.9, open to a
56
+ denial of service through crafted glob patterns (GHSA-g3hv-75wg-m249). Nothing
57
+ was exposed: the tool only reads the patterns of our own build configuration,
58
+ and no copy of `minimatch` ships in the app or in the npm package. An npm
59
+ `overrides` entry in `desktop/electron/package.json` now resolves those copies
60
+ to 11.x; a build with it contains the same files as one without, the
61
+ `package.json` line aside. Remove the entry once `app-builder-lib` itself
62
+ requires `minimatch` 11.0.1 or later.
63
+
64
+ - **`@hono/node-server` 2.1.8 and `hono` 4.13.18 in the lockfile.** Two
65
+ moderate advisories for the first (GHSA-qv5m-9pm6-hqp3, GHSA-jpvv-r467-5p4w),
66
+ five for the second (four moderate, one low: GHSA-46wx-v44x-9hh2,
67
+ GHSA-4h7h-rv7c-7m2v, GHSA-4m76-xfj5-7975, GHSA-h7mg-cq63-vhpq,
68
+ GHSA-3gg2-335m-rxc6). The MCP SDK pulls both for its HTTP transport; the
69
+ stdio server this package runs never imports them, so nothing was exposed.
70
+
71
+ ## [4.0.3] - 2026-11-05
72
+
73
+ **A security release: upgrade.** `ssh_db_query` could run shell commands on
74
+ the server ([GHSA-qmf5-hrhv-5hjm](https://github.com/bvisible/mcp-ssh-manager/security/advisories/GHSA-qmf5-hrhv-5hjm),
75
+ high, reported by @orshih6). Every earlier version is affected; nothing else
76
+ changes (the release pipeline upgrades 3.8.5, 3.8.6, 3.8.7, 4.0.0, 4.0.1 and
77
+ 4.0.2 from the registry to this version and back).
78
+
79
+ The Windows installer is **not Authenticode-signed** in this release either,
80
+ for the same reason as 4.0.0: Windows shows *"Windows protected your PC"*,
81
+ *More info → Run anyway*, and `ssh-manager app` checks the installer against
82
+ the SHA-256 in `release-manifest-win32.json`. macOS builds are signed and notarized.
83
+
84
+ ### Security
85
+
86
+ - **`ssh_db_query` no longer lets the database client reach a shell.** The tool
87
+ is read-only, so it is allowed on servers in `readonly` and `restricted` mode
88
+ and never held for approval. Its SQL went to the remote `psql` or `mysql`
89
+ client as the client's input, and both clients act on commands of their own
90
+ found there: `\!` runs a shell command, psql's `\o |command` pipes to one,
91
+ mysql's `system` does at the start of a line. A query such as
92
+ `SELECT 1 \! <command>` passed the SELECT-only check, so a read-only query
93
+ could run anything as the SSH user, and an agent misled by what it read could
94
+ do it on a server meant to be read-only.
95
+ - **PostgreSQL**: each statement is now a single-quoted `-c` argument, which
96
+ psql sends to the server as it is, inside the same read-only transaction.
97
+ Multi-line queries and backslashes in literals keep working.
98
+ - **MySQL / MariaDB**: the client reads its commands even from `-e`, and no
99
+ option to turn them off exists in every client, so a MySQL query must now be
100
+ one line without backslashes (and without other control characters). The
101
+ error says so.
102
+ - `tests/test-db-client-commands.js` runs the report's payloads through the
103
+ real engine, over SSH, to a server in readonly mode, against a real psql and
104
+ a real MariaDB client: queries answer, no payload reaches a shell.
105
+
10
106
  ## [4.0.2] - 2026-11-01
11
107
 
12
108
  **Commands reach a Mac, and the desktop terminal behaves like your own.**
package/CLAUDE.md CHANGED
@@ -185,6 +185,7 @@ SSH_SERVER_[NAME]_HOST=hostname
185
185
  SSH_SERVER_[NAME]_USER=username
186
186
  SSH_SERVER_[NAME]_PASSWORD=password # For password auth
187
187
  SSH_SERVER_[NAME]_KEYPATH=~/.ssh/key # For SSH key auth
188
+ SSH_SERVER_[NAME]_AGENT_PUBLIC_KEY_PATH=~/.ssh/id_ed25519.pub # Alternative: select one SSH_AUTH_SOCK identity
188
189
  SSH_SERVER_[NAME]_PASSPHRASE=passphrase # Optional, for passphrase-protected keys
189
190
  SSH_SERVER_[NAME]_PORT=22 # Optional
190
191
  SSH_SERVER_[NAME]_DEFAULT_DIR=/path # Optional default working directory
@@ -216,6 +217,19 @@ forward_agent = true # Optional: forward local ssh-agent t
216
217
  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
218
  ```
218
219
 
220
+ ### Selecting an SSH agent key
221
+
222
+ Use `agent_public_key_path` in TOML or `SSH_SERVER_[NAME]_AGENT_PUBLIC_KEY_PATH` in `.env` (internal field: `agentPublicKeyPath`) to select a single public key from the existing agent at `SSH_AUTH_SOCK`:
223
+
224
+ ```toml
225
+ [ssh_servers.agent_host]
226
+ host = "example.com"
227
+ user = "admin"
228
+ agent_public_key_path = "~/.ssh/id_ed25519.pub"
229
+ ```
230
+
231
+ This works with compatible SSH agents, including compatible password-manager agents; signing stays in the agent. Missing or invalid public key files, an unavailable agent, or no matching identity fail authentication without falling back to other agent identities. Combining this option with `key_path`, `password`, `cert_path`, or enabled `forward_agent` is rejected. Without this option, existing authentication behavior is unchanged. `ssh_sync` uses system OpenSSH and does not apply this filter; configure `IdentityFile` and `IdentitiesOnly yes` separately in the SSH client configuration.
232
+
219
233
  ## Key Implementation Details
220
234
 
221
235
  1. **Connection Pooling**: The server maintains persistent SSH connections in a Map to avoid reconnection overhead (src/index.js:31)
@@ -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.0.1.tgz"
17
- sha256 "c931cb956869345975c59f953329be71eb75c893b8810dbe6121f26ccedc1880"
16
+ url "https://registry.npmjs.org/mcp-ssh-manager/-/mcp-ssh-manager-4.0.3.tgz"
17
+ sha256 "99267e8df2ddfdb0e0cc0edf4ef2901dd430cd4569c2c3793ea1d7e8eeeabcd4"
18
18
  license "MIT"
19
19
 
20
20
  depends_on "node"
package/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  [![npm version](https://img.shields.io/npm/v/mcp-ssh-manager.svg?style=flat-square&logo=npm&color=c04500)](https://www.npmjs.com/package/mcp-ssh-manager)
23
23
  [![npm downloads](https://img.shields.io/npm/dm/mcp-ssh-manager.svg?style=flat-square&logo=npm&color=c04500)](https://www.npmjs.com/package/mcp-ssh-manager)
24
- [![Version](https://img.shields.io/badge/release-4.0.2-c04500?style=flat-square)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.0.2)
24
+ [![Version](https://img.shields.io/badge/release-4.1.0-c04500?style=flat-square)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.1.0)
25
25
  [![Claude Code](https://img.shields.io/badge/Claude_Code-Compatible-5A67D8?style=flat-square&logo=anthropic)](https://claude.ai/code)
26
26
  [![OpenAI Codex](https://img.shields.io/badge/OpenAI_Codex-Compatible-00A67E?style=flat-square&logo=openai)](https://openai.com/codex)
27
27
  [![MCP](https://img.shields.io/badge/MCP-Server-orange?style=flat-square)](https://modelcontextprotocol.io)
@@ -54,17 +54,17 @@ An MCP SSH server is the most dangerous tool you can hand an agent: a shell on m
54
54
 
55
55
  ## Choose your workspace
56
56
 
57
- **Desktop application (`4.0.2`):** one installation with its own runtime,
57
+ **Desktop application (`4.1.0`):** one installation with its own runtime,
58
58
  terminal, file browser and server settings. No separate Node.js or npm
59
- installation. [Download it](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.0.2):
59
+ installation. [Download it](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.1.0):
60
60
 
61
61
  | Platform | File | Signature |
62
62
  |---|---|---|
63
63
  | macOS, Apple silicon / Intel | `…-arm64.dmg` / `…-x64.dmg` | **Signed and notarized by Apple** — opens normally |
64
- | Windows x64 / arm64 | `…-setup.exe` | **Not code-signed in 4.0.x.** 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. |
64
+ | 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. |
65
65
  | Linux x64 | `.deb`, `.AppImage` | Unsigned, as Linux packages usually are |
66
66
 
67
- **Already using npm / the CLI?** `npm update -g mcp-ssh-manager` brings 4.0.2,
67
+ **Already using npm / the CLI?** `npm update -g mcp-ssh-manager` brings 4.1.0,
68
68
  and the V4 engine runs without an interface, from your existing `.env`, TOML or
69
69
  process variables — no automatic import, no forced wizard, no approval prompt
70
70
  unless you enable one per server. The one behaviour that tightens is **SSH
@@ -320,7 +320,7 @@ AES-256-GCM, master key in your OS keychain (a `0600` file where there is none
320
320
 
321
321
  - **Your sudo password never reaches the remote command line.** It travels on the SSH channel's stdin, so it isn't visible in `ps`, in `/proc/<pid>/cmdline`, or in an `auditd` trail — unlike the `echo "$pass" | sudo -S` pattern common in this category ([#34](https://github.com/bvisible/mcp-ssh-manager/issues/34)).
322
322
  - **Every shell argument is quoted** through one central helper, with a test that drives **340 builder × argument × payload combinations** through a real shell to prove none of them execute.
323
- - **Read-only SQL is enforced, not suggested.** `ssh_db_query` refuses anything that isn't a `SELECT`.
323
+ - **Read-only SQL is enforced, not suggested.** `ssh_db_query` refuses anything that isn't a `SELECT`, runs it inside a read-only transaction, and never lets the `psql` or `mysql` client read it as a script, where their own commands (`\!`) would reach a shell. A MySQL query is therefore one line, without backslashes.
324
324
  - **Vulnerabilities are published, not buried.** [SECURITY.md](SECURITY.md) has the reporting process and every advisory already fixed — including the six in v3.8.6, among them a command injection on the machine running the server, triggered by any SSH server it connects to.
325
325
  - **Reproducible installs.** The lockfile is committed, CI installs with `npm ci`, and a test enforces that every dependency resolves to registry.npmjs.org with an integrity hash and no unreviewed install scripts.
326
326
 
@@ -399,7 +399,7 @@ See the [Backup Guide](docs/BACKUP_GUIDE.md) and [examples/backup-workflow.md](e
399
399
  | `ssh_db_dump` | MySQL, PostgreSQL, MongoDB; optional gzip, optional table subset |
400
400
  | `ssh_db_import` | Import a dump, `.gz` handled automatically |
401
401
  | `ssh_db_list` | Databases, or the tables inside one |
402
- | `ssh_db_query` | **`SELECT` only** — enforced, not suggested |
402
+ | `ssh_db_query` | **`SELECT` only** — enforced, not suggested (MySQL: one line, no backslash) |
403
403
 
404
404
  **Deployment & sessions**
405
405
 
@@ -508,6 +508,7 @@ SSH_SERVER_[NAME]_HOST=hostname_or_ip
508
508
  SSH_SERVER_[NAME]_USER=username
509
509
  SSH_SERVER_[NAME]_PASSWORD=password # or use a key
510
510
  SSH_SERVER_[NAME]_KEYPATH=~/.ssh/key
511
+ SSH_SERVER_[NAME]_AGENT_PUBLIC_KEY_PATH=~/.ssh/id_ed25519.pub # alternative: select one key from SSH_AUTH_SOCK
511
512
  SSH_SERVER_[NAME]_CERTPATH=~/.ssh/key-cert.pub # optional: OpenSSH certificate for KEYPATH
512
513
  SSH_SERVER_[NAME]_PASSPHRASE=key_passphrase # optional
513
514
  SSH_SERVER_[NAME]_PORT=22 # optional
@@ -552,6 +553,17 @@ user = "admin"
552
553
  proxy_jump = "bastion"
553
554
  ```
554
555
 
556
+ **Selecting an SSH agent key** — use a public key file to select one identity from the existing agent at `SSH_AUTH_SOCK`, including compatible password-manager agents. The private key stays in the agent, which performs signing. For example:
557
+
558
+ ```toml
559
+ [ssh_servers.agent_host]
560
+ host = "example.com"
561
+ user = "admin"
562
+ agent_public_key_path = "~/.ssh/id_ed25519.pub"
563
+ ```
564
+
565
+ The `.env` equivalent is `SSH_SERVER_[NAME]_AGENT_PUBLIC_KEY_PATH`; the internal configuration field is `agentPublicKeyPath`. This option fails if the public key file is missing or invalid, the agent is unavailable, or the agent does not offer a matching identity. It cannot be combined with `key_path`, `password`, `cert_path`, or enabled `forward_agent`; conflicting configuration is rejected. Omitting the option preserves the existing authentication behavior. `ssh_sync` uses system OpenSSH and does not apply this filter: configure its `IdentityFile` and `IdentitiesOnly yes` in your SSH client configuration separately.
566
+
555
567
  **OpenSSH user certificates** — for servers that trust a certificate authority (`TrustedUserCAKeys`), point `CERTPATH` / `cert_path` at the certificate signed for `KEYPATH` (usually `<key>-cert.pub`). It is read on every connection, so a short-lived certificate renewed on disk needs no restart, and a missing file fails the connection instead of falling back to the bare key. It takes effect once `ssh2` ships certificate support ([mscdex/ssh2#1495](https://github.com/mscdex/ssh2/pull/1495)); until then the plain key is offered, as before. `ssh_sync` uses the system `ssh`, which finds `<key>-cert.pub` next to the key on its own.
556
568
 
557
569
  **Loading order**, highest priority first: process environment → `.env` → the encrypted vault → TOML. A credential you deliberately put in the vault beats one left in a `.env`; an operator overriding for a single run still beats both.
@@ -685,6 +697,10 @@ The hero animation ships twice, light and dark, swapped by `<picture>` on `prefe
685
697
 
686
698
  ## What's new
687
699
 
700
+ **[4.1.0](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.1.0) — choose the agent key per server, and sudo in the audit log.** A server can name the one key of your SSH agent it uses, so an agent that holds many keys (a password manager's, say) no longer runs into `MaxAuthTries` before the right one is offered (thanks to @RebornOnce, [#128](https://github.com/bvisible/mcp-ssh-manager/pull/128)); with `AUDIT_LOG` on, `ssh_execute_sudo`, downloads, group commands and commands sent to a session now record what they did, never the sudo password ([#134](https://github.com/bvisible/mcp-ssh-manager/pull/134), thanks to @orshih6, reported by @revert12); [`llms-install.md`](llms-install.md) lets an agent set the server up for you; dependencies refreshed. Nothing to change on upgrade. See the [CHANGELOG](CHANGELOG.md#410---2026-11-13).
701
+
702
+ **[4.0.3](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.0.3) — a security release; upgrade.** `ssh_db_query`, the read-only tool, could run shell commands on the server through the `psql` and `mysql` clients' own commands (`\!`), including on servers in `readonly` or `restricted` mode ([GHSA-qmf5-hrhv-5hjm](https://github.com/bvisible/mcp-ssh-manager/security/advisories/GHSA-qmf5-hrhv-5hjm), reported by @orshih6). Every version before it is affected. A MySQL query must now be one line without backslashes. See the [CHANGELOG](CHANGELOG.md#403---2026-11-05).
703
+
688
704
  **[4.0.2](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.0.2) — commands reach a Mac, and the desktop terminal is your own.** Commands sent to a macOS server no longer fail with `timeout: command not found` before they start (thanks to Henrik Tilly, [#115](https://github.com/bvisible/mcp-ssh-manager/pull/115)); the desktop terminal starts a login shell, so what Homebrew installed is found as in Terminal or Warp, and PowerShell on Windows; keystrokes reach the shell in the order they were typed; dependencies refreshed. Nothing to change on upgrade.
689
705
 
690
706
  **[4.0.1](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.0.1) — the application tells you about updates.** *Options → Updates*, a mark on the sidebar and a notification once per version, so a new release no longer goes unnoticed in a menu you never open; a tidier Servers toolbar; the interface is built when the package is made rather than committed (what you install is byte for byte the same); and the npm, registry and GitHub descriptions say what V4 is. No change to the engine's behaviour.
@@ -730,6 +746,10 @@ Made with ❤️ for the Claude Code community
730
746
 
731
747
  </div>
732
748
 
749
+ ## Also from us
750
+
751
+ **[Relais](https://github.com/bvisible/relais)**: several Claude accounts on one Mac, one workspace. Switch Claude Desktop and Claude Code between your work and personal accounts in one click, keep every conversation, and see each account's limits. Free and open source, for macOS.
752
+
733
753
  ## Validation before a release
734
754
 
735
755
  The [V4 testing guide](docs/TESTING-V4.md) describes the offline suites, real npm
package/brand/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  | `wordmark.svg` | The logo: **ssh** solid, **manager** outlined. Supplied, not derived. |
6
6
  | `icon.svg` | The app icon — the mark on its tile. Everything else is generated from this. |
7
7
  | `mark.svg` | The mark alone, no tile, `currentColor` for the white parts. |
8
+ | `logo-400.png` | The icon at 400×400, for directories that ask for one (the Cline MCP Marketplace). Rendered from `icon.svg`: `qlmanage -t -s 400 -o /tmp brand/icon.svg`. |
8
9
  | `social-preview.html` | The GitHub social preview (1280×640), rendered to `docs/images/social-preview.png` and `@2x` by `npm run brand:social`. The window in it is the README's own capture of the real application (`docs/images/v4-waiting-app.png`, made by the screenshot rig), so the image follows the interface when the rig is re-run. |
9
10
 
10
11
  ## The icon
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "ssh-manager-desktop",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "ssh-manager-desktop",
9
- "version": "4.0.2",
9
+ "version": "4.1.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "electron-updater": "^6.8.9",
@@ -236,23 +236,6 @@
236
236
  "node": ">=16.4"
237
237
  }
238
238
  },
239
- "node_modules/@electron/universal/node_modules/balanced-match": {
240
- "version": "1.0.2",
241
- "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
242
- "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
243
- "dev": true,
244
- "license": "MIT"
245
- },
246
- "node_modules/@electron/universal/node_modules/brace-expansion": {
247
- "version": "2.1.7",
248
- "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz",
249
- "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==",
250
- "dev": true,
251
- "license": "MIT",
252
- "dependencies": {
253
- "balanced-match": "^1.0.0"
254
- }
255
- },
256
239
  "node_modules/@electron/universal/node_modules/fs-extra": {
257
240
  "version": "11.4.0",
258
241
  "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.4.0.tgz",
@@ -268,22 +251,6 @@
268
251
  "node": ">=14.14"
269
252
  }
270
253
  },
271
- "node_modules/@electron/universal/node_modules/minimatch": {
272
- "version": "9.0.9",
273
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz",
274
- "integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==",
275
- "dev": true,
276
- "license": "ISC",
277
- "dependencies": {
278
- "brace-expansion": "^2.0.2"
279
- },
280
- "engines": {
281
- "node": ">=16 || 14 >=14.17"
282
- },
283
- "funding": {
284
- "url": "https://github.com/sponsors/isaacs"
285
- }
286
- },
287
254
  "node_modules/@electron/windows-sign": {
288
255
  "version": "1.2.2",
289
256
  "resolved": "https://registry.npmjs.org/@electron/windows-sign/-/windows-sign-1.2.2.tgz",
@@ -336,6 +303,13 @@
336
303
  "node": ">=18.0.0"
337
304
  }
338
305
  },
306
+ "node_modules/@isaacs/nonrecursive-glob-match": {
307
+ "version": "1.0.3",
308
+ "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.0.3.tgz",
309
+ "integrity": "sha512-SI7kyKHq4XXDRozw+r9GlRZkia1ZkFrpLW98r2IC2Bpr8YkFGE3fvjzmxCG0x78A++69HmDNrDvSMYBZmHGpKA==",
310
+ "dev": true,
311
+ "license": "BlueOak-1.0.0"
312
+ },
339
313
  "node_modules/@malept/cross-spawn-promise": {
340
314
  "version": "2.0.0",
341
315
  "resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-2.0.0.tgz",
@@ -2481,16 +2455,17 @@
2481
2455
  }
2482
2456
  },
2483
2457
  "node_modules/minimatch": {
2484
- "version": "10.2.6",
2485
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz",
2486
- "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==",
2458
+ "version": "11.0.4",
2459
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.4.tgz",
2460
+ "integrity": "sha512-/UJ1dEoVQTjPNDh6SGlUo+ueLMmoHTas4q+8yaAR/5t6nLAIiBDJtoYUh20IYleix7ehiQkgczb84PE3uzHkxg==",
2487
2461
  "dev": true,
2488
2462
  "license": "BlueOak-1.0.0",
2489
2463
  "dependencies": {
2490
- "brace-expansion": "^5.0.8"
2464
+ "@isaacs/nonrecursive-glob-match": "^1.0.3",
2465
+ "brace-expansion": "^5.0.12"
2491
2466
  },
2492
2467
  "engines": {
2493
- "node": "18 || 20 || >=22"
2468
+ "node": "20 || >=22"
2494
2469
  },
2495
2470
  "funding": {
2496
2471
  "url": "https://github.com/sponsors/isaacs"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ssh-manager-desktop",
3
3
  "productName": "SSH Manager",
4
- "version": "4.0.2",
4
+ "version": "4.1.0",
5
5
  "private": true,
6
6
  "description": "The SSH Manager control plane as a desktop application",
7
7
  "main": "main.js",
@@ -26,5 +26,8 @@
26
26
  "electron-updater": "^6.8.9",
27
27
  "node-pty": "^1.1.0"
28
28
  },
29
+ "overrides": {
30
+ "minimatch@>=7.0.0 <11.0.1": "^11.0.1"
31
+ },
29
32
  "homepage": "https://github.com/bvisible/mcp-ssh-manager"
30
33
  }
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.0.2 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.0.2)).
3
+ **4.0 is released, on npm and as a desktop application**; the latest is 4.1.0 ([release](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v4.1.0)).
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
@@ -0,0 +1,97 @@
1
+ # Installing MCP SSH Manager — instructions for AI agents
2
+
3
+ These steps let an AI agent (Cline or any MCP client) set up this server for its
4
+ user. Follow them in order. Ask the user for anything you do not know; never
5
+ guess a host, a user name or a key.
6
+
7
+ ## 1. Check Node.js
8
+
9
+ ```bash
10
+ node --version
11
+ ```
12
+
13
+ Version 18 or later is required. If Node is missing or older, ask the user to
14
+ install a current LTS from https://nodejs.org before going on.
15
+
16
+ ## 2. Register the server with the MCP client
17
+
18
+ The server speaks MCP over stdio. Add this entry to the client's MCP settings
19
+ (for Cline: `cline_mcp_settings.json`, opened from *MCP Servers → Configure*):
20
+
21
+ ```json
22
+ {
23
+ "mcpServers": {
24
+ "ssh-manager": {
25
+ "command": "npx",
26
+ "args": ["-y", "mcp-ssh-manager"]
27
+ }
28
+ }
29
+ }
30
+ ```
31
+
32
+ `npx` downloads the published package on first use; nothing else needs to be
33
+ installed. A user who prefers a global install can run
34
+ `npm install -g mcp-ssh-manager` and use `"command": "mcp-ssh-manager"` with no
35
+ `args` instead.
36
+
37
+ ## 3. Describe the user's servers
38
+
39
+ Servers are read from `~/.ssh-manager/.env` (on Windows,
40
+ `%USERPROFILE%\.ssh-manager\.env`). Ask the user, for each server: a short name,
41
+ the host, the SSH user, the port if it is not 22, and the path of the private key
42
+ they use for it. Then create the directory and the file:
43
+
44
+ ```bash
45
+ mkdir -p ~/.ssh-manager
46
+ touch ~/.ssh-manager/.env
47
+ chmod 600 ~/.ssh-manager/.env
48
+ ```
49
+
50
+ Append one block per server. The name is the part between `SSH_SERVER_` and the
51
+ field, in capitals, with letters, digits and underscores only; the tools refer to
52
+ it in lower case (`PRODUCTION` below is `production`).
53
+
54
+ ```env
55
+ SSH_SERVER_PRODUCTION_HOST=203.0.113.10
56
+ SSH_SERVER_PRODUCTION_USER=deploy
57
+ SSH_SERVER_PRODUCTION_KEYPATH=~/.ssh/id_ed25519
58
+ SSH_SERVER_PRODUCTION_PORT=22
59
+ ```
60
+
61
+ Rules that matter:
62
+
63
+ - **Prefer a key.** Do not ask the user to type a password or a key passphrase
64
+ into the conversation. If a server only accepts a password, tell the user to
65
+ add `SSH_SERVER_<NAME>_PASSWORD=...` to the file themselves, or to run
66
+ `npx -y -p mcp-ssh-manager ssh-manager server add`, which asks for it in their
67
+ own terminal.
68
+ - **Offer a safety mode** for servers that matter. `SSH_SERVER_<NAME>_MODE=readonly`
69
+ refuses every tool that changes the server; `restricted` allows only commands
70
+ matching `SSH_SERVER_<NAME>_ALLOW_PATTERNS`. The default, `unrestricted`, allows
71
+ everything. See `docs/SECURITY_MODES.md`.
72
+ - **Do not overwrite** an existing `~/.ssh-manager/.env`: it may already hold the
73
+ user's servers. Append to it, and leave existing blocks as they are.
74
+
75
+ The first connection to a host records its key in `~/.ssh/known_hosts` (trust on
76
+ first use); later connections are refused if the key changes.
77
+
78
+ ## 4. Restart and check
79
+
80
+ Restart the MCP server in the client (for Cline: the restart button next to
81
+ `ssh-manager` in *MCP Servers*) so it reads the file, then:
82
+
83
+ 1. Call `ssh_list_servers`. Each server written above must be listed.
84
+ 2. Call `ssh_execute` with `{"server": "production", "command": "uptime"}` (use
85
+ the user's server name). A result with an exit code of 0 means the setup works.
86
+
87
+ If the server is missing from the list, check the variable names in the file. If
88
+ the connection is refused, check the key path, the user name and the port with the
89
+ user; `Permission denied` usually means the key is not authorised on the server.
90
+
91
+ ## Optional
92
+
93
+ - **Desktop application**: the same engine with an interface (approvals, live
94
+ output, a terminal, a file browser), no Node.js needed. Downloads:
95
+ https://github.com/bvisible/mcp-ssh-manager/releases/latest
96
+ - **Credentials in an encrypted vault** instead of the `.env`, and the full list of
97
+ options (jump hosts, groups, sudo, TOML configuration): see the `README.md`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
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: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: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: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: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",
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: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: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",
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",
@@ -28,10 +28,12 @@
28
28
  "test:hooks": "node tests/test-hooks.js",
29
29
  "test:tools": "node tests/test-tool-registry.js",
30
30
  "test:policy": "node tests/test-policy.js",
31
+ "test:auditsuccess": "node tests/test-audit-success.js",
31
32
  "test:ping": "node tests/test-ssh-ping.js",
32
33
  "test:config": "node tests/test-server-config-manager.js",
33
34
  "test:fieldnames": "node tests/test-config-field-names.js",
34
35
  "test:groups": "node tests/test-server-groups.js",
36
+ "test:agentkey": "node --test tests/test-agent-key-selection.js tests/test-agent-key-selection-integration.js tests/test-agent-key-config.js tests/test-agent-openssh.js",
35
37
  "test:agentforward": "node tests/test-agent-forward.js",
36
38
  "test:certpath": "node tests/test-cert-path.js",
37
39
  "test:agentannounce": "node tests/test-agent-announce.js",
@@ -46,6 +48,7 @@
46
48
  "test:quoteprops": "node tests/test-shell-quote-properties.js",
47
49
  "test:backupinjection": "node tests/test-backup-monitor-injection.js",
48
50
  "test:dbrowcount": "node tests/test-database-row-count.js",
51
+ "test:dbclientcmds": "node tests/test-db-client-commands.js",
49
52
  "test:timeoutwrap": "node tests/test-timeout-wrapper.js",
50
53
  "test:cli-edit": "node tests/test-cli-edit-server.js",
51
54
  "test:all": "npm test && npm run typecheck && ./scripts/validate.sh",
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Check that every action a workflow pins by SHA is pinned to a commit of that
4
+ * action's own repository.
5
+ *
6
+ * Two ways a pin can look right and be wrong:
7
+ *
8
+ * - the SHA of an annotated tag object instead of the commit it points to.
9
+ * GitHub Actions runs it, but OpenSSF Scorecard refuses to publish results
10
+ * from such a workflow ("imposter commit"), and from 2026-08-28 to 2026-11-09
11
+ * the Scorecard results of this repository were never published because of
12
+ * one, with every run green.
13
+ * - a commit from a fork. GitHub resolves those through the parent repository,
14
+ * which is how an "imposter commit" smuggles code in under a trusted name.
15
+ *
16
+ * Asks the GitHub API (GITHUB_TOKEN or GH_TOKEN when set) whether
17
+ * repos/<owner>/<repo>/commits/<sha> exists. Exits 1 on any pin that is not one.
18
+ *
19
+ * node scripts/check-action-pins.mjs [workflow files…] (default: .github/workflows/*.yml)
20
+ */
21
+ import fs from 'node:fs';
22
+ import path from 'node:path';
23
+
24
+ const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..');
25
+ const files = process.argv.slice(2).length
26
+ ? process.argv.slice(2)
27
+ : fs.readdirSync(path.join(root, '.github', 'workflows')).filter(name => /\.ya?ml$/.test(name))
28
+ .map(name => path.join(root, '.github', 'workflows', name));
29
+
30
+ const pins = new Map();
31
+ for (const file of files) {
32
+ for (const match of fs.readFileSync(file, 'utf8').matchAll(/uses:\s*([\w.-]+\/[\w.-]+)(?:\/[\w./-]+)?@([0-9a-f]{40})/g)) {
33
+ const key = `${match[1]}@${match[2]}`;
34
+ if (!pins.has(key)) pins.set(key, []);
35
+ pins.get(key).push(path.relative(root, file));
36
+ }
37
+ }
38
+
39
+ const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
40
+ const headers = { accept: 'application/vnd.github+json', 'user-agent': 'mcp-ssh-manager-pin-check', ...(token ? { authorization: `Bearer ${token}` } : {}) };
41
+ let bad = 0;
42
+ for (const [key, where] of pins) {
43
+ const [repo, sha] = key.split('@');
44
+ const response = await fetch(`https://api.github.com/repos/${repo}/commits/${sha}`, { headers });
45
+ if (response.ok) {
46
+ console.log(`ok ${repo}@${sha.slice(0, 12)}`);
47
+ continue;
48
+ }
49
+ bad++;
50
+ const tag = await fetch(`https://api.github.com/repos/${repo}/git/tags/${sha}`, { headers });
51
+ const reason = tag.ok
52
+ ? `the SHA of a tag object; pin the commit it points to, ${(await tag.json()).object.sha}`
53
+ : `not a commit of ${repo} (HTTP ${response.status})`;
54
+ console.log(`FAIL ${repo}@${sha.slice(0, 12)} in ${where.join(', ')}: ${reason}`);
55
+ }
56
+ console.log(bad ? `\n${bad} pinned action(s) do not point to a commit of their repository` : `\nall ${pins.size} pinned actions point to commits of their repositories`);
57
+ process.exit(bad ? 1 : 0);
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.0.2",
9
+ "version": "4.1.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "mcp-ssh-manager",
14
- "version": "4.0.2",
14
+ "version": "4.1.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -25,6 +25,7 @@ import { resolveConfigOptions } from './config-paths.js';
25
25
  * @property {string} [user] SSH user.
26
26
  * @property {string} [password] Password for password authentication.
27
27
  * @property {string} [keyPath] Path to the private key (`KEYPATH` / `key_path`).
28
+ * @property {string} [agentPublicKeyPath] Public key selecting one SSH Agent identity (`AGENT_PUBLIC_KEY_PATH` / `agent_public_key_path`).
28
29
  * @property {string} [certPath] OpenSSH user certificate for keyPath (`CERTPATH` / `cert_path`).
29
30
  * @property {string} [passphrase] Passphrase for a protected private key.
30
31
  * @property {number} [port] TCP port; defaults to 22.
@@ -266,6 +267,7 @@ export class ConfigLoader {
266
267
  password: serverConfig.password,
267
268
  keyPath: serverConfig.key_path || serverConfig.keypath || serverConfig.ssh_key,
268
269
  certPath: serverConfig.cert_path,
270
+ agentPublicKeyPath: serverConfig.agent_public_key_path,
269
271
  passphrase: serverConfig.passphrase,
270
272
  port: serverConfig.port || 22,
271
273
  defaultDir: serverConfig.default_dir || serverConfig.default_directory || serverConfig.cwd,
@@ -344,6 +346,7 @@ export class ConfigLoader {
344
346
  password: env[`SSH_SERVER_${match[1]}_PASSWORD`],
345
347
  keyPath: env[`SSH_SERVER_${match[1]}_KEYPATH`],
346
348
  certPath: env[`SSH_SERVER_${match[1]}_CERTPATH`],
349
+ agentPublicKeyPath: env[`SSH_SERVER_${match[1]}_AGENT_PUBLIC_KEY_PATH`],
347
350
  passphrase: env[`SSH_SERVER_${match[1]}_PASSPHRASE`],
348
351
  port: parseInt(env[`SSH_SERVER_${match[1]}_PORT`] || '22'),
349
352
  defaultDir: env[`SSH_SERVER_${match[1]}_DEFAULT_DIR`],
@@ -429,6 +432,7 @@ export class ConfigLoader {
429
432
  if (server.password) serverConfig.password = server.password;
430
433
  if (server.keyPath) serverConfig.key_path = server.keyPath;
431
434
  if (server.certPath) serverConfig.cert_path = server.certPath;
435
+ if (server.agentPublicKeyPath) serverConfig.agent_public_key_path = server.agentPublicKeyPath;
432
436
  if (server.passphrase) serverConfig.passphrase = server.passphrase;
433
437
  if (server.defaultDir) serverConfig.default_dir = server.defaultDir;
434
438
  if (server.sudoPassword) serverConfig.sudo_password = server.sudoPassword;
@@ -475,6 +479,7 @@ export class ConfigLoader {
475
479
  if (server.password) lines.push(`SSH_SERVER_${upperName}_PASSWORD="${server.password}"`);
476
480
  if (server.keyPath) lines.push(`SSH_SERVER_${upperName}_KEYPATH=${server.keyPath}`);
477
481
  if (server.certPath) lines.push(`SSH_SERVER_${upperName}_CERTPATH=${server.certPath}`);
482
+ if (server.agentPublicKeyPath) lines.push(`SSH_SERVER_${upperName}_AGENT_PUBLIC_KEY_PATH=${server.agentPublicKeyPath}`);
478
483
  if (server.passphrase) lines.push(`SSH_SERVER_${upperName}_PASSPHRASE="${server.passphrase}"`);
479
484
  lines.push(`SSH_SERVER_${upperName}_PORT=${server.port || 22}`);
480
485
  if (server.defaultDir) lines.push(`SSH_SERVER_${upperName}_DEFAULT_DIR=${server.defaultDir}`);
@@ -393,7 +393,8 @@ export function buildMySQLQueryCommand(options) {
393
393
  if (!isSafeQuery(query)) {
394
394
  throw new Error('Only SELECT queries are allowed');
395
395
  }
396
- const script = readOnlyScript(DB_TYPES.MYSQL, query);
396
+ assertNoMySQLClientCommands(query);
397
+ const script = readOnlyScript(query);
397
398
 
398
399
  let command = 'mysql';
399
400
  if (user) command += ` -u${shellQuote(user)}`;
@@ -439,9 +440,17 @@ export function buildPostgreSQLQueryCommand(options) {
439
440
  if (host) command += ` -h ${shellQuote(host)}`;
440
441
  if (port) command += ` -p ${shellQuote(port)}`;
441
442
  command += ` -d ${shellQuote(database)}`;
442
- // Feed SQL via stdin (quoted heredoc) instead of `-c "${query}"` so the remote shell
443
- // never parses it. See buildHeredoc and issue #44.
444
- command += buildHeredoc(readOnlyScript(DB_TYPES.POSTGRESQL, query));
443
+ // Each statement is a single-quoted `-c` argument, never psql's input. psql runs
444
+ // the backslash commands of a script it reads (`\!` runs a shell command, `\o |cmd`
445
+ // pipes to one) wherever they appear, so a query fed on stdin could leave the
446
+ // database for the shell (GHSA-qmf5-hrhv-5hjm). A `-c` that does not start with a
447
+ // backslash goes to the server as it is. Three of them, not one: psql before 15
448
+ // prints only the last result of a multi-statement `-c`, here the ROLLBACK.
449
+ // shellQuote, not double quotes, so the remote shell parses nothing (issue #44).
450
+ const statement = query.trim().replace(/;\s*$/, '');
451
+ command += ` -c ${shellQuote('BEGIN TRANSACTION READ ONLY')}`;
452
+ command += ` -c ${shellQuote(statement)}`;
453
+ command += ` -c ${shellQuote('ROLLBACK')}`;
445
454
 
446
455
  return command;
447
456
  }
@@ -656,17 +665,38 @@ export function isSafeQuery(query) {
656
665
  }
657
666
 
658
667
  /**
659
- * The SQL fed to the client: the query inside a read-only transaction. The
660
- * database then refuses any write the query would make, including one hidden
661
- * in a function it calls (MySQL 5.6.5+, MariaDB 10.0+, every PostgreSQL).
662
- * @param {string} type - DB_TYPES.MYSQL or DB_TYPES.POSTGRESQL
668
+ * Refuse what the mysql client would take for one of its own commands.
669
+ *
670
+ * The query reaches the remote `mysql` client as its input, and the client acts
671
+ * on backslash commands anywhere in a line (`\!` runs a shell command) and on
672
+ * named ones at the start of a line (`system`, `source`, `tee`), in batch mode and
673
+ * with `-e` alike, before the database sees anything (GHSA-qmf5-hrhv-5hjm). There
674
+ * is no option every client accepts to turn this off (MariaDB has `--sandbox`,
675
+ * MySQL 8.0.40+ `--system-command=OFF`, older clients reject both), so the query
676
+ * may contain neither a backslash nor a line break, nor any other control
677
+ * character. A read-only SELECT needs none of them.
678
+ *
679
+ * @param {string} query - A query that passed isSafeQuery
680
+ * @throws {Error} When the query contains a backslash or a control character
681
+ */
682
+ export function assertNoMySQLClientCommands(query) {
683
+ const statement = query.trim();
684
+ // eslint-disable-next-line no-control-regex
685
+ if (/[\\\x00-\x08\x0a-\x1f\x7f]/.test(statement)) {
686
+ throw new Error('MySQL queries must be one line without backslashes: the mysql client runs commands such as \\! (shell) found in its input');
687
+ }
688
+ }
689
+
690
+ /**
691
+ * The SQL fed to the mysql client: the query inside a read-only transaction.
692
+ * The database then refuses any write the query would make, including one
693
+ * hidden in a function it calls (MySQL 5.6.5+, MariaDB 10.0+). PostgreSQL gets
694
+ * the same transaction from separate `-c` arguments (buildPostgreSQLQueryCommand).
663
695
  * @param {string} query - A query that passed isSafeQuery
664
696
  */
665
- function readOnlyScript(type, query) {
697
+ function readOnlyScript(query) {
666
698
  const statement = query.trim().replace(/;\s*$/, '');
667
- return type === DB_TYPES.MYSQL
668
- ? `SET SESSION TRANSACTION READ ONLY;\n${statement};`
669
- : `BEGIN TRANSACTION READ ONLY;\n${statement};\nROLLBACK;`;
699
+ return `SET SESSION TRANSACTION READ ONLY;\n${statement};`;
670
700
  }
671
701
 
672
702
  /**
@@ -0,0 +1,53 @@
1
+ // Select one public identity while the original agent retains the private key
2
+ // and handles signing and any user authorization prompts.
3
+ import ssh2 from 'ssh2';
4
+ const { BaseAgent, utils } = ssh2;
5
+
6
+ /** @param {any} value @returns {Buffer} */
7
+ function publicBytes(value) {
8
+ const key = value && typeof value.getPublicSSH === 'function'
9
+ ? value : utils.parseKey(value);
10
+ if (key instanceof Error) throw key;
11
+ if (!key || Array.isArray(key)) throw new Error('Expected one SSH public key');
12
+ return key.getPublicSSH();
13
+ }
14
+
15
+ export class FilteredAgent extends BaseAgent {
16
+ /** @param {import('ssh2').BaseAgent} delegate @param {Buffer} publicKey */
17
+ constructor(delegate, publicKey) {
18
+ super();
19
+ this.delegate = delegate;
20
+ this.allowedKey = publicBytes(publicKey);
21
+ }
22
+
23
+ /** @param {function} callback */
24
+ getIdentities(callback) {
25
+ this.delegate.getIdentities((error, keys) => {
26
+ if (error) return callback(error);
27
+ let selected;
28
+ try {
29
+ selected = keys.find(key => publicBytes(key).equals(this.allowedKey));
30
+ if (!selected) throw new Error('Configured public key is not available in SSH Agent');
31
+ } catch (error) {
32
+ return callback(error);
33
+ }
34
+ callback(null, [selected]);
35
+ });
36
+ }
37
+
38
+ /** @param {any} publicKey @param {Buffer} data @param {any} options @param {function} [callback] */
39
+ sign(publicKey, data, options, callback) {
40
+ if (typeof options === 'function') {
41
+ callback = options;
42
+ options = undefined;
43
+ }
44
+ try {
45
+ if (!publicBytes(publicKey).equals(this.allowedKey)) {
46
+ throw new Error('SSH Agent signing identity does not match configured public key');
47
+ }
48
+ } catch (error) {
49
+ return callback(error);
50
+ }
51
+ this.delegate.sign(publicKey, data, options, callback);
52
+ }
53
+ }
package/src/index.js CHANGED
@@ -887,6 +887,8 @@ registerToolConditional(
887
887
  duration: `${Date.now() - startTime}ms`
888
888
  });
889
889
 
890
+ await auditOk(serverName, 'ssh_download', { remotePath, localPath }, { success: true });
891
+
890
892
  return {
891
893
  content: [
892
894
  {
@@ -896,6 +898,10 @@ registerToolConditional(
896
898
  ],
897
899
  };
898
900
  } catch (error) {
901
+ await auditOk(serverName, 'ssh_download', { remotePath, localPath }, {
902
+ success: false,
903
+ error: error.message,
904
+ });
899
905
  logger.logTransfer('download', serverName, remotePath, localPath, {
900
906
  success: false,
901
907
  error: error.message
@@ -1701,6 +1707,9 @@ registerToolConditional(
1701
1707
  }
1702
1708
  },
1703
1709
  async ({ session: sessionId, command, timeout = 30000 }) => {
1710
+ // Set once the policy allowed the command, so a failure after that point is
1711
+ // audited as well.
1712
+ let auditServer = null;
1704
1713
  try {
1705
1714
  const session = getSession(sessionId);
1706
1715
  const currentConfig = await getServerConfig(session.serverName);
@@ -1712,11 +1721,16 @@ registerToolConditional(
1712
1721
  // Resolve the session's underlying server to its policy.
1713
1722
  const denied = await applyServerPolicy(session.serverName, 'ssh_session_send', { session: sessionId, command }, command);
1714
1723
  if (denied) return denied;
1724
+ auditServer = session.serverName;
1715
1725
 
1716
1726
  const startTime = Date.now();
1717
1727
  const result = await session.execute(command, { timeout });
1718
1728
  const duration = Date.now() - startTime;
1719
1729
 
1730
+ await auditOk(session.serverName, 'ssh_session_send', { session: sessionId, command }, {
1731
+ success: result.success,
1732
+ });
1733
+
1720
1734
  logger.info('Session command executed', {
1721
1735
  session: sessionId,
1722
1736
  command: command.substring(0, 50),
@@ -1751,6 +1765,12 @@ registerToolConditional(
1751
1765
  ]
1752
1766
  };
1753
1767
  } catch (error) {
1768
+ if (auditServer) {
1769
+ await auditOk(auditServer, 'ssh_session_send', { session: sessionId, command }, {
1770
+ success: false,
1771
+ error: error.message,
1772
+ });
1773
+ }
1754
1774
  logger.error('Failed to send command to session', {
1755
1775
  session: sessionId,
1756
1776
  command,
@@ -1981,6 +2001,10 @@ registerToolConditional(
1981
2001
  }
1982
2002
 
1983
2003
  const execResult = await execCommandWithTimeout(ssh, fullCommand, { platform }, 30000);
2004
+ await auditOk(serverName, 'ssh_execute_group', { group: groupName, command, cwd }, {
2005
+ code: execResult.code,
2006
+ success: execResult.code === 0,
2007
+ });
1984
2008
 
1985
2009
  return {
1986
2010
  stdout: execResult.stdout,
@@ -2433,6 +2457,11 @@ registerToolConditional(
2433
2457
  // response format is unchanged for existing callers.
2434
2458
  const maskedCommand = fullCommand;
2435
2459
 
2460
+ await auditOk(server, 'ssh_execute_sudo', { command, cwd }, {
2461
+ code: result.code,
2462
+ success: result.code === 0,
2463
+ });
2464
+
2436
2465
  return {
2437
2466
  content: [
2438
2467
  {
@@ -2442,6 +2471,10 @@ registerToolConditional(
2442
2471
  ],
2443
2472
  };
2444
2473
  } catch (error) {
2474
+ await auditOk(server, 'ssh_execute_sudo', { command, cwd }, {
2475
+ success: false,
2476
+ error: error.message,
2477
+ });
2445
2478
  return {
2446
2479
  content: [
2447
2480
  {
@@ -1,4 +1,5 @@
1
- import { Client } from 'ssh2';
1
+ import { Client, createAgent } from 'ssh2';
2
+ import { FilteredAgent } from './filtered-agent.js';
2
3
  import fs from 'fs';
3
4
  import { trustedHostKeyAlgorithms, verifyHostKey } from './ssh-key-manager.js';
4
5
  import { logger } from './logger.js';
@@ -171,9 +172,26 @@ class SSHManager {
171
172
  };
172
173
  }
173
174
 
175
+ // An explicitly selected Agent identity must not silently fall back to
176
+ // another credential or forward the unfiltered Agent to a remote host.
177
+ if (this.config.agentPublicKeyPath) {
178
+ if (this.config.keyPath || this.config.keypath || this.config.password || this.config.certPath) {
179
+ throw new Error('agent_public_key_path cannot be combined with key_path, password or cert_path');
180
+ }
181
+ if (this.config.forwardAgent) {
182
+ throw new Error('agent_public_key_path cannot be combined with forward_agent');
183
+ }
184
+ if (!process.env.SSH_AUTH_SOCK) {
185
+ throw new Error('agent_public_key_path requires SSH_AUTH_SOCK');
186
+ }
187
+ }
188
+
174
189
  // Use ssh-agent if available (handles passphrase-protected keys transparently)
175
190
  if (process.env.SSH_AUTH_SOCK) {
176
- connConfig.agent = process.env.SSH_AUTH_SOCK;
191
+ connConfig.agent = this.config.agentPublicKeyPath
192
+ ? new FilteredAgent(createAgent(process.env.SSH_AUTH_SOCK),
193
+ fs.readFileSync(expandHomePath(this.config.agentPublicKeyPath)))
194
+ : process.env.SSH_AUTH_SOCK;
177
195
  // Opt-in per-server agent forwarding. ssh2 requires `agent` to be set,
178
196
  // so we only enable it inside this block — otherwise ssh2 throws at
179
197
  // connect. With allowAgentFwd on, every exec/shell channel forwards the