MCPcopy Create free account
hub / github.com/Noumena-Network/code / makeRegexForSafeCommand

Function makeRegexForSafeCommand

src/tools/BashTool/readOnlyValidation.ts:1512–1515  ·  view source on GitHub ↗

* Creates a regex pattern that matches safe invocations of a command. * * The regex ensures commands are invoked safely by blocking: * - Shell metacharacters that could lead to command injection or redirection * - Command substitution via backticks or $() * - Variable expansion that could conta

(command: string)

Source from the content-addressed store, hash-verified

1510 * @returns RegExp that matches safe invocations of the command
1511 */
1512function makeRegexForSafeCommand(command: string): RegExp {
1513 // Create regex pattern: /^command(?:\s|$)[^<>()$`|{}&;\n\r]*$/
1514 return new RegExp(`^${command}(?:\\s|$)[^<>()$\`|{}&;\\n\\r]*$`)
1515}
1516
1517// Simple commands that are safe for execution (converted to regex patterns using makeRegexForSafeCommand)
1518// WARNING: If you are adding new commands here, be very careful to ensure

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected