Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/agents/toml-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('toml-loader', () => {
const filePath = await writeAgentToml(`
name = "test-agent"
description = "A test agent"
tools = ["not-a-tool"]
tools = ["tool!"]
[prompts]
system_prompt = "You are a test agent."
`);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/tools/tool-names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ describe('tool-names', () => {
expect(isValidToolName('my-server__my-tool')).toBe(true);
});

it('should validate generic slug names (unprefixed tools)', () => {
expect(isValidToolName('search_for_files_codesearch')).toBe(true);
expect(isValidToolName('simple-tool-name')).toBe(true);
expect(isValidToolName('tool_with_underscores')).toBe(true);
});

it('should reject invalid tool names', () => {
expect(isValidToolName('')).toBe(false);
expect(isValidToolName('invalid-name')).toBe(false);
expect(isValidToolName('server__')).toBe(false);
expect(isValidToolName('__tool')).toBe(false);
expect(isValidToolName('server__tool__extra')).toBe(false);
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/tools/tool-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ export function isValidToolName(
return slugRegex.test(server) && slugRegex.test(tool);
}

return false;
// Allow any valid slug to support unprefixed MCP tools or other dynamic tools
const slugRegex = /^[a-z0-9-_]+$/i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current regex allows tool names like constructor and prototype. If these tool names are later used as keys in plain JavaScript objects, this could lead to prototype pollution vulnerabilities. It's safer to explicitly disallow these names in the regex.

Note that the same vulnerability exists for the namespaced tool validation on line 87. While that line is not part of this diff, it should also be updated to prevent this vulnerability for namespaced tools (e.g., server__constructor).

Suggested change
const slugRegex = /^[a-z0-9-_]+$/i;
const slugRegex = /^(?!(?:constructor|prototype)$)[a-z0-9-_]+$/i;

return slugRegex.test(name);
}