Skip to content

Commit 5a4806f

Browse files
petejmPeter McDadeclaude
authored
security: restrict set_config_value to known configuration keys (#353)
Add an allowlist of keys that can be set via the set_config_value MCP tool. Previously, any key could be set — including internal keys like clientId, usageStats, and abTest_* flags — because the ServerConfig interface uses `[key: string]: any`. This prevents a prompt injection or malicious MCP client from tampering with internal state. Internal keys are still writable by the server itself via configManager.setValue() directly; only the client-facing tool handler is restricted. Allowed keys: blockedCommands, allowedDirectories, defaultShell, telemetryEnabled, fileReadLineLimit, fileWriteLineLimit. Co-authored-by: Peter McDade <pmcdade@pmcdadePersonal.pmcdade.org> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7090a5d commit 5a4806f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/tools/config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ export async function getConfig() {
5555
}
5656
}
5757

58+
// Keys that can be set via the set_config_value MCP tool.
59+
// Internal keys (clientId, usageStats, abTest_*, onboardingState, etc.)
60+
// are managed by the server itself and should not be settable by clients.
61+
const ALLOWED_CONFIG_KEYS = new Set([
62+
'blockedCommands',
63+
'allowedDirectories',
64+
'defaultShell',
65+
'telemetryEnabled',
66+
'fileReadLineLimit',
67+
'fileWriteLineLimit',
68+
]);
69+
5870
/**
5971
* Set a specific config value
6072
*/
@@ -73,6 +85,16 @@ export async function setConfigValue(args: unknown) {
7385
};
7486
}
7587

88+
if (!ALLOWED_CONFIG_KEYS.has(parsed.data.key)) {
89+
return {
90+
content: [{
91+
type: "text",
92+
text: `Key "${parsed.data.key}" is not configurable via this tool. Allowed keys: ${[...ALLOWED_CONFIG_KEYS].join(', ')}`
93+
}],
94+
isError: true
95+
};
96+
}
97+
7698
try {
7799
// Parse string values that should be arrays or objects
78100
let valueToStore = parsed.data.value;

0 commit comments

Comments
 (0)