Tencent/WeKnora · error
environment variable name '%s' exceeds maximum length
Error message
environment variable name '%s' exceeds maximum length
What it means
ValidateStdioEnvVars limits environment-variable NAME length to 256 characters. Overly long names are rejected to prevent abuse and platform limitations. Note the message logs only the first 50 characters (SanitizeForLog(key[:50])).
Source
Thrown at internal/utils/security.go:604
// ValidateStdioEnvVars validates environment variables for MCP stdio transport
// Returns an error if any env var name or value is dangerous
func ValidateStdioEnvVars(envVars map[string]string) error {
if len(envVars) == 0 {
return nil
}
for key, value := range envVars {
// Check key against dangerous patterns
for _, pattern := range DangerousEnvVarPatterns {
if pattern.MatchString(key) {
return fmt.Errorf("environment variable '%s' is not allowed for security reasons", key)
}
}
// Check key length
if len(key) > 256 {
return fmt.Errorf("environment variable name '%s' exceeds maximum length", SanitizeForLog(key[:50]))
}
// Check value length
if len(value) > 4096 {
return fmt.Errorf("environment variable '%s' value exceeds maximum length", key)
}
// Check for null bytes in value
if strings.Contains(value, "\x00") {
return fmt.Errorf("environment variable '%s' value contains null bytes", key)
}
// Check value for shell injection patterns
for _, pattern := range DangerousArgPatterns {
if pattern.MatchString(value) {
return fmt.Errorf("environment variable '%s' value contains potentially dangerous pattern", key)
}
}View on GitHub (pinned to 988cbb0330)
Solutions
- Shorten the variable name to a conventional short identifier (<=256 chars, typically <64)
- Check whether a value was accidentally placed as a key (key containing '=' or very long text) and restructure the map
- Validate env keys against ^[A-Za-z_][A-Za-z0-9_]*$ before building the config
Example fix
// before
"env": {"MY_VERY_LONGGenerated_KEY_NAME_that_goes_on_and_on_for_300_chars...": "v"}
// after
"env": {"MY_KEY": "v"} Defensive patterns
Strategy: validation
Validate before calling
for k := range cfg.Env {
if len(k) > 256 {
return fmt.Errorf("env key too long (%d > 256): %.50q", len(k), k)
}
if !regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`).MatchString(k) {
return fmt.Errorf("env key %q is not a valid identifier", k)
}
} Try / catch
if err := ValidateStdioConfig(cfg); err != nil {
if strings.Contains(err.Error(), "exceeds maximum length") {
return fmt.Errorf("fix env map — a value was likely placed in the key position: %w", err)
}
return err
} Prevention
- Use conventional short env var names
- Check for paste errors where 'KEY=value' was inserted as a whole key
- Validate keys with an identifier regex before building the config
When it happens
Trigger: ValidateStdioConfig called with an env map containing a key longer than 256 bytes — usually from malformed configs or generated keys.
Common situations: Copy-paste errors where a value was accidentally placed in the key position ("API_KEY=secret" pasted as a whole line); programmatically generated env keys embedding long identifiers; corrupted config files.
Related errors
- environment variable '%s' value exceeds maximum length
- argument %d exceeds maximum length (1024 characters)
- command cannot be empty
- argument %d contains null bytes
- environment variable '%s' is not allowed for security reason
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/b29aa1bf7d034eb0.
Report an issue: GitHub.