FlowiseAI/Flowise · error · Error
Environment variable '${key}' contains null byte
Error message
Environment variable '${key}' contains null byte What it means
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.
Source
Thrown at packages/components/nodes/tools/MCP/core.ts:305
/**
* Validates user-supplied env vars against the operator-controlled allow-list in
* `CUSTOM_MCP_ALLOWED_ENV_VARS` (comma-separated names). Empty = none allowed.
*/
export const validateEnvironmentVariables = (env: Record<string, any>): void => {
const allowedEnvVars = new Set(
(process.env.CUSTOM_MCP_ALLOWED_ENV_VARS ?? '')
.split(',')
.map((s) => s.trim())
.filter(Boolean)
)
for (const [key, value] of Object.entries(env)) {
if (!allowedEnvVars.has(key)) {
throw new Error(`Environment variable '${key}' is not allowed. Permitted: ${[...allowedEnvVars].join(', ') || '(none)'}`)
}
if (typeof value === 'string' && value.includes('\0')) {
throw new Error(`Environment variable '${key}' contains null byte`)
}
}
}
/**
* Validates that command arguments don't contain flags that enable arbitrary code execution
* This prevents attacks where whitelisted commands are used with dangerous flags
* (e.g., "npx -c malicious-command" or "python -c malicious-code")
* @param command The command to validate
* @param args The arguments to validate
*/
export const validateCommandFlags = (command: string, args: string[]): void => {
// Define dangerous flags for each command that enable code execution
const dangerousFlagsByCommand: Record<string, string[]> = {
npx: [
'-c', // Execute shell commands
'--call', // Execute shell commands
'--shell-auto-fallback', // Shell execution fallbackView on GitHub (pinned to abe4a8601a)
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.
Example fix
// before env['API_KEY'] = rawToken // contains '\0' // after env['API_KEY'] = String(rawToken).replace(/\0/g, '')
Defensive patterns
Strategy: validation
Validate before calling
for (const [k, v] of Object.entries(env)) {
if (typeof v === 'string' && v.includes('\0')) {
throw new Error(`Refusing to forward env var '${k}': contains null byte`)
}
} Type guard
const envValuesHaveNoNullBytes = (env: Record<string, any>): boolean =>
Object.values(env).every(v => typeof v !== 'string' || !v.includes('\0')) Try / catch
try {
validateEnvironmentVariables(env)
} catch (e) {
if (e.message.includes('contains null byte')) {
// strip null bytes from the named value before retrying
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Argument contains potentially dangerous characters: "${arg}"
- Environment variable '${key}' is not allowed. Permitted: ${[
- Argument '${arg}' is not allowed for command '${command}'.
- Argument '${arg}' contains flag '${flag}' that is not allowe
- Argument '${arg}' contains dangerous flag '-${ch}' for comma
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/55511c3e0d6cb20f.
Report an issue: GitHub.