Tencent/WeKnora · error

invalid command: %w

Error message

invalid command: %w

What it means

ValidateStdioConfig wraps any error from ValidateStdioCommand with the prefix 'invalid command: %w'. The inner error explains the specific reason — e.g. empty command, path traversal, disallowed binary, or dangerous pattern in the command. Check errors.Unwrap/Is to reach the cause.

Source

Thrown at internal/utils/security.go:633

		}

		// 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)
			}
		}
	}

	return nil
}

// ValidateStdioConfig performs comprehensive validation of stdio configuration
// This should be called before creating or executing any stdio-based MCP client
func ValidateStdioConfig(command string, args []string, envVars map[string]string) error {
	// Validate command
	if err := ValidateStdioCommand(command); err != nil {
		return fmt.Errorf("invalid command: %w", err)
	}

	// Validate arguments
	if err := ValidateStdioArgs(args); err != nil {
		return fmt.Errorf("invalid arguments: %w", err)
	}

	// Validate environment variables
	if err := ValidateStdioEnvVars(envVars); err != nil {
		return fmt.Errorf("invalid environment variables: %w", err)
	}

	return nil
}

// SSRFSafeHTTPClientConfig contains configuration for the SSRF-safe HTTP client
type SSRFSafeHTTPClientConfig struct {
	Timeout            time.Duration

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Inspect the wrapped error (errors.Unwrap or %v) to see the specific ValidateStdioCommand reason.
  2. Use a plain executable name or an allowed absolute path with no shell metacharacters.
  3. Move extra tokens into the args []string parameter rather than embedding them in the command string.
  4. Verify the command exists and is permitted (PATH lookup / allowlist) before validation.

Example fix

// before
err := secutils.ValidateStdioConfig("python -m server", nil, env)
// after
err := secutils.ValidateStdioConfig("python", []string{"-m", "server"}, env)
Defensive patterns

Strategy: validation

Validate before calling

if command == "" { return errors.New("command is required") }
if strings.ContainsAny(command, ";|&`$\\") { return errors.New("command must be a plain executable") }
if _, err := exec.LookPath(command); err != nil { return fmt.Errorf("command not found: %w", err) }

Type guard

func isValidCommand(cmd string) bool {
    return cmd != "" && !strings.ContainsAny(cmd, ";|&`$\\")
}

Try / catch

if err := secutils.ValidateStdioConfig(cmd, args, env); err != nil {
    return fmt.Errorf("stdio config rejected: %w", err) // Unwrap for the specific cause
}

Prevention

When it happens

Trigger: Calling ValidateStdioConfig with a command string that fails ValidateStdioCommand: empty string, path-traversal paths, disallowed executables, or commands matching dangerous patterns.

Common situations: Typo in the binary name, configuring a command not on the allowed list, or storing a full shell line (e.g. "python -m foo") in the command field instead of separating args.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/0df9ba06688aa181. Report an issue: GitHub.