Skip to content

Commit 57f4714

Browse files
committed
Fix security concerns
1 parent 00aea8d commit 57f4714

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/mcp/tools/discovery/discover_tools.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,28 @@ interface LLMConfig {
2121
}
2222

2323
// Default LLM configuration with environment variable overrides
24-
const getLLMConfig = (): LLMConfig => ({
25-
maxTokens: process.env.XCODEBUILDMCP_LLM_MAX_TOKENS
26-
? parseInt(process.env.XCODEBUILDMCP_LLM_MAX_TOKENS, 10)
27-
: 200,
28-
temperature: process.env.XCODEBUILDMCP_LLM_TEMPERATURE
29-
? parseFloat(process.env.XCODEBUILDMCP_LLM_TEMPERATURE)
30-
: undefined,
31-
});
24+
const getLLMConfig = (): LLMConfig => {
25+
let maxTokens = 200; // default
26+
if (process.env.XCODEBUILDMCP_LLM_MAX_TOKENS) {
27+
const parsed = parseInt(process.env.XCODEBUILDMCP_LLM_MAX_TOKENS, 10);
28+
if (!isNaN(parsed) && parsed > 0) {
29+
maxTokens = parsed;
30+
}
31+
}
32+
33+
let temperature: number | undefined;
34+
if (process.env.XCODEBUILDMCP_LLM_TEMPERATURE) {
35+
const parsed = parseFloat(process.env.XCODEBUILDMCP_LLM_TEMPERATURE);
36+
if (!isNaN(parsed) && parsed >= 0 && parsed <= 2) {
37+
temperature = parsed;
38+
}
39+
}
40+
41+
return {
42+
maxTokens,
43+
temperature,
44+
};
45+
};
3246

3347
/**
3448
* Sanitizes user input to prevent injection attacks and ensure safe LLM usage

src/mcp/tools/project-scaffolding/scaffold_ios_project.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,7 @@ async function scaffoldProject(
457457
let templatePath;
458458
try {
459459
// Use the default command executor if not provided
460-
if (!commandExecutor) {
461-
commandExecutor = getDefaultCommandExecutor();
462-
}
460+
commandExecutor ??= getDefaultCommandExecutor();
463461

464462
templatePath = await TemplateManager.getTemplatePath(
465463
platform,

src/utils/command.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ async function defaultExecutor(
4343
// For shell execution, we need to format as ['sh', '-c', 'full command string']
4444
const commandString = command
4545
.map((arg) => {
46-
// If the argument contains spaces or special characters, wrap it in quotes
47-
// Ensure existing quotes are escaped
48-
if (/[\s,"'=]/.test(arg) && !/^".*"$/.test(arg)) {
49-
// Check if needs quoting and isn't already quoted
50-
return `"${arg.replace(/(["\\])/g, '\\$1')}"`; // Escape existing quotes and backslashes
46+
// Shell metacharacters that require quoting: space, quotes, equals, dollar, backticks, semicolons, pipes, etc.
47+
if (/[\s,"'=$`;&|<>(){}[\]\\*?~]/.test(arg) && !/^".*"$/.test(arg)) {
48+
// Escape all quotes and backslashes, then wrap in double quotes
49+
return `"${arg.replace(/(["\\])/g, '\\$1')}"`;
5150
}
5251
return arg;
5352
})

0 commit comments

Comments
 (0)