{"record":{"id":"f68749257552e394","repo":"Tencent/WeKnora","slug":"environment-variable-s-value-contains-potential","errorCode":null,"errorMessage":"environment variable '%s' value contains potentially dangerous pattern","messagePattern":"environment variable '(.+?)' value contains potentially dangerous pattern","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/utils/security.go","lineNumber":620,"sourceCode":"\t\t// Check key length\n\t\tif len(key) > 256 {\n\t\t\treturn fmt.Errorf(\"environment variable name '%s' exceeds maximum length\", SanitizeForLog(key[:50]))\n\t\t}\n\n\t\t// Check value length\n\t\tif len(value) > 4096 {\n\t\t\treturn fmt.Errorf(\"environment variable '%s' value exceeds maximum length\", key)\n\t\t}\n\n\t\t// Check for null bytes in value\n\t\tif strings.Contains(value, \"\\x00\") {\n\t\t\treturn fmt.Errorf(\"environment variable '%s' value contains null bytes\", key)\n\t\t}\n\n\t\t// Check value for shell injection patterns\n\t\tfor _, pattern := range DangerousArgPatterns {\n\t\t\tif pattern.MatchString(value) {\n\t\t\t\treturn fmt.Errorf(\"environment variable '%s' value contains potentially dangerous pattern\", key)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// ValidateStdioConfig performs comprehensive validation of stdio configuration\n// This should be called before creating or executing any stdio-based MCP client\nfunc ValidateStdioConfig(command string, args []string, envVars map[string]string) error {\n\t// Validate command\n\tif err := ValidateStdioCommand(command); err != nil {\n\t\treturn fmt.Errorf(\"invalid command: %w\", err)\n\t}\n\n\t// Validate arguments\n\tif err := ValidateStdioArgs(args); err != nil {\n\t\treturn fmt.Errorf(\"invalid arguments: %w\", err)","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/utils/security.go#L602-L638","documentation":"ValidateStdioEnvVars checks each environment variable value against the DangerousArgPatterns regex list and rejects values matching shell metacharacter / injection patterns. This prevents env values from being abused for shell injection when the child process or its launcher interpolates them into a shell command. It is a deliberate security gate, not a bug.","triggerScenarios":"Calling ValidateStdioConfig (or ValidateStdioEnvVars directly) where any env value matches one of the DangerousArgPatterns regexes (e.g. backticks, $(), ;, |, &&).","commonSituations":"Config files where values were meant to be executed by a shell, values copied from shell scripts with $(...) substitutions, or tampered/attacker-supplied configuration.","solutions":["Remove shell metacharacters from the value; pass the literal value (the command is executed directly, not via a shell).","Precompute the value (run the substitution yourself and store the result).","Review DangerousArgPatterns in internal/utils/security.go to see which pattern matched and adjust the value."],"exampleFix":"// before\nenvVars[\"LOG_DIR\"] = \"$(pwd)/logs\"\nerr := secutils.ValidateStdioConfig(cmd, args, envVars)\n// after\nenvVars[\"LOG_DIR\"] = \"/abs/path/to/logs\"\nerr := secutils.ValidateStdioConfig(cmd, args, envVars)","handlingStrategy":"validation","validationCode":"for _, v := range envVars {\n    for _, p := range secutils.DangerousArgPatterns {\n        if p.MatchString(v) { return fmt.Errorf(\"unsafe env value: %q\", v) }\n    }\n}","typeGuard":"func isShellSafe(v string) bool {\n    for _, p := range secutils.DangerousArgPatterns {\n        if p.MatchString(v) { return false }\n    }\n    return true\n}","tryCatchPattern":"err := secutils.ValidateStdioConfig(cmd, args, env)\nif err != nil && strings.Contains(err.Error(), \"dangerous pattern\") {\n    return fmt.Errorf(\"env var rejected by security policy: %w\", err)\n}","preventionTips":["Store literal values in env vars, never shell expressions like $(...).","Precompute dynamic values before writing config.","Document that env values are passed directly to exec, not through a shell."],"tags":["security","shell-injection","validation","stdio"],"backgroundTag":"shell-injection-detected","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}