mcp-ssh-manager 3.6.5 → 3.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +18 -6
- package/SECURITY.md +55 -0
- package/docs/images/social-preview.png +0 -0
- package/docs/images/social-preview@2x.png +0 -0
- package/package.json +4 -2
- package/src/database-manager.js +118 -93
- package/src/index.js +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,37 @@ 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.6.7] - 2026-07-11
|
|
9
|
+
|
|
10
|
+
### Security
|
|
11
|
+
|
|
12
|
+
- **Command injection in the database command builders** ([#51](https://github.com/bvisible/mcp-ssh-manager/pull/51) — responsibly disclosed by **Ugur Ozer / AI Risk Management**, see [#48](https://github.com/bvisible/mcp-ssh-manager/issues/48))
|
|
13
|
+
- Every `ssh_db_*` tool argument — `database`, `table`, `collection`, output/input file paths, and the `user` / `host` / `port` / `password` connection fields — arrives from tool-call parameters and was interpolated straight into a **shell-evaluated** command string in `src/database-manager.js`. A crafted value (`$(…)`, backticks, `; cmd`, `| cmd`, `&& cmd`, bare `> file`) executed arbitrary commands on the configured SSH target, under the account the MCP server uses.
|
|
14
|
+
- The strongest path is **`ssh_db_list`**: it is classified read-only, so it stayed **allowed in the `readonly` and `restricted`** per-server security modes while still reaching an injectable builder — bypassing the boundary those modes promise.
|
|
15
|
+
- The v3.6.5 heredoc fix (#44) only hardened `ssh_db_query`'s query **text**; the `list` / `dump` / `import` / `restore` builders and the query builders' **connection flags** were untouched.
|
|
16
|
+
- **Fix:** a centralized `shellQuote()` (single-quote wrap + `'\''` escaping) now wraps **every** interpolated caller value across all 15 builders. The MySQL list-tables `database` became a shell-quoted positional argument instead of an interpolated `USE <db>` SQL clause, closing the SQL path too. Shell-quoting is transparent for legitimate values.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Security regression test `tests/test-database-injection.js` (`npm run test:dbinjection`, part of `npm test`): drives every builder × every caller-controlled parameter × an injection-payload battery (648 combinations) through a real `/bin/sh` with fake DB client binaries and asserts no payload ever executes; unit-tests `shellQuote()`; verifies benign values stay correctly quoted.
|
|
21
|
+
- `SECURITY.md` documenting the private vulnerability disclosure process (GitHub private vulnerability reporting + security email; resolves [#48](https://github.com/bvisible/mcp-ssh-manager/issues/48)).
|
|
22
|
+
|
|
23
|
+
## [3.6.6] - 2026-07-11
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **Handlers read stale snake_case config fields that `ConfigLoader` no longer produces** ([#49](https://github.com/bvisible/mcp-ssh-manager/issues/49) — thanks [@egoan82](https://github.com/egoan82) for the excellent root-cause report; fixed in [#50](https://github.com/bvisible/mcp-ssh-manager/pull/50))
|
|
28
|
+
- Since the v3.0.0 ConfigLoader refactor, resolved server configs expose **camelCase** fields (`sudoPassword`, `defaultDir`, `keyPath`), but several handlers still read the pre-3.0 snake_case/lowercase names — always `undefined`, so their fallback branches silently never ran:
|
|
29
|
+
- `ssh_execute_sudo` ignored the configured `SUDO_PASSWORD` → `sudo: a terminal is required to authenticate` on hosts without a TTY on the exec channel
|
|
30
|
+
- `ssh_execute` / `ssh_group_execute` / `ssh_execute_sudo` ignored `DEFAULT_DIR` — commands silently ran in `$HOME`
|
|
31
|
+
- `ssh_list_servers` always reported an empty `defaultDir`
|
|
32
|
+
- `ssh_sync` never passed the configured SSH key to rsync (`-i` / `BatchMode=yes`), falling back to whatever default key the agent offered
|
|
33
|
+
- No configuration change required: `.env`/TOML source keys (`SUDO_PASSWORD`, `default_dir`, `key_path`, …) are unchanged — existing configs simply start working again.
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- Regression test `tests/test-config-field-names.js` (`npm run test:fieldnames`, part of `npm test`): locks the ConfigLoader's output field names from both `.env` and TOML sources, and statically forbids stale `.sudo_password` / `.default_dir` / `.keypath` access in `src/`.
|
|
38
|
+
|
|
8
39
|
## [3.6.5] - 2026-06-30
|
|
9
40
|
|
|
10
41
|
### Security
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
|
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/mcp-ssh-manager)
|
|
8
8
|
[](https://www.npmjs.com/package/mcp-ssh-manager)
|
|
9
|
-
[](https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.6.7)
|
|
10
10
|
[](https://claude.ai/code)
|
|
11
11
|
[](https://openai.com/codex)
|
|
12
12
|
[](https://modelcontextprotocol.io)
|
|
@@ -20,19 +20,31 @@ A Model Context Protocol (MCP) server that enables **Claude Code** and **OpenAI
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
## 🎉 What's New in v3.6.
|
|
23
|
+
## 🎉 What's New in v3.6.7
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
**🔒 Security fix: command injection in the database helpers (`ssh_db_list` / `ssh_db_dump` / `ssh_db_import`)** (Released: July 11, 2026)
|
|
26
26
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
27
|
+
- **Every `ssh_db_*` argument is now shell-quoted** ([#51](https://github.com/bvisible/mcp-ssh-manager/pull/51) — responsibly disclosed by **Ugur Ozer / AI Risk Management**, see [#48](https://github.com/bvisible/mcp-ssh-manager/issues/48)) — the database, table, collection, file-path and connection values passed to the database command builders were interpolated straight into a shell-evaluated string, so a crafted value (`$(…)`, backticks, `; cmd`) executed arbitrary commands on the SSH target. The strongest path was **`ssh_db_list`**, which is read-only-classified and therefore stayed allowed in the `readonly` and `restricted` security modes. The v3.6.5 heredoc fix (#44) only covered `ssh_db_query`'s query *text*; this hardens the list/dump/import/restore builders and the query builders' connection flags too.
|
|
28
|
+
- **🧪 Regression-proofed** — a new test drives every builder × every caller-controlled parameter × an injection-payload battery (648 combinations) through a real shell with fake DB binaries and asserts nothing executes.
|
|
29
|
+
- **🔐 `SECURITY.md` added** — documents private vulnerability reporting (GitHub Security tab + security email).
|
|
30
|
+
- **No configuration or API change** — shell-quoting is transparent for normal database/table/file names.
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
⚠️ **Upgrade recommended for anyone exposing the database tools**, especially operators relying on `readonly` / `restricted` modes as a security boundary.
|
|
33
|
+
|
|
34
|
+
[Read full changelog →](CHANGELOG.md#367---2026-07-11)
|
|
31
35
|
|
|
32
36
|
---
|
|
33
37
|
|
|
34
38
|
## Previous Releases
|
|
35
39
|
|
|
40
|
+
### v3.6.6 - `SUDO_PASSWORD` / `DEFAULT_DIR` / `ssh_sync` key auth work again (July 11, 2026)
|
|
41
|
+
|
|
42
|
+
- **🔑 camelCase config field reads** ([#50](https://github.com/bvisible/mcp-ssh-manager/pull/50) — thanks [@egoan82](https://github.com/egoan82)) — since the v3.0.0 ConfigLoader refactor, `ssh_execute_sudo` ignored `SUDO_PASSWORD`, `DEFAULT_DIR` was ignored by `ssh_execute`/`ssh_group_execute`/`ssh_list_servers`, and `ssh_sync` never passed the configured SSH key to rsync. All aligned with the loader's camelCase fields, with a regression test locking the loader output shape. [Full changelog →](CHANGELOG.md#366---2026-07-11)
|
|
43
|
+
|
|
44
|
+
### v3.6.5 - `ssh_db_query` shell-injection security fix + real row_count (June 30, 2026)
|
|
45
|
+
|
|
46
|
+
- **🔒 Queries are delivered on stdin via a single-quoted heredoc** ([#44](https://github.com/bvisible/mcp-ssh-manager/pull/44), [#45](https://github.com/bvisible/mcp-ssh-manager/pull/45) — thanks [@technophile77](https://github.com/technophile77)) — the remote shell no longer parses backticks/`$(…)` inside queries (which corrupted backtick identifiers **and** let the "SELECT-only" tool run arbitrary shell commands), and `row_count` now reflects each engine's real output instead of counting wrapper lines. [Full changelog →](CHANGELOG.md#365---2026-06-30)
|
|
47
|
+
|
|
36
48
|
### v3.6.4 - Internal cleanup + a dead-code quality gate (June 18, 2026)
|
|
37
49
|
|
|
38
50
|
- **🧹 Dead-code removal (−343 lines), zero behavioral change** — removed 27 unused exports and 2 duplicate exports; the MCP server and CLI behave identically (command builders/parsers byte-identical, all 37 tools verified end-to-end). A calibrated `knip.json` plus a **blocking** `knip` CI step keep unused code from creeping back. [Full changelog →](CHANGELOG.md#364---2026-06-18)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
Only the latest published `mcp-ssh-manager` release on npm receives security fixes.
|
|
6
|
+
Please upgrade to the newest version before reporting an issue.
|
|
7
|
+
|
|
8
|
+
| Version | Supported |
|
|
9
|
+
| ------- | --------- |
|
|
10
|
+
| latest | ✅ |
|
|
11
|
+
| older | ❌ |
|
|
12
|
+
|
|
13
|
+
## Reporting a Vulnerability
|
|
14
|
+
|
|
15
|
+
**Please do not report security vulnerabilities through public GitHub issues,
|
|
16
|
+
discussions, or pull requests.**
|
|
17
|
+
|
|
18
|
+
Report privately through either channel:
|
|
19
|
+
|
|
20
|
+
- **GitHub Private Vulnerability Reporting** (preferred) — open the
|
|
21
|
+
[**Security** tab](https://github.com/bvisible/mcp-ssh-manager/security/advisories)
|
|
22
|
+
of this repository and click **Report a vulnerability**. This keeps the report,
|
|
23
|
+
discussion, and any resulting advisory private until a fix is released.
|
|
24
|
+
- **Email** — <security@bvisible.ch> (or <jeremy@bvisible.ch>).
|
|
25
|
+
|
|
26
|
+
Please include, as far as you can:
|
|
27
|
+
|
|
28
|
+
- the affected version and the affected tool(s) or source area,
|
|
29
|
+
- a description of the vulnerability and its impact,
|
|
30
|
+
- a minimal proof of concept or reproduction steps, and
|
|
31
|
+
- any suggested remediation.
|
|
32
|
+
|
|
33
|
+
To keep proof-of-concept work safe, validate against **local package source and
|
|
34
|
+
your own owned test boundary** — do not exercise third-party hosts or
|
|
35
|
+
maintainer infrastructure.
|
|
36
|
+
|
|
37
|
+
## Disclosure Process
|
|
38
|
+
|
|
39
|
+
- We aim to acknowledge a report within **72 hours**.
|
|
40
|
+
- We will confirm the issue, determine affected versions, and prepare a fix,
|
|
41
|
+
keeping you informed along the way.
|
|
42
|
+
- Fixes are released as a new npm version accompanied by a
|
|
43
|
+
[GitHub Security Advisory](https://github.com/bvisible/mcp-ssh-manager/security/advisories)
|
|
44
|
+
(with a CVE where warranted).
|
|
45
|
+
- We are happy to **credit reporters** in the advisory and release notes.
|
|
46
|
+
Let us know the name/handle you would like used, or if you prefer to remain anonymous.
|
|
47
|
+
|
|
48
|
+
## Scope Notes
|
|
49
|
+
|
|
50
|
+
`mcp-ssh-manager` executes commands on remote hosts on behalf of an AI assistant.
|
|
51
|
+
Reports are especially valuable when a tool documented as read-only or safe
|
|
52
|
+
(for example `ssh_db_list`, `ssh_db_query`, or any tool permitted under the
|
|
53
|
+
`readonly` / `restricted` per-server security modes) can be made to execute
|
|
54
|
+
arbitrary commands, escalate privileges, or exfiltrate data on the configured
|
|
55
|
+
SSH target.
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-ssh-manager",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.7",
|
|
4
4
|
"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
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"setup": "npm install && pip install -r tools/requirements.txt",
|
|
14
14
|
"configure": "python tools/server-manager.py",
|
|
15
15
|
"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:lifecycle && npm run test:sync && npm run test:dbquoting && npm run test:dbrowcount",
|
|
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:lifecycle && npm run test:sync && npm run test:dbquoting && npm run test:dbinjection && npm run test:dbrowcount",
|
|
17
17
|
"test:profiles": "node tests/test-profiles.js",
|
|
18
18
|
"test:aliases": "node tests/test-command-aliases.js",
|
|
19
19
|
"test:hooks": "node tests/test-hooks.js",
|
|
@@ -21,9 +21,11 @@
|
|
|
21
21
|
"test:policy": "node tests/test-policy.js",
|
|
22
22
|
"test:ping": "node tests/test-ssh-ping.js",
|
|
23
23
|
"test:config": "node tests/test-server-config-manager.js",
|
|
24
|
+
"test:fieldnames": "node tests/test-config-field-names.js",
|
|
24
25
|
"test:lifecycle": "node tests/test-lifecycle.js",
|
|
25
26
|
"test:sync": "node tests/test-sync-stats.js",
|
|
26
27
|
"test:dbquoting": "node tests/test-database-query-quoting.js",
|
|
28
|
+
"test:dbinjection": "node tests/test-database-injection.js",
|
|
27
29
|
"test:dbrowcount": "node tests/test-database-row-count.js",
|
|
28
30
|
"test:all": "npm test && ./scripts/validate.sh",
|
|
29
31
|
"validate": "./scripts/validate.sh",
|
package/src/database-manager.js
CHANGED
|
@@ -10,6 +10,28 @@ export const DB_TYPES = {
|
|
|
10
10
|
MONGODB: 'mongodb'
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// A single quote character as a constant, so shellQuote()'s escaping stays
|
|
14
|
+
// readable under the repo's single-quote lint style.
|
|
15
|
+
const SQ = '\'';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Quote a value for safe inclusion as a single POSIX shell word.
|
|
19
|
+
*
|
|
20
|
+
* Wraps the value in single quotes and escapes any embedded single quote as
|
|
21
|
+
* '\'' so the remote shell treats it literally — it never interprets $(...),
|
|
22
|
+
* backticks, $VAR, ;, |, &, redirects, spaces, or newlines inside the value.
|
|
23
|
+
* EVERY caller-controlled value interpolated into a database command string
|
|
24
|
+
* MUST go through this: the database/table/collection names, file paths, and
|
|
25
|
+
* connection fields all arrive from tool arguments (issue #48 — command
|
|
26
|
+
* injection via ssh_db_list / ssh_db_dump / ssh_db_import builder arguments).
|
|
27
|
+
* Numbers are coerced to string; null/undefined become an empty quoted word.
|
|
28
|
+
*/
|
|
29
|
+
export function shellQuote(value) {
|
|
30
|
+
if (value === null || value === undefined) return SQ + SQ;
|
|
31
|
+
// Replace every ' with '\'' (close quote, escaped quote, reopen), then wrap.
|
|
32
|
+
return SQ + String(value).replace(/'/g, SQ + '\\' + SQ + SQ) + SQ;
|
|
33
|
+
}
|
|
34
|
+
|
|
13
35
|
/**
|
|
14
36
|
* Build MySQL dump command
|
|
15
37
|
*/
|
|
@@ -27,22 +49,22 @@ export function buildMySQLDumpCommand(options) {
|
|
|
27
49
|
|
|
28
50
|
let command = 'mysqldump';
|
|
29
51
|
|
|
30
|
-
if (user) command += ` -u${user}`;
|
|
31
|
-
if (password) command += ` -p
|
|
32
|
-
if (host) command += ` -h ${host}`;
|
|
33
|
-
if (port) command += ` -P ${port}`;
|
|
52
|
+
if (user) command += ` -u${shellQuote(user)}`;
|
|
53
|
+
if (password) command += ` -p${shellQuote(password)}`;
|
|
54
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
55
|
+
if (port) command += ` -P ${shellQuote(port)}`;
|
|
34
56
|
|
|
35
57
|
command += ' --single-transaction --routines --triggers';
|
|
36
|
-
command += ` ${database}`;
|
|
58
|
+
command += ` ${shellQuote(database)}`;
|
|
37
59
|
|
|
38
60
|
if (tables && Array.isArray(tables)) {
|
|
39
|
-
command += ` ${tables.join(' ')}`;
|
|
61
|
+
command += ` ${tables.map(shellQuote).join(' ')}`;
|
|
40
62
|
}
|
|
41
63
|
|
|
42
64
|
if (compress) {
|
|
43
|
-
command += ` | gzip >
|
|
65
|
+
command += ` | gzip > ${shellQuote(outputFile)}`;
|
|
44
66
|
} else {
|
|
45
|
-
command += ` >
|
|
67
|
+
command += ` > ${shellQuote(outputFile)}`;
|
|
46
68
|
}
|
|
47
69
|
|
|
48
70
|
return command;
|
|
@@ -65,27 +87,27 @@ export function buildPostgreSQLDumpCommand(options) {
|
|
|
65
87
|
|
|
66
88
|
let command = '';
|
|
67
89
|
if (password) {
|
|
68
|
-
command = `PGPASSWORD
|
|
90
|
+
command = `PGPASSWORD=${shellQuote(password)} `;
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
command += 'pg_dump';
|
|
72
|
-
if (user) command += ` -U ${user}`;
|
|
73
|
-
if (host) command += ` -h ${host}`;
|
|
74
|
-
if (port) command += ` -p ${port}`;
|
|
94
|
+
if (user) command += ` -U ${shellQuote(user)}`;
|
|
95
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
96
|
+
if (port) command += ` -p ${shellQuote(port)}`;
|
|
75
97
|
command += ' --format=custom --clean --if-exists';
|
|
76
98
|
|
|
77
99
|
if (tables && Array.isArray(tables)) {
|
|
78
100
|
for (const table of tables) {
|
|
79
|
-
command += ` -t ${table}`;
|
|
101
|
+
command += ` -t ${shellQuote(table)}`;
|
|
80
102
|
}
|
|
81
103
|
}
|
|
82
104
|
|
|
83
|
-
command += ` ${database}`;
|
|
105
|
+
command += ` ${shellQuote(database)}`;
|
|
84
106
|
|
|
85
107
|
if (compress) {
|
|
86
|
-
command += ` | gzip >
|
|
108
|
+
command += ` | gzip > ${shellQuote(outputFile)}`;
|
|
87
109
|
} else {
|
|
88
|
-
command += ` >
|
|
110
|
+
command += ` > ${shellQuote(outputFile)}`;
|
|
89
111
|
}
|
|
90
112
|
|
|
91
113
|
return command;
|
|
@@ -107,23 +129,23 @@ export function buildMongoDBDumpCommand(options) {
|
|
|
107
129
|
} = options;
|
|
108
130
|
|
|
109
131
|
let command = 'mongodump';
|
|
110
|
-
if (host) command += ` --host ${host}`;
|
|
111
|
-
if (port) command += ` --port ${port}`;
|
|
112
|
-
if (user) command += ` --username ${user}`;
|
|
113
|
-
if (password) command += ` --password
|
|
114
|
-
if (database) command += ` --db ${database}`;
|
|
132
|
+
if (host) command += ` --host ${shellQuote(host)}`;
|
|
133
|
+
if (port) command += ` --port ${shellQuote(port)}`;
|
|
134
|
+
if (user) command += ` --username ${shellQuote(user)}`;
|
|
135
|
+
if (password) command += ` --password ${shellQuote(password)}`;
|
|
136
|
+
if (database) command += ` --db ${shellQuote(database)}`;
|
|
115
137
|
|
|
116
138
|
if (collections && Array.isArray(collections)) {
|
|
117
139
|
for (const collection of collections) {
|
|
118
|
-
command += ` --collection ${collection}`;
|
|
140
|
+
command += ` --collection ${shellQuote(collection)}`;
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
143
|
|
|
122
|
-
command += ` --out
|
|
144
|
+
command += ` --out ${shellQuote(outputDir)}`;
|
|
123
145
|
|
|
124
146
|
if (compress) {
|
|
125
|
-
command += ` && tar -czf
|
|
126
|
-
command += ` && rm -rf
|
|
147
|
+
command += ` && tar -czf ${shellQuote(outputDir + '.tar.gz')} -C "$(dirname ${shellQuote(outputDir)})" "$(basename ${shellQuote(outputDir)})"`;
|
|
148
|
+
command += ` && rm -rf ${shellQuote(outputDir)}`;
|
|
127
149
|
}
|
|
128
150
|
|
|
129
151
|
return command;
|
|
@@ -145,17 +167,17 @@ export function buildMySQLImportCommand(options) {
|
|
|
145
167
|
let command = '';
|
|
146
168
|
|
|
147
169
|
if (inputFile.endsWith('.gz')) {
|
|
148
|
-
command = `gunzip -c
|
|
170
|
+
command = `gunzip -c ${shellQuote(inputFile)} | `;
|
|
149
171
|
} else {
|
|
150
|
-
command = `cat
|
|
172
|
+
command = `cat ${shellQuote(inputFile)} | `;
|
|
151
173
|
}
|
|
152
174
|
|
|
153
175
|
command += 'mysql';
|
|
154
|
-
if (user) command += ` -u${user}`;
|
|
155
|
-
if (password) command += ` -p
|
|
156
|
-
if (host) command += ` -h ${host}`;
|
|
157
|
-
if (port) command += ` -P ${port}`;
|
|
158
|
-
command += ` ${database}`;
|
|
176
|
+
if (user) command += ` -u${shellQuote(user)}`;
|
|
177
|
+
if (password) command += ` -p${shellQuote(password)}`;
|
|
178
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
179
|
+
if (port) command += ` -P ${shellQuote(port)}`;
|
|
180
|
+
command += ` ${shellQuote(database)}`;
|
|
159
181
|
|
|
160
182
|
return command;
|
|
161
183
|
}
|
|
@@ -175,20 +197,20 @@ export function buildPostgreSQLImportCommand(options) {
|
|
|
175
197
|
|
|
176
198
|
let command = '';
|
|
177
199
|
if (password) {
|
|
178
|
-
command = `PGPASSWORD
|
|
200
|
+
command = `PGPASSWORD=${shellQuote(password)} `;
|
|
179
201
|
}
|
|
180
202
|
|
|
181
203
|
command += 'pg_restore';
|
|
182
|
-
if (user) command += ` -U ${user}`;
|
|
183
|
-
if (host) command += ` -h ${host}`;
|
|
184
|
-
if (port) command += ` -p ${port}`;
|
|
204
|
+
if (user) command += ` -U ${shellQuote(user)}`;
|
|
205
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
206
|
+
if (port) command += ` -p ${shellQuote(port)}`;
|
|
185
207
|
command += ' --clean --if-exists';
|
|
186
|
-
command += ` -d ${database}`;
|
|
208
|
+
command += ` -d ${shellQuote(database)}`;
|
|
187
209
|
|
|
188
210
|
if (inputFile.endsWith('.gz')) {
|
|
189
|
-
command = `gunzip -c
|
|
211
|
+
command = `gunzip -c ${shellQuote(inputFile)} | ${command}`;
|
|
190
212
|
} else {
|
|
191
|
-
command += `
|
|
213
|
+
command += ` ${shellQuote(inputFile)}`;
|
|
192
214
|
}
|
|
193
215
|
|
|
194
216
|
return command;
|
|
@@ -211,23 +233,23 @@ export function buildMongoDBRestoreCommand(options) {
|
|
|
211
233
|
|
|
212
234
|
if (inputPath.endsWith('.tar.gz')) {
|
|
213
235
|
const extractDir = inputPath.replace('.tar.gz', '');
|
|
214
|
-
command = `tar -xzf
|
|
236
|
+
command = `tar -xzf ${shellQuote(inputPath)} -C "$(dirname ${shellQuote(inputPath)})" && `;
|
|
215
237
|
command += 'mongorestore';
|
|
216
238
|
if (drop) command += ' --drop';
|
|
217
|
-
if (host) command += ` --host ${host}`;
|
|
218
|
-
if (port) command += ` --port ${port}`;
|
|
219
|
-
if (user) command += ` --username ${user}`;
|
|
220
|
-
if (password) command += ` --password
|
|
221
|
-
command += `
|
|
222
|
-
command += ` && rm -rf
|
|
239
|
+
if (host) command += ` --host ${shellQuote(host)}`;
|
|
240
|
+
if (port) command += ` --port ${shellQuote(port)}`;
|
|
241
|
+
if (user) command += ` --username ${shellQuote(user)}`;
|
|
242
|
+
if (password) command += ` --password ${shellQuote(password)}`;
|
|
243
|
+
command += ` ${shellQuote(extractDir)}`;
|
|
244
|
+
command += ` && rm -rf ${shellQuote(extractDir)}`;
|
|
223
245
|
} else {
|
|
224
246
|
command = 'mongorestore';
|
|
225
247
|
if (drop) command += ' --drop';
|
|
226
|
-
if (host) command += ` --host ${host}`;
|
|
227
|
-
if (port) command += ` --port ${port}`;
|
|
228
|
-
if (user) command += ` --username ${user}`;
|
|
229
|
-
if (password) command += ` --password
|
|
230
|
-
command += `
|
|
248
|
+
if (host) command += ` --host ${shellQuote(host)}`;
|
|
249
|
+
if (port) command += ` --port ${shellQuote(port)}`;
|
|
250
|
+
if (user) command += ` --username ${shellQuote(user)}`;
|
|
251
|
+
if (password) command += ` --password ${shellQuote(password)}`;
|
|
252
|
+
command += ` ${shellQuote(inputPath)}`;
|
|
231
253
|
}
|
|
232
254
|
|
|
233
255
|
return command;
|
|
@@ -240,10 +262,10 @@ export function buildMySQLListDatabasesCommand(options) {
|
|
|
240
262
|
const { user, password, host = 'localhost', port = 3306 } = options;
|
|
241
263
|
|
|
242
264
|
let command = 'mysql';
|
|
243
|
-
if (user) command += ` -u${user}`;
|
|
244
|
-
if (password) command += ` -p
|
|
245
|
-
if (host) command += ` -h ${host}`;
|
|
246
|
-
if (port) command += ` -P ${port}`;
|
|
265
|
+
if (user) command += ` -u${shellQuote(user)}`;
|
|
266
|
+
if (password) command += ` -p${shellQuote(password)}`;
|
|
267
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
268
|
+
if (port) command += ` -P ${shellQuote(port)}`;
|
|
247
269
|
command += ' -e "SHOW DATABASES;" | tail -n +2';
|
|
248
270
|
|
|
249
271
|
return command;
|
|
@@ -256,11 +278,14 @@ export function buildMySQLListTablesCommand(options) {
|
|
|
256
278
|
const { database, user, password, host = 'localhost', port = 3306 } = options;
|
|
257
279
|
|
|
258
280
|
let command = 'mysql';
|
|
259
|
-
if (user) command += ` -u${user}`;
|
|
260
|
-
if (password) command += ` -p
|
|
261
|
-
if (host) command += ` -h ${host}`;
|
|
262
|
-
if (port) command += ` -P ${port}`;
|
|
263
|
-
|
|
281
|
+
if (user) command += ` -u${shellQuote(user)}`;
|
|
282
|
+
if (password) command += ` -p${shellQuote(password)}`;
|
|
283
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
284
|
+
if (port) command += ` -P ${shellQuote(port)}`;
|
|
285
|
+
// Pass the database as a shell-quoted positional argument instead of
|
|
286
|
+
// interpolating it into the -e SQL, so the name can inject neither the
|
|
287
|
+
// shell nor the SQL (a crafted USE clause).
|
|
288
|
+
command += ` ${shellQuote(database)} -e "SHOW TABLES;" | tail -n +2`;
|
|
264
289
|
|
|
265
290
|
return command;
|
|
266
291
|
}
|
|
@@ -273,13 +298,13 @@ export function buildPostgreSQLListDatabasesCommand(options) {
|
|
|
273
298
|
|
|
274
299
|
let command = '';
|
|
275
300
|
if (password) {
|
|
276
|
-
command = `PGPASSWORD
|
|
301
|
+
command = `PGPASSWORD=${shellQuote(password)} `;
|
|
277
302
|
}
|
|
278
303
|
|
|
279
304
|
command += 'psql';
|
|
280
|
-
if (user) command += ` -U ${user}`;
|
|
281
|
-
if (host) command += ` -h ${host}`;
|
|
282
|
-
if (port) command += ` -p ${port}`;
|
|
305
|
+
if (user) command += ` -U ${shellQuote(user)}`;
|
|
306
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
307
|
+
if (port) command += ` -p ${shellQuote(port)}`;
|
|
283
308
|
command += ' -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;" | sed \'/^$/d\' | sed \'s/^[ \\t]*//\'';
|
|
284
309
|
|
|
285
310
|
return command;
|
|
@@ -293,14 +318,14 @@ export function buildPostgreSQLListTablesCommand(options) {
|
|
|
293
318
|
|
|
294
319
|
let command = '';
|
|
295
320
|
if (password) {
|
|
296
|
-
command = `PGPASSWORD
|
|
321
|
+
command = `PGPASSWORD=${shellQuote(password)} `;
|
|
297
322
|
}
|
|
298
323
|
|
|
299
324
|
command += 'psql';
|
|
300
|
-
if (user) command += ` -U ${user}`;
|
|
301
|
-
if (host) command += ` -h ${host}`;
|
|
302
|
-
if (port) command += ` -p ${port}`;
|
|
303
|
-
command += ` -d ${database}`;
|
|
325
|
+
if (user) command += ` -U ${shellQuote(user)}`;
|
|
326
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
327
|
+
if (port) command += ` -p ${shellQuote(port)}`;
|
|
328
|
+
command += ` -d ${shellQuote(database)}`;
|
|
304
329
|
command += ' -t -c "SELECT tablename FROM pg_tables WHERE schemaname = \'public\';" | sed \'/^$/d\' | sed \'s/^[ \\t]*//\'';
|
|
305
330
|
|
|
306
331
|
return command;
|
|
@@ -313,10 +338,10 @@ export function buildMongoDBListDatabasesCommand(options) {
|
|
|
313
338
|
const { user, password, host = 'localhost', port = 27017 } = options;
|
|
314
339
|
|
|
315
340
|
let command = 'mongo';
|
|
316
|
-
if (host) command += ` --host ${host}`;
|
|
317
|
-
if (port) command += ` --port ${port}`;
|
|
318
|
-
if (user) command += ` --username ${user}`;
|
|
319
|
-
if (password) command += ` --password
|
|
341
|
+
if (host) command += ` --host ${shellQuote(host)}`;
|
|
342
|
+
if (port) command += ` --port ${shellQuote(port)}`;
|
|
343
|
+
if (user) command += ` --username ${shellQuote(user)}`;
|
|
344
|
+
if (password) command += ` --password ${shellQuote(password)}`;
|
|
320
345
|
command += ' --quiet --eval "db.adminCommand(\'listDatabases\').databases.forEach(function(d){print(d.name)})"';
|
|
321
346
|
|
|
322
347
|
return command;
|
|
@@ -329,11 +354,11 @@ export function buildMongoDBListCollectionsCommand(options) {
|
|
|
329
354
|
const { database, user, password, host = 'localhost', port = 27017 } = options;
|
|
330
355
|
|
|
331
356
|
let command = 'mongo';
|
|
332
|
-
if (host) command += ` --host ${host}`;
|
|
333
|
-
if (port) command += ` --port ${port}`;
|
|
334
|
-
if (user) command += ` --username ${user}`;
|
|
335
|
-
if (password) command += ` --password
|
|
336
|
-
command += ` ${database}`;
|
|
357
|
+
if (host) command += ` --host ${shellQuote(host)}`;
|
|
358
|
+
if (port) command += ` --port ${shellQuote(port)}`;
|
|
359
|
+
if (user) command += ` --username ${shellQuote(user)}`;
|
|
360
|
+
if (password) command += ` --password ${shellQuote(password)}`;
|
|
361
|
+
command += ` ${shellQuote(database)}`;
|
|
337
362
|
command += ' --quiet --eval "db.getCollectionNames().forEach(function(c){print(c)})"';
|
|
338
363
|
|
|
339
364
|
return command;
|
|
@@ -386,11 +411,11 @@ export function buildMySQLQueryCommand(options) {
|
|
|
386
411
|
}
|
|
387
412
|
|
|
388
413
|
let command = 'mysql';
|
|
389
|
-
if (user) command += ` -u${user}`;
|
|
390
|
-
if (password) command += ` -p
|
|
391
|
-
if (host) command += ` -h ${host}`;
|
|
392
|
-
if (port) command += ` -P ${port}`;
|
|
393
|
-
command += ` ${database}`;
|
|
414
|
+
if (user) command += ` -u${shellQuote(user)}`;
|
|
415
|
+
if (password) command += ` -p${shellQuote(password)}`;
|
|
416
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
417
|
+
if (port) command += ` -P ${shellQuote(port)}`;
|
|
418
|
+
command += ` ${shellQuote(database)}`;
|
|
394
419
|
|
|
395
420
|
// Feed the SQL via stdin (quoted heredoc) so the remote shell never parses it —
|
|
396
421
|
// backtick-quoted identifiers and `$` survive intact, and query text cannot inject
|
|
@@ -419,14 +444,14 @@ export function buildPostgreSQLQueryCommand(options) {
|
|
|
419
444
|
|
|
420
445
|
let command = '';
|
|
421
446
|
if (password) {
|
|
422
|
-
command = `PGPASSWORD
|
|
447
|
+
command = `PGPASSWORD=${shellQuote(password)} `;
|
|
423
448
|
}
|
|
424
449
|
|
|
425
450
|
command += 'psql';
|
|
426
|
-
if (user) command += ` -U ${user}`;
|
|
427
|
-
if (host) command += ` -h ${host}`;
|
|
428
|
-
if (port) command += ` -p ${port}`;
|
|
429
|
-
command += ` -d ${database}`;
|
|
451
|
+
if (user) command += ` -U ${shellQuote(user)}`;
|
|
452
|
+
if (host) command += ` -h ${shellQuote(host)}`;
|
|
453
|
+
if (port) command += ` -p ${shellQuote(port)}`;
|
|
454
|
+
command += ` -d ${shellQuote(database)}`;
|
|
430
455
|
// Feed SQL via stdin (quoted heredoc) instead of `-c "${query}"` so the remote shell
|
|
431
456
|
// never parses it. See buildHeredoc and issue #44.
|
|
432
457
|
command += buildHeredoc(query);
|
|
@@ -441,11 +466,11 @@ export function buildMongoDBQueryCommand(options) {
|
|
|
441
466
|
const { database, collection, query, user, password, host = 'localhost', port = 27017 } = options;
|
|
442
467
|
|
|
443
468
|
let command = 'mongo';
|
|
444
|
-
if (host) command += ` --host ${host}`;
|
|
445
|
-
if (port) command += ` --port ${port}`;
|
|
446
|
-
if (user) command += ` --username ${user}`;
|
|
447
|
-
if (password) command += ` --password
|
|
448
|
-
command += ` ${database}`;
|
|
469
|
+
if (host) command += ` --host ${shellQuote(host)}`;
|
|
470
|
+
if (port) command += ` --port ${shellQuote(port)}`;
|
|
471
|
+
if (user) command += ` --username ${shellQuote(user)}`;
|
|
472
|
+
if (password) command += ` --password ${shellQuote(password)}`;
|
|
473
|
+
command += ` ${shellQuote(database)}`;
|
|
449
474
|
// Feed the JS script via stdin (quoted heredoc) instead of `--eval "..."` so the
|
|
450
475
|
// remote shell never expands backticks/`$` in the query. mongo still evaluates the
|
|
451
476
|
// script as JavaScript (expected). See buildHeredoc and issue #44.
|
package/src/index.js
CHANGED
|
@@ -672,10 +672,10 @@ registerToolConditional(
|
|
|
672
672
|
});
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
-
// Use provided cwd, or
|
|
675
|
+
// Use provided cwd, or the server's configured defaultDir, or no cwd
|
|
676
676
|
const servers = await loadServerConfig();
|
|
677
677
|
const serverConfig = servers[serverName.toLowerCase()];
|
|
678
|
-
const workingDir = cwd || serverConfig?.
|
|
678
|
+
const workingDir = cwd || serverConfig?.defaultDir;
|
|
679
679
|
const platform = serverConfig?.platform || 'linux';
|
|
680
680
|
|
|
681
681
|
// Build cwd-prefixed command using platform-appropriate syntax
|
|
@@ -898,7 +898,7 @@ registerToolConditional(
|
|
|
898
898
|
const serverConfig = servers[serverName.toLowerCase()];
|
|
899
899
|
|
|
900
900
|
// Check if sshpass is available for password authentication
|
|
901
|
-
if (!serverConfig.
|
|
901
|
+
if (!serverConfig.keyPath && serverConfig.password) {
|
|
902
902
|
// Check if sshpass is installed
|
|
903
903
|
try {
|
|
904
904
|
const { execSync } = await import('child_process');
|
|
@@ -980,12 +980,12 @@ registerToolConditional(
|
|
|
980
980
|
const sshOptions = [];
|
|
981
981
|
|
|
982
982
|
// Different options based on authentication method
|
|
983
|
-
if (serverConfig.
|
|
983
|
+
if (serverConfig.keyPath) {
|
|
984
984
|
sshOptions.push('-o BatchMode=yes'); // No password prompts
|
|
985
985
|
sshOptions.push('-o StrictHostKeyChecking=accept-new'); // Accept new keys, reject changed ones
|
|
986
986
|
sshOptions.push('-o ConnectTimeout=10'); // Connection timeout
|
|
987
987
|
|
|
988
|
-
const keyPath = serverConfig.
|
|
988
|
+
const keyPath = serverConfig.keyPath.replace('~', os.homedir());
|
|
989
989
|
sshOptions.push(`-i ${keyPath}`);
|
|
990
990
|
} else {
|
|
991
991
|
// With sshpass, we don't use BatchMode
|
|
@@ -1893,7 +1893,7 @@ registerToolConditional(
|
|
|
1893
1893
|
// does not support `cd && `) vs cd && for Linux/macOS.
|
|
1894
1894
|
const servers = await loadServerConfig();
|
|
1895
1895
|
const serverConfig = servers[serverName.toLowerCase()];
|
|
1896
|
-
const workingDir = cwd || serverConfig?.
|
|
1896
|
+
const workingDir = cwd || serverConfig?.defaultDir;
|
|
1897
1897
|
const platform = serverConfig?.platform || 'linux';
|
|
1898
1898
|
let fullCommand;
|
|
1899
1899
|
if (workingDir) {
|
|
@@ -2133,7 +2133,7 @@ registerToolConditional(
|
|
|
2133
2133
|
user: config.user,
|
|
2134
2134
|
port: config.port || '22',
|
|
2135
2135
|
auth: config.password ? 'password' : 'key',
|
|
2136
|
-
defaultDir: config.
|
|
2136
|
+
defaultDir: config.defaultDir || '',
|
|
2137
2137
|
description: config.description || ''
|
|
2138
2138
|
}));
|
|
2139
2139
|
|
|
@@ -2294,9 +2294,9 @@ registerToolConditional(
|
|
|
2294
2294
|
// Add password if provided
|
|
2295
2295
|
if (password) {
|
|
2296
2296
|
fullCommand = `echo "${password}" | sudo -S ${command.replace(/^sudo /, '')}`;
|
|
2297
|
-
} else if (serverConfig?.
|
|
2297
|
+
} else if (serverConfig?.sudoPassword) {
|
|
2298
2298
|
// Use configured sudo password if available
|
|
2299
|
-
fullCommand = `echo "${serverConfig.
|
|
2299
|
+
fullCommand = `echo "${serverConfig.sudoPassword}" | sudo -S ${command.replace(/^sudo /, '')}`;
|
|
2300
2300
|
}
|
|
2301
2301
|
|
|
2302
2302
|
// Add working directory if specified
|
|
@@ -2308,12 +2308,12 @@ registerToolConditional(
|
|
|
2308
2308
|
} else {
|
|
2309
2309
|
fullCommand = `cd ${cwd} && ${fullCommand}`;
|
|
2310
2310
|
}
|
|
2311
|
-
} else if (serverConfig?.
|
|
2311
|
+
} else if (serverConfig?.defaultDir) {
|
|
2312
2312
|
if (platform === 'windows') {
|
|
2313
|
-
const escapedDir = serverConfig.
|
|
2313
|
+
const escapedDir = serverConfig.defaultDir.replace(/'/g, '\'\'');
|
|
2314
2314
|
fullCommand = `Set-Location '${escapedDir}'; ${fullCommand}`;
|
|
2315
2315
|
} else {
|
|
2316
|
-
fullCommand = `cd ${serverConfig.
|
|
2316
|
+
fullCommand = `cd ${serverConfig.defaultDir} && ${fullCommand}`;
|
|
2317
2317
|
}
|
|
2318
2318
|
}
|
|
2319
2319
|
|