@codegiveness/mssql-mcp 0.5.1 → 0.5.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/bin/mssql-mcp.js +80 -7
- package/package.json +7 -7
package/bin/mssql-mcp.js
CHANGED
|
@@ -63,7 +63,21 @@ function parseChecksumFile(text) {
|
|
|
63
63
|
|
|
64
64
|
// Follow up to 3 HTTP redirects (GitHub releases redirect to S3/CDN).
|
|
65
65
|
// Hard depth limit prevents redirect loops from hanging or stack-overflowing.
|
|
66
|
+
// Redirect hosts are pinned to GitHub infrastructure: a MITM/DNS-rebind that
|
|
67
|
+
// redirects to an attacker host is refused before the connection is opened.
|
|
66
68
|
const MAX_REDIRECTS = 3;
|
|
69
|
+
const REDIRECT_HOST_ALLOWLIST = [
|
|
70
|
+
'github.com',
|
|
71
|
+
'objects.githubusercontent.com',
|
|
72
|
+
'github-releases.githubusercontent.com',
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
function isAllowedRedirectHost(host) {
|
|
76
|
+
if (!host) return false;
|
|
77
|
+
const h = host.toLowerCase();
|
|
78
|
+
if (REDIRECT_HOST_ALLOWLIST.indexOf(h) !== -1) return true;
|
|
79
|
+
return h.endsWith('.githubusercontent.com');
|
|
80
|
+
}
|
|
67
81
|
|
|
68
82
|
function fetchUrl(url, depth) {
|
|
69
83
|
if (depth === undefined) depth = 0;
|
|
@@ -75,7 +89,12 @@ function fetchUrl(url, depth) {
|
|
|
75
89
|
const req = https.get(url, (res) => {
|
|
76
90
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
77
91
|
res.resume();
|
|
78
|
-
|
|
92
|
+
const next = new URL(res.headers.location, url);
|
|
93
|
+
if (!isAllowedRedirectHost(next.hostname)) {
|
|
94
|
+
reject(new Error('Refusing to follow redirect to untrusted host: ' + next.hostname));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
fetchUrl(next.href, depth + 1).then(resolve, reject);
|
|
79
98
|
return;
|
|
80
99
|
}
|
|
81
100
|
if (res.statusCode !== 200) {
|
|
@@ -95,6 +114,39 @@ function fetchUrl(url, depth) {
|
|
|
95
114
|
}
|
|
96
115
|
|
|
97
116
|
function extractTarGz(archivePath, outDir) {
|
|
117
|
+
// Validate entry names before extraction to prevent path traversal (Tar Slip).
|
|
118
|
+
// `tar -xzf` alone may strip leading ../ on modern GNU tar but does not provide
|
|
119
|
+
// a portable app-level guarantee — defense-in-depth requires the application
|
|
120
|
+
// reject traversal entries explicitly. Mirrors extractZip's prefix check and
|
|
121
|
+
// additionally rejects symlink/hardlink entries, which tar can write outside
|
|
122
|
+
// the target dir (a vector zip does not have).
|
|
123
|
+
const list = spawnSync('tar', ['-tzf', archivePath], { encoding: 'utf8' });
|
|
124
|
+
if (list.status !== 0) {
|
|
125
|
+
throw new Error('tar -tzf failed with status ' + list.status);
|
|
126
|
+
}
|
|
127
|
+
for (const name of list.stdout.split('\n')) {
|
|
128
|
+
const entry = name.trim();
|
|
129
|
+
if (!entry) continue;
|
|
130
|
+
if (entry.startsWith('/') || entry.indexOf('..') !== -1) {
|
|
131
|
+
throw new Error('Refusing to extract tar entry outside target directory: ' + entry);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Inspect entry metadata (permissions field) to reject symlinks/hardlinks.
|
|
136
|
+
// GNU tar `--test-label`/`-tv` first column: `lrwxrwxrwx` symlink, `hrwxr-xr-x`
|
|
137
|
+
// hardlink, `-rw-r--r--` regular file. The first char is the type flag.
|
|
138
|
+
const verbose = spawnSync('tar', ['-tvf', archivePath], { encoding: 'utf8' });
|
|
139
|
+
if (verbose.status !== 0) {
|
|
140
|
+
throw new Error('tar -tvf failed with status ' + verbose.status);
|
|
141
|
+
}
|
|
142
|
+
for (const line of verbose.stdout.split('\n')) {
|
|
143
|
+
if (!line) continue;
|
|
144
|
+
const typeFlag = line[0];
|
|
145
|
+
if (typeFlag === 'l' || typeFlag === 'h') {
|
|
146
|
+
throw new Error('Refusing to extract tar entry of type ' + typeFlag + ': ' + line.trim());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
98
150
|
const r = spawnSync('tar', ['-xzf', archivePath, '-C', outDir], { stdio: 'inherit' });
|
|
99
151
|
if (r.status !== 0) {
|
|
100
152
|
throw new Error('tar exited with status ' + r.status);
|
|
@@ -172,15 +224,32 @@ async function main() {
|
|
|
172
224
|
}
|
|
173
225
|
|
|
174
226
|
// Check if a cached binary exists at ~/.mssql-mcp/bin/<version>/<rid>/mssql-mcp[.exe]
|
|
175
|
-
|
|
227
|
+
// and re-verify its SHA256 against a sidecar file before trusting it. Prevents
|
|
228
|
+
// cache poisoning: a tampered binary (or a tampered/missing sidecar) is treated
|
|
229
|
+
// as a cache miss and re-downloaded.
|
|
230
|
+
function resolveCachedBinary(rid, cacheRoot) {
|
|
231
|
+
const root = cacheRoot || CACHE_ROOT;
|
|
176
232
|
const pkg = require('../package.json');
|
|
177
233
|
const version = pkg.version;
|
|
178
234
|
const binaryName = process.platform === 'win32' ? 'mssql-mcp.exe' : 'mssql-mcp';
|
|
179
|
-
const cachedPath = path.join(
|
|
180
|
-
if (fs.existsSync(cachedPath)) {
|
|
181
|
-
return
|
|
235
|
+
const cachedPath = path.join(root, version, rid, binaryName);
|
|
236
|
+
if (!fs.existsSync(cachedPath)) {
|
|
237
|
+
return null;
|
|
182
238
|
}
|
|
183
|
-
|
|
239
|
+
const sidecarPath = cachedPath + '.sha256';
|
|
240
|
+
if (!fs.existsSync(sidecarPath)) {
|
|
241
|
+
// No recorded checksum — cannot trust the cached binary. Treat as miss.
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
const expected = parseChecksumFile(fs.readFileSync(sidecarPath, 'utf8'));
|
|
245
|
+
const actual = sha256Hex(fs.readFileSync(cachedPath));
|
|
246
|
+
if (expected !== actual) {
|
|
247
|
+
// Tampered or corrupted cache. Purge and re-download.
|
|
248
|
+
try { fs.rmSync(cachedPath, { force: true }); } catch (_) { /* best effort */ }
|
|
249
|
+
try { fs.rmSync(sidecarPath, { force: true }); } catch (_) { /* best effort */ }
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
return cachedPath;
|
|
184
253
|
}
|
|
185
254
|
|
|
186
255
|
// Attempt self-heal download. Returns the binary path on success, or exits
|
|
@@ -263,6 +332,10 @@ async function selfHealOrDie(rid) {
|
|
|
263
332
|
fs.chmodSync(cachedBinaryPath, 0o755);
|
|
264
333
|
}
|
|
265
334
|
|
|
335
|
+
// Record the verified binary's checksum alongside it so future cache hits
|
|
336
|
+
// can re-verify integrity (resolveCachedBinary reads this sidecar).
|
|
337
|
+
fs.writeFileSync(cachedBinaryPath + '.sha256', sha256Hex(fs.readFileSync(cachedBinaryPath)));
|
|
338
|
+
|
|
266
339
|
console.error('mssql-mcp: cached binary to ' + cachedBinaryPath);
|
|
267
340
|
} finally {
|
|
268
341
|
try {
|
|
@@ -359,7 +432,7 @@ function failWindowsDotNetMissing(spawnError) {
|
|
|
359
432
|
}
|
|
360
433
|
|
|
361
434
|
// Exposed for smoke tests (npm/test.js). Not part of the public API.
|
|
362
|
-
module.exports = { ridFor, archiveExt, parseChecksumFile, classifyDownloadError, sha256Hex };
|
|
435
|
+
module.exports = { ridFor, archiveExt, parseChecksumFile, classifyDownloadError, sha256Hex, extractTarGz, fetchUrl, isAllowedRedirectHost, resolveCachedBinary };
|
|
363
436
|
|
|
364
437
|
// Run main() only when invoked directly (not when required by test.js).
|
|
365
438
|
if (require.main === module) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codegiveness/mssql-mcp",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "A Model Context Protocol (MCP) server for Microsoft SQL Server, built in C#/.NET 10",
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "A Model Context Protocol (MCP) server for Microsoft SQL Server, built in C#/.NET 10. Lets AI agents (Claude Desktop, Cursor, etc.) safely query and interact with SQL Server databases through a controlled tool surface.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/codegiveness/mssql-mcp#readme",
|
|
7
7
|
"keywords": [
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"bin/mssql-mcp.js"
|
|
28
28
|
],
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"@codegiveness/mssql-mcp-linux-x64": "0.5.
|
|
31
|
-
"@codegiveness/mssql-mcp-linux-arm64": "0.5.
|
|
32
|
-
"@codegiveness/mssql-mcp-osx-x64": "0.5.
|
|
33
|
-
"@codegiveness/mssql-mcp-osx-arm64": "0.5.
|
|
34
|
-
"@codegiveness/mssql-mcp-win-x64": "0.5.
|
|
30
|
+
"@codegiveness/mssql-mcp-linux-x64": "0.5.2",
|
|
31
|
+
"@codegiveness/mssql-mcp-linux-arm64": "0.5.2",
|
|
32
|
+
"@codegiveness/mssql-mcp-osx-x64": "0.5.2",
|
|
33
|
+
"@codegiveness/mssql-mcp-osx-arm64": "0.5.2",
|
|
34
|
+
"@codegiveness/mssql-mcp-win-x64": "0.5.2"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=18"
|