mcp-ssh-manager 3.8.0 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,49 @@ All notable changes to MCP SSH Manager will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.8.2] - 2026-08-28
9
+
10
+ ### Security
11
+
12
+ - **The sudo password no longer reaches the remote command line** ([#34](https://github.com/bvisible/mcp-ssh-manager/issues/34)). `ssh_execute_sudo` and the three privileged steps of `ssh_deploy` built `echo "<password>" | sudo -S <cmd>`, which published the password to the remote process list, `/proc/<pid>/cmdline` and any `auditd` trail for the lifetime of the `echo` — readable by every account on the host. The existing output masking never helped: it only redacted the copy sent back to the agent. The password now travels on the SSH exec channel's stdin (`sudo -S -k -p ''`), where no other process can observe it. `-k` is required: without it an already-authorised sudo skips the prompt, leaving the password in the pipe for the command itself to read as input. Guarded by `npm run test:sudostdin`, which also fails if the old pipeline reappears anywhere in `src/`.
13
+
14
+ ### Added
15
+
16
+ - **`server.json`** — the manifest for the official [MCP Registry](https://registry.modelcontextprotocol.io), published as `io.github.bvisible/mcp-ssh-manager`, plus the `mcpName` field in `package.json` that proves package ownership. The registry is what feeds MCP clients today; the project was absent from it.
17
+ - **OpenSSF Scorecard workflow and badge** — a public grade of the repository's supply-chain posture. For a server that hands an agent a shell on production machines, that grade is part of the product.
18
+ - **`Release` workflow** publishing to npm with build provenance and attaching a CycloneDX SBOM to each GitHub release. Removes the hand-publish step that failed twice on 2026-08-28 (expired token, then a 2FA prompt), and lets anyone verify the tarball's origin with `npm audit signatures`.
19
+ - **README section "Giving an agent SSH access, safely"** documenting the per-server `unrestricted` / `readonly` / `restricted` modes, which existed since v3.5.0 but were never surfaced where readers land.
20
+
21
+ ### Fixed
22
+
23
+ - `SSHManager.execCommand` accepts an `stdin` option, written to the exec channel and then closed. Commands that pass no stdin are untouched, so interactive remote processes keep working.
24
+
25
+ ## [3.8.1] - 2026-08-28
26
+
27
+ ### Added
28
+
29
+ - **`package-lock.json` is now committed** (contributed by @cudatuda in #60) — installs are reproducible, `npm ci` works, and the transitive tree is auditable. npm excludes lockfiles from published tarballs, so consumers of the package are unaffected.
30
+ - **`npm run test:lockfile`** (`tests/test-lockfile.js`, wired into `npm test`) — guards the lockfile against the ways it rots: version drift between `package.json` and the lockfile's two version fields, dependency ranges out of sync, a locked version outside its declared range, packages resolved from anywhere but registry.npmjs.org, missing integrity hashes, `file:`/`git+`/`link:` entries, unreviewed install scripts, and runtime dependencies requiring a newer Node than `engines.node` advertises.
31
+ - **Node 22.x added to the CI test matrix** — `engines` claims `>=18` and 22 is the active LTS.
32
+ - **`.github/dependabot.yml`** — a pinned tree stops receiving upstream fixes on its own, so monthly grouped dependency updates (capped at 3 open PRs) act as the counterweight. GitHub Actions versions are tracked too.
33
+ - **Advisory `npm audit --omit=dev --audit-level=high` step** in the `Code Quality` workflow. Not a required check: a CVE published against a transitive dependency should be visible without blocking unrelated merges.
34
+
35
+ ### Changed
36
+
37
+ - **CI installs with `npm ci` instead of `npm install`** in both workflows. `npm ci` reproduces the locked tree exactly and aborts if `package.json` and the lockfile have drifted.
38
+ - **ESLint and the JSDoc typecheck are now blocking**, and moved into the `lint` job — one of the three required status checks on `main`. They previously lived in the advisory `Code Quality` workflow, where ESLint additionally ran with `continue-on-error: true`, so neither gate could ever fail a pull request.
39
+ - **Node module caching now works.** `Code Quality` keyed its cache on `hashFiles('**/package-lock.json')` while the lockfile was gitignored, so every run shared one degenerate key. Replaced by `actions/setup-node@v4`'s built-in `cache: 'npm'`.
40
+ - GitHub Actions bumped from `actions/checkout@v3` / `actions/setup-node@v3` / `actions/cache@v3` to v4.
41
+
42
+ ### Removed
43
+
44
+ - **`npm install --save-dev eslint prettier` from the `Code Quality` workflow** — it re-resolved both packages to their latest majors on every run (ESLint 9 over the pinned `^8.56.0`) and rewrote `package.json` in the CI workspace, defeating the pinning it ran next to.
45
+ - Redundant CI steps re-running `test-profiles.js`, `test-command-aliases.js` and `test-hooks.js` individually after `npm test` had already run them.
46
+
47
+ ### Fixed
48
+
49
+ - `mcp-ssh-manager-setup.md`: the two `.gitignore` templates no longer tell readers to ignore `package-lock.json`.
50
+
8
51
  ## [3.8.0] - 2026-08-14
9
52
 
10
53
  ### Security
package/CLAUDE.md CHANGED
@@ -69,6 +69,7 @@ See [docs/TOOL_MANAGEMENT.md](docs/TOOL_MANAGEMENT.md) for complete guide.
69
69
 
70
70
  ### Development and Testing
71
71
  ```bash
72
+ npm ci # Install the exact tree from package-lock.json
72
73
  npm start # Start MCP server (requires stdin)
73
74
  npm test # Run the full test suite
74
75
  npm run typecheck # Type-check JSDoc with tsc (no build, nothing emitted)
@@ -84,6 +85,27 @@ The baseline is 0 errors and CI enforces it, so add JSDoc annotations (or a narr
84
85
  `/** @type {...} */` cast) rather than leaving new errors. `typescript` is pinned to `^6`
85
86
  because knip 5 declares `peer typescript ">=5.0.4 <7"` — bumping one requires bumping the other.
86
87
 
88
+ **Lockfile**: `package-lock.json` is committed and CI installs with `npm ci`, so the tree is
89
+ reproducible and auditable. npm never ships a lockfile inside a published tarball, so this is
90
+ invisible to consumers of the package. Two consequences for maintainers:
91
+
92
+ - **Releases bump three version spots, not one**: `package.json`, `package-lock.json`
93
+ (`.version` *and* `.packages[""].version`) and the README badge. `npm version <x.y.z>` does
94
+ the first two together; a hand edit does not. `npm run test:lockfile` fails when they diverge,
95
+ and so does `npm ci`.
96
+ - **Dependency changes must commit the regenerated lockfile.** After editing `package.json` by
97
+ hand, run `npm install --package-lock-only` and commit both files.
98
+
99
+ `tests/test-lockfile.js` guards the rest: every package resolves to registry.npmjs.org with an
100
+ integrity hash, no `file:`/`git+`/`link:` entries, install scripts limited to a reviewed
101
+ allowlist (`ssh2`, `cpu-features`), and no runtime dependency requiring a newer Node than
102
+ `engines.node` advertises — that last check carries one documented exception,
103
+ `@hono/node-server` (needs Node >=20, pulled by the MCP SDK for its HTTP transport, never
104
+ imported by the stdio server we ship; re-check it when bumping the SDK).
105
+
106
+ **Required status checks on `main`** are `lint`, `test (18.x)` and `test (20.x)`. Renaming those
107
+ jobs or dropping a matrix entry makes `main` unmergeable until branch protection is updated.
108
+
87
109
  ### Debug Tools (in `debug/` directory)
88
110
  ```bash
89
111
  ./debug/test-claude-code.sh # Test Claude Code integration
package/CONTRIBUTING.md CHANGED
@@ -36,6 +36,7 @@ Enhancement suggestions are tracked as GitHub issues. When creating an enhanceme
36
36
  3. Ensure the test suite passes
37
37
  4. Make sure your code follows the existing code style
38
38
  5. Write a clear commit message
39
+ 6. Commit `package-lock.json` if you touched dependencies
39
40
 
40
41
  ## Development Process
41
42
 
@@ -47,10 +48,21 @@ Enhancement suggestions are tracked as GitHub issues. When creating an enhanceme
47
48
 
48
49
  2. Install dependencies:
49
50
  ```bash
50
- npm install
51
+ npm ci # exact versions from package-lock.json
51
52
  pip install -r tools/requirements.txt
52
53
  ```
53
54
 
55
+ `package-lock.json` is committed. Use `npm ci` to install: it reproduces the
56
+ exact tree CI uses and fails loudly if the lockfile and `package.json` have
57
+ drifted apart. If you add, remove or bump a dependency, commit the updated
58
+ lockfile alongside `package.json` — `npm run test:lockfile` checks the two
59
+ stay in sync.
60
+
61
+ The lockfile was generated with npm 11. Older npm reformats it (key order,
62
+ the `libc` field) and produces a huge diff even when no version changes —
63
+ if your diff is thousands of lines but `npm run test:lockfile` still passes,
64
+ that is what happened; drop the reformat and keep only real version changes.
65
+
54
66
  3. Create a branch:
55
67
  ```bash
56
68
  git checkout -b feature/your-feature-name
@@ -95,10 +107,14 @@ Enhancement suggestions are tracked as GitHub issues. When creating an enhanceme
95
107
 
96
108
  Before submitting a pull request:
97
109
 
98
- 1. Test your changes manually
99
- 2. Ensure existing functionality still works
100
- 3. Test with different server configurations
101
- 4. Verify Claude Code integration works
110
+ 1. Run `npm run test:all` (test suite + typecheck + validation script)
111
+ 2. Test your changes manually
112
+ 3. Ensure existing functionality still works
113
+ 4. Test with different server configurations
114
+ 5. Verify Claude Code integration works
115
+
116
+ CI installs with `npm ci` on Node 18, 20 and 22, and the `lint` job runs
117
+ ESLint and the JSDoc typecheck as blocking gates.
102
118
 
103
119
  ## Documentation
104
120
 
package/README.md CHANGED
@@ -6,10 +6,11 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
8
8
  [![npm downloads](https://img.shields.io/npm/dt/mcp-ssh-manager.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/mcp-ssh-manager)
9
- [![Version](https://img.shields.io/badge/Version-3.8.0-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.8.0)
9
+ [![Version](https://img.shields.io/badge/Version-3.8.2-brightgreen?style=for-the-badge)](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.8.2)
10
10
  [![Claude Code](https://img.shields.io/badge/Claude_Code-Compatible-5A67D8?style=for-the-badge&logo=anthropic)](https://claude.ai/code)
11
11
  [![OpenAI Codex](https://img.shields.io/badge/OpenAI_Codex-Compatible-00A67E?style=for-the-badge&logo=openai)](https://openai.com/codex)
12
12
  [![MCP](https://img.shields.io/badge/MCP-Server-orange?style=for-the-badge)](https://modelcontextprotocol.io)
13
+ [![OpenSSF Scorecard](https://img.shields.io/ossf-scorecard/github.com/bvisible/mcp-ssh-manager?style=for-the-badge&label=OpenSSF)](https://scorecard.dev/viewer/?uri=github.com/bvisible/mcp-ssh-manager)
13
14
  [![License](https://img.shields.io/badge/License-MIT-blue?style=for-the-badge)](LICENSE)
14
15
 
15
16
  [![MCP Toplist](https://mcptoplist.com/badge/glama%2Fbvisible%2Fmcp-ssh-manager.svg)](https://mcptoplist.com/server/glama%2Fbvisible%2Fmcp-ssh-manager)
@@ -22,28 +23,67 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
22
23
 
23
24
  ---
24
25
 
25
- ## 🎉 What's New in v3.8.0
26
+ ## 🎉 What's New in v3.8.2
26
27
 
27
- **👥 Groups that live in your config, `ssh_sync` fixed on Windows, and a crash that took the whole server down** (Released: August 14, 2026)
28
+ **🔐 The sudo password stops leaking to the remote process list, and the server joins the official MCP Registry** (Released: August 28, 2026)
28
29
 
29
- - **New optional `group` field per server** ([#56](https://github.com/bvisible/mcp-ssh-manager/pull/56) — contributed by [@ice616](https://github.com/ice616), requested in [#55](https://github.com/bvisible/mcp-ssh-manager/issues/55)) — tag a server with `group = "production"` and it *is* in that group: `ssh_execute_group` and `ssh_group_manage list` resolve members straight from your `.env`/TOML, so there is no `.server-groups.json` to maintain and the grouping travels with the config when you export it to another tool. Membership is the **union** of both sources, so groups you already store keep working untouched.
30
- - **🪟 `ssh_sync` works from a Windows host** ([#59](https://github.com/bvisible/mcp-ssh-manager/pull/59) — contributed by [@2836603852](https://github.com/2836603852)) — a local path like `C:\project` reached MSYS2 rsync unchanged, which read `C:` as a remote host and tried to SSH into a machine named `c`. Drive-letter, UNC and extended-length paths are now converted for the rsync argument only, while Node keeps the native path for its filesystem checks.
31
- - **💥 A tunnel on a busy port no longer kills the MCP server** — `ssh_tunnel_create` on an already-bound port hit an unhandled `'error'` event and took the entire process down with it, dropping every pooled SSH connection and open session. It now returns a normal error.
32
- - **🔒 Security: `@modelcontextprotocol/sdk` floor raised to `^1.30.0`** — the previous range still allowed versions carrying three published advisories, one of them high. `npm audit` is clean, and the `uuid` dependency is gone in favour of Node's built-in `crypto.randomUUID()`.
33
- - **🧪 JSDoc type-checking in CI** (`npm run typecheck`) — TypeScript now runs as a static checker over the plain JavaScript. **No build step, no `dist/`, nothing changes for users**; it found two of the bugs above on the day it landed.
30
+ - **🔒 Security fix: the sudo password no longer reaches the remote command line** ([#34](https://github.com/bvisible/mcp-ssh-manager/issues/34)) — `ssh_execute_sudo` and `ssh_deploy` built `echo "<password>" | sudo -S …`, leaving the password visible in `ps` and `/proc/<pid>/cmdline` to every account on the host. It now travels on the SSH channel's stdin, where nothing else can read it. A regression test fails if the old pattern comes back anywhere in `src/`.
31
+ - **📖 Listed in the official MCP Registry** as `io.github.bvisible/mcp-ssh-manager` — the registry that feeds MCP clients. The project was simply absent from it.
32
+ - **🛡️ OpenSSF Scorecard + signed provenance + SBOM** — releases now publish from CI with build provenance you can check via `npm audit signatures`, and each one carries a CycloneDX SBOM.
33
+ - **📋 The security modes are finally documented where people land** — `readonly` and `restricted` have existed since v3.5.0 and were buried. See the section right below.
34
+
35
+ [Read full changelog →](CHANGELOG.md#382---2026-08-28)
36
+
37
+ ---
38
+
39
+ ## 🔐 Giving an agent SSH access, safely
40
+
41
+ An MCP SSH server is the most dangerous tool you can hand an AI agent: a shell on
42
+ machines that matter. This one is built so you decide how far the agent can go —
43
+ **per server**, not globally.
44
+
45
+ | Mode | What the agent can do |
46
+ |---|---|
47
+ | `unrestricted` *(default)* | Everything. Same behaviour as any other SSH MCP server. |
48
+ | `readonly` | Mutating tools are refused outright — no deploy, no upload, no sudo, no database import. Read commands still work. |
49
+ | `restricted` | Every command must match an allow pattern **and** no deny pattern. Anything else is refused before it reaches the host. |
34
50
 
35
51
  ```env
36
- SSH_SERVER_WEB1_GROUP=production
52
+ SSH_SERVER_PROD_MODE=readonly
53
+ SSH_SERVER_STAGING_MODE=restricted
54
+ SSH_SERVER_STAGING_ALLOW_PATTERNS=^systemctl (status|restart) myapp$;^tail -n \d+ /var/log/
37
55
  ```
38
56
 
39
- [Read full changelog →](CHANGELOG.md#380---2026-08-14)
57
+ Alongside that:
58
+
59
+ - **The sudo password never reaches the remote command line.** It travels on the
60
+ SSH channel's stdin, so it is not visible in `ps`, in `/proc/<pid>/cmdline`, or
61
+ in an `auditd` trail — unlike the `echo "$pass" | sudo -S` pattern common in
62
+ this category ([#34](https://github.com/bvisible/mcp-ssh-manager/issues/34)).
63
+ - **Every database argument is shell-quoted** through one centralised helper,
64
+ guarded by a 648-combination injection test.
65
+ - **Read-only SQL is enforced**, not suggested: `ssh_db_query` refuses anything
66
+ that is not a `SELECT`.
67
+ - **Vulnerabilities are published, not buried.** See [SECURITY.md](SECURITY.md)
68
+ for the reporting process and the advisories already fixed.
69
+ - **Reproducible installs**: the lockfile is committed, CI installs with
70
+ `npm ci`, and a test enforces that every dependency resolves to
71
+ registry.npmjs.org with an integrity hash and no unreviewed install scripts.
40
72
 
41
73
  ---
42
74
 
43
75
  ## Previous Releases
44
76
 
45
77
  <details>
46
- <summary><b>📜 Release history — v3.7.0 down to v1.0.0</b> (click to expand)</summary>
78
+ <summary><b>📜 Release history — v3.8.1 down to v1.0.0</b> (click to expand)</summary>
79
+
80
+ ### v3.8.1 - Reproducible installs and blocking quality gates (August 28, 2026)
81
+
82
+ - **Committed lockfile** ([#60](https://github.com/bvisible/mcp-ssh-manager/pull/60) — contributed by [@cudatuda](https://github.com/cudatuda)) plus `npm run test:lockfile` guarding it against drift and tampering. CI installs with `npm ci`; ESLint and the JSDoc typecheck became blocking gates after being purely decorative. [Full changelog →](CHANGELOG.md#381---2026-08-28)
83
+
84
+ ### v3.8.0 - Groups in your config, `ssh_sync` on Windows, tunnel crash fix (August 14, 2026)
85
+
86
+ - **👥 New optional `group` field per server** ([#56](https://github.com/bvisible/mcp-ssh-manager/pull/56) — contributed by [@ice616](https://github.com/ice616), requested in [#55](https://github.com/bvisible/mcp-ssh-manager/issues/55)) — tag a server with `group = "production"` and it *is* in that group: `ssh_execute_group` resolves members straight from your `.env`/TOML, union'd with any `.server-groups.json` you already keep. Also: `ssh_sync` fixed from a Windows host ([#59](https://github.com/bvisible/mcp-ssh-manager/pull/59) — contributed by [@2836603852](https://github.com/2836603852)), a tunnel on a busy port no longer takes the whole MCP server down, the `@modelcontextprotocol/sdk` floor raised to `^1.30.0` over three advisories, and JSDoc type-checking added to CI. [Full changelog →](CHANGELOG.md#380---2026-08-14)
47
87
 
48
88
  ### v3.7.0 - Per-server SSH agent forwarding (July 13, 2026)
49
89
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "3.8.0",
3
+ "version": "3.8.2",
4
+ "mcpName": "io.github.bvisible/mcp-ssh-manager",
4
5
  "description": "MCP SSH Manager: Model Context Protocol server for SSH remote server management. Control SSH connections from Claude Code and OpenAI Codex - execute commands, transfer files, database operations, backups, health monitoring, and DevOps automation. NEW: Tool activation system reduces context usage by 92%",
5
6
  "main": "src/index.js",
6
7
  "bin": {
@@ -13,7 +14,9 @@
13
14
  "setup": "npm install && pip install -r tools/requirements.txt",
14
15
  "configure": "python tools/server-manager.py",
15
16
  "test-connection": "python tools/test-connection.py",
16
- "test": "npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:dbrowcount",
17
+ "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:dbrowcount",
18
+ "test:lockfile": "node tests/test-lockfile.js",
19
+ "test:sudostdin": "node tests/test-sudo-stdin.js",
17
20
  "test:profiles": "node tests/test-profiles.js",
18
21
  "test:aliases": "node tests/test-command-aliases.js",
19
22
  "test:hooks": "node tests/test-hooks.js",
package/server.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.bvisible/mcp-ssh-manager",
4
+ "description": "SSH server management for agents, with per-server read-only and allowlist security modes",
5
+ "repository": {
6
+ "url": "https://github.com/bvisible/mcp-ssh-manager",
7
+ "source": "github"
8
+ },
9
+ "version": "3.8.2",
10
+ "packages": [
11
+ {
12
+ "registryType": "npm",
13
+ "identifier": "mcp-ssh-manager",
14
+ "version": "3.8.2",
15
+ "transport": {
16
+ "type": "stdio"
17
+ },
18
+ "environmentVariables": [
19
+ {
20
+ "name": "SSH_CONFIG_PATH",
21
+ "description": "Path to a TOML file holding the server definitions. Defaults to ~/.codex/ssh-config.toml. Each server can set MODE to readonly or restricted to constrain what the agent may run.",
22
+ "isRequired": false,
23
+ "isSecret": false,
24
+ "format": "filepath"
25
+ },
26
+ {
27
+ "name": "SSH_ENV_PATH",
28
+ "description": "Path to a .env file declaring servers as SSH_SERVER_<NAME>_HOST, _USER, _KEYPATH and friends. Defaults to a .env next to the package.",
29
+ "isRequired": false,
30
+ "isSecret": false,
31
+ "format": "filepath"
32
+ }
33
+ ]
34
+ }
35
+ ]
36
+ }
@@ -51,40 +51,40 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
51
51
  strategy.requiresSudo = true;
52
52
  }
53
53
 
54
+ // A step that needs the sudo password carries it as `stdin`, never inside
55
+ // `command`. Interpolating it (`echo "<pass>" | sudo -S …`) published the
56
+ // password to the remote process list and /proc/<pid>/cmdline (issue #34).
57
+ // See the ssh_execute_sudo handler for what -S -k -p '' each do.
58
+ const sudoPrefix = sudoPassword ? "sudo -S -k -p '' " : 'sudo ';
59
+ const withSudoStdin = (step) => (sudoPassword ? { ...step, stdin: `${sudoPassword}\n` } : step);
60
+
54
61
  // Step 3: Copy from temp to final location
55
- const copyCmd = needsSudo && sudoPassword ?
56
- `echo "${sudoPassword}" | sudo -S cp {{tempFile}} "${remotePath}"` :
57
- needsSudo ?
58
- `sudo cp {{tempFile}} "${remotePath}"` :
59
- `cp {{tempFile}} "${remotePath}"`;
62
+ const copyCmd = needsSudo ?
63
+ `${sudoPrefix}cp {{tempFile}} "${remotePath}"` :
64
+ `cp {{tempFile}} "${remotePath}"`;
60
65
 
61
- strategy.steps.push({
66
+ strategy.steps.push(needsSudo ? withSudoStdin({
67
+ type: 'copy',
68
+ command: copyCmd
69
+ }) : {
62
70
  type: 'copy',
63
71
  command: copyCmd
64
72
  });
65
73
 
66
74
  // Step 4: Set ownership if specified
67
75
  if (owner) {
68
- const chownCmd = sudoPassword ?
69
- `echo "${sudoPassword}" | sudo -S chown ${owner} "${remotePath}"` :
70
- `sudo chown ${owner} "${remotePath}"`;
71
-
72
- strategy.steps.push({
76
+ strategy.steps.push(withSudoStdin({
73
77
  type: 'chown',
74
- command: chownCmd
75
- });
78
+ command: `${sudoPrefix}chown ${owner} "${remotePath}"`
79
+ }));
76
80
  }
77
81
 
78
82
  // Step 5: Set permissions if specified
79
83
  if (permissions) {
80
- const chmodCmd = sudoPassword ?
81
- `echo "${sudoPassword}" | sudo -S chmod ${permissions} "${remotePath}"` :
82
- `sudo chmod ${permissions} "${remotePath}"`;
83
-
84
- strategy.steps.push({
84
+ strategy.steps.push(withSudoStdin({
85
85
  type: 'chmod',
86
- command: chmodCmd
87
- });
86
+ command: `${sudoPrefix}chmod ${permissions} "${remotePath}"`
87
+ }));
88
88
  }
89
89
 
90
90
  // Step 6: Restart service if specified
package/src/index.js CHANGED
@@ -2284,7 +2284,14 @@ registerToolConditional(
2284
2284
  for (const step of strategy.steps) {
2285
2285
  const command = step.command.replace('{{tempFile}}', tempFile);
2286
2286
 
2287
- const result = await execCommandWithTimeout(ssh, command, { platform: deployServerConfig?.platform }, 15000);
2287
+ // step.stdin carries the sudo password for steps that need it, so it
2288
+ // never reaches the remote command line (issue #34).
2289
+ const result = await execCommandWithTimeout(
2290
+ ssh,
2291
+ command,
2292
+ { platform: deployServerConfig?.platform, stdin: step.stdin ?? null },
2293
+ 15000
2294
+ );
2288
2295
 
2289
2296
  if (result.code !== 0 && step.type !== 'backup') {
2290
2297
  throw new Error(`${step.type} failed: ${result.stderr}`);
@@ -2364,12 +2371,21 @@ registerToolConditional(
2364
2371
  fullCommand = `sudo ${fullCommand}`;
2365
2372
  }
2366
2373
 
2367
- // Add password if provided
2368
- if (password) {
2369
- fullCommand = `echo "${password}" | sudo -S ${command.replace(/^sudo /, '')}`;
2370
- } else if (serverConfig?.sudoPassword) {
2371
- // Use configured sudo password if available
2372
- fullCommand = `echo "${serverConfig.sudoPassword}" | sudo -S ${command.replace(/^sudo /, '')}`;
2374
+ // Add password if provided. The password travels on the exec channel's
2375
+ // stdin, never inside the command string: the previous
2376
+ // `echo "<pass>" | sudo -S …` left it readable in the remote process list
2377
+ // and /proc/<pid>/cmdline for anyone with an account on the host (#34).
2378
+ // -S read the password from stdin
2379
+ // -k invalidate any cached sudo timestamp first, so sudo always
2380
+ // consumes the password we wrote. Without it, an already-authorised
2381
+ // sudo skips the prompt and the password stays in the pipe, where
2382
+ // the command itself would read it as its own input.
2383
+ // -p '' suppress the prompt, which would otherwise land in stderr.
2384
+ let sudoStdin = null;
2385
+ const effectiveSudoPassword = password || serverConfig?.sudoPassword;
2386
+ if (effectiveSudoPassword) {
2387
+ fullCommand = `sudo -S -k -p '' ${command.replace(/^sudo /, '')}`;
2388
+ sudoStdin = `${effectiveSudoPassword}\n`;
2373
2389
  }
2374
2390
 
2375
2391
  // Add working directory if specified
@@ -2390,10 +2406,12 @@ registerToolConditional(
2390
2406
  }
2391
2407
  }
2392
2408
 
2393
- const result = await execCommandWithTimeout(ssh, fullCommand, { platform }, timeout);
2409
+ const result = await execCommandWithTimeout(ssh, fullCommand, { platform, stdin: sudoStdin }, timeout);
2394
2410
 
2395
- // Mask password in output for security
2396
- const maskedCommand = fullCommand.replace(/echo "[^"]+" \| sudo -S/, 'sudo');
2411
+ // The command string no longer carries the password, so there is nothing
2412
+ // left to mask — the flags are shown as-is. Kept as a named value so the
2413
+ // response format is unchanged for existing callers.
2414
+ const maskedCommand = fullCommand;
2397
2415
 
2398
2416
  return {
2399
2417
  content: [
@@ -188,7 +188,7 @@ class SSHManager {
188
188
  throw new Error('Not connected to SSH server');
189
189
  }
190
190
 
191
- const { timeout = 30000, cwd, rawCommand = false } = options;
191
+ const { timeout = 30000, cwd, rawCommand = false, stdin = null } = options;
192
192
  const fullCommand = (cwd && !rawCommand) ? `cd ${cwd} && ${command}` : command;
193
193
 
194
194
  return new Promise((resolve, reject) => {
@@ -238,6 +238,27 @@ class SSHManager {
238
238
 
239
239
  stream = streamObj;
240
240
 
241
+ // Feed the remote process on the exec channel's stdin. This is how the
242
+ // sudo password reaches `sudo -S` without ever appearing in the remote
243
+ // command line: interpolating it into `echo "..." | sudo -S` left it
244
+ // readable in `ps` and /proc/<pid>/cmdline for every account on the
245
+ // host, for the lifetime of the echo (issue #34). Closing the input
246
+ // afterwards tells sudo no more is coming; only done when a caller
247
+ // actually supplies stdin, so interactive commands are unaffected.
248
+ if (stdin !== null) {
249
+ try {
250
+ stream.write(stdin);
251
+ stream.end();
252
+ } catch (writeError) {
253
+ if (!completed) {
254
+ completed = true;
255
+ if (timeoutId) clearTimeout(timeoutId);
256
+ reject(writeError);
257
+ return;
258
+ }
259
+ }
260
+ }
261
+
241
262
  stream.on('close', (code, signal) => {
242
263
  if (!completed) {
243
264
  completed = true;