Skip to content

Commit a5e05fa

Browse files
fix: improved minor sanitizations
1 parent af860e2 commit a5e05fa

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/dockerUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import util from 'util';
33
import { logger } from './logger.ts';
44
import { getConfig } from './config.ts';
55
import { textContent } from './types.ts';
6-
import { sanitizeShellCommand } from './utils.ts';
6+
import { sanitizeContainerId, sanitizeShellCommand } from './utils.ts';
77

88
const execFilePromise = util.promisify(execFile);
99

@@ -19,7 +19,7 @@ export async function forceStopContainer(containerId: string): Promise<void> {
1919
);
2020
try {
2121
// Sanitize containerId
22-
const safeId = sanitizeShellCommand(containerId);
22+
const safeId = sanitizeContainerId(containerId);
2323
if (!safeId) throw new Error('Invalid containerId');
2424
// Force stop the container (ignores errors if already stopped)
2525
await execFilePromise('docker', ['stop', safeId]);

src/tools/exec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
DOCKER_NOT_RUNNING_ERROR,
66
isDockerRunning,
77
sanitizeContainerId,
8+
sanitizeShellCommand,
89
} from '../utils.ts';
910

1011
export const argSchema = {
@@ -19,7 +20,6 @@ export default async function execInSandbox({
1920
container_id: string;
2021
commands: string[];
2122
}): Promise<McpResponse> {
22-
console.log('execInSandbox', container_id);
2323
const validId = sanitizeContainerId(container_id);
2424
if (!validId) {
2525
return {
@@ -35,8 +35,13 @@ export default async function execInSandbox({
3535

3636
const output: string[] = [];
3737
for (const cmd of commands) {
38+
const sanitizedCmd = sanitizeShellCommand(cmd);
39+
if (!sanitizedCmd)
40+
throw new Error(
41+
'Cannot run command as it contains dangerous metacharacters'
42+
);
3843
output.push(
39-
execFileSync('docker', ['exec', validId, '/bin/sh', '-c', cmd], {
44+
execFileSync('docker', ['exec', validId, '/bin/sh', '-c', sanitizedCmd], {
4045
encoding: 'utf8',
4146
})
4247
);

0 commit comments

Comments
 (0)