{"record":{"id":"ef725088e4fd7fd6","repo":"FlowiseAI/Flowise","slug":"argument-contains-potentially-dangerous-characters","errorCode":null,"errorMessage":"Argument contains potentially dangerous characters: \"${arg}\"","messagePattern":"Argument contains potentially dangerous characters: \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/tools/MCP/core.ts","lineNumber":281,"sourceCode":"    const dangerousPatterns = [\n        // Shell metacharacters\n        /[;&|`$(){}[\\]<>]/,\n        // Command chaining\n        /&&|\\|\\||;;/,\n        // Redirections\n        />>|<<|>/,\n        // Backticks and command substitution\n        /`|\\$\\(/,\n        // Process substitution\n        /<\\(|>\\(/\n    ]\n\n    for (const arg of args) {\n        if (typeof arg !== 'string') continue\n\n        for (const pattern of dangerousPatterns) {\n            if (pattern.test(arg)) {\n                throw new Error(`Argument contains potentially dangerous characters: \"${arg}\"`)\n            }\n        }\n    }\n}\n\n/**\n * Validates user-supplied env vars against the operator-controlled allow-list in\n * `CUSTOM_MCP_ALLOWED_ENV_VARS` (comma-separated names). Empty = none allowed.\n */\nexport const validateEnvironmentVariables = (env: Record<string, any>): void => {\n    const allowedEnvVars = new Set(\n        (process.env.CUSTOM_MCP_ALLOWED_ENV_VARS ?? '')\n            .split(',')\n            .map((s) => s.trim())\n            .filter(Boolean)\n    )\n\n    for (const [key, value] of Object.entries(env)) {","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/tools/MCP/core.ts#L263-L299","documentation":"Thrown by validateCommandInjection when any string arg matches one of the dangerousPatterns regexes: shell metacharacters [;&|`$(){}[\\]<>], command chaining (&&, ||, ;;), redirections (>>, <<, >), backticks/$(, or process substitution <( >(. The guard rejects args before they reach StdioClientTransport to prevent shell injection through MCP command arguments.","triggerScenarios":"validateCommandInjection(args) called from validateMCPServerConfig when serverParams.args is a non-empty array and any element contains a matched metacharacter. Reachable from any MCP node whose user input flows into args (e.g. Supergateway _args string).","commonSituations":"User types a command-like argument such as 'server.js; rm -rf /', pipes 'a | b', env expansion '$HOME', or redirection in the node's arguments field; a value legitimately containing parentheses or brackets (e.g. a JSON snippet) is passed as an arg.","solutions":["Strip or URL-encode shell metacharacters from user input before it becomes an MCP arg.","Pass structured values via env vars (allow-listed) rather than as command args.","If a legitimate arg needs characters like '(' or '{', base64-encode it and decode inside the script, or move the data out of args entirely."],"exampleFix":"// before: user input passed raw\nconst processedArgs = userInput.trim().split(/\\s+/)\n\n// after: reject/encode metacharacters up front\nconst safe = userInput.replace(/[;&|`$(){}[\\]<>]/g, '')\nconst processedArgs = safe.trim().split(/\\s+/)","handlingStrategy":"validation","validationCode":"const dangerous = arg => /[;&|`$(){}[\\]<>]/.test(arg) || /&&|\\|\\|;;/.test(arg) || />>|<<|>/.test(arg) || /`|\\$\\(/.test(arg) || /<\\(|>\\(/.test(arg)\nif (args.some(a => typeof a === 'string' && dangerous(a))) {\n  throw new Error('Rejecting args containing shell metacharacters')\n}","typeGuard":"const argsAreSafe = (args: string[]): boolean => !args.some(a => typeof a === 'string' && (/[;&|`$(){}[\\]<>]/.test(a) || /&&|\\|\\|;;/.test(a) || />>|<<|>/.test(a) || /`|\\$\\(/.test(a) || /<\\(|>\\(/.test(a)))","tryCatchPattern":"try {\n  validateCommandInjection(args)\n} catch (e) {\n  if (e.message.startsWith('Argument contains potentially dangerous characters')) {\n    // sanitize or reject the offending arg before retrying\n  }\n  throw e\n}","preventionTips":["Never pass free-form user text as command args; encode or move to env vars.","Run validateCommandInjection on user input at the UI boundary for early feedback.","Prefer structured config over string args."],"tags":["mcp","security","injection","validation"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}