{"record":{"id":"55511c3e0d6cb20f","repo":"FlowiseAI/Flowise","slug":"environment-variable-key-contains-null-byte","errorCode":null,"errorMessage":"Environment variable '${key}' contains null byte","messagePattern":"Environment variable '(.+?)' contains null byte","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/tools/MCP/core.ts","lineNumber":305,"sourceCode":"/**\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)) {\n        if (!allowedEnvVars.has(key)) {\n            throw new Error(`Environment variable '${key}' is not allowed. Permitted: ${[...allowedEnvVars].join(', ') || '(none)'}`)\n        }\n\n        if (typeof value === 'string' && value.includes('\\0')) {\n            throw new Error(`Environment variable '${key}' contains null byte`)\n        }\n    }\n}\n\n/**\n * Validates that command arguments don't contain flags that enable arbitrary code execution\n * This prevents attacks where whitelisted commands are used with dangerous flags\n * (e.g., \"npx -c malicious-command\" or \"python -c malicious-code\")\n * @param command The command to validate\n * @param args The arguments to validate\n */\nexport const validateCommandFlags = (command: string, args: string[]): void => {\n    // Define dangerous flags for each command that enable code execution\n    const dangerousFlagsByCommand: Record<string, string[]> = {\n        npx: [\n            '-c', // Execute shell commands\n            '--call', // Execute shell commands\n            '--shell-auto-fallback', // Shell execution fallback","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/tools/MCP/core.ts#L287-L323","documentation":"Thrown by validateEnvironmentVariables after a key passes the allow-list but its string value contains a null byte ('\\0'). Null bytes can truncate or manipulate strings in C-based process environments and are a classic poisoning vector, so the validator rejects them outright.","triggerScenarios":"A string value in serverParams.env includes the literal '\\0' character. Could come from binary/encoded user input, malformed base64 decoding, or a malicious payload designed to terminate a string early.","commonSituations":"User pastes a value with embedded control characters; a token or secret was decoded from base64/hex with trailing null bytes; test fixtures containing raw bytes.","solutions":["Sanitize env values by stripping null bytes before assigning: value.replace(/\\0/g, '').","Validate input encoding at the source (reject non-printable characters in secret fields).","Re-issue the token/secret if it legitimately cannot be represented without null bytes."],"exampleFix":"// before\nenv['API_KEY'] = rawToken // contains '\\0'\n\n// after\nenv['API_KEY'] = String(rawToken).replace(/\\0/g, '')","handlingStrategy":"validation","validationCode":"for (const [k, v] of Object.entries(env)) {\n  if (typeof v === 'string' && v.includes('\\0')) {\n    throw new Error(`Refusing to forward env var '${k}': contains null byte`)\n  }\n}","typeGuard":"const envValuesHaveNoNullBytes = (env: Record<string, any>): boolean =>\n  Object.values(env).every(v => typeof v !== 'string' || !v.includes('\\0'))","tryCatchPattern":"try {\n  validateEnvironmentVariables(env)\n} catch (e) {\n  if (e.message.includes('contains null byte')) {\n    // strip null bytes from the named value before retrying\n  }\n  throw e\n}","preventionTips":["Sanitize all secret/token inputs by stripping control characters at ingestion.","Validate base64/hex decoding produces printable strings before storing.","Reject non-printable characters in credential fields at the UI layer."],"tags":["mcp","security","env","injection"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}