Tencent/WeKnora · error

command path contains invalid characters

Error message

command path contains invalid characters

What it means

After passing the whitelist, ValidateStdioCommand performs a final check that the raw command string contains no ".." path-traversal segments. This blocks tricks where a whitelisted base name is embedded in a traversal path. The error text is generic ("invalid characters") but specifically means ".." was found.

Source

Thrown at internal/utils/security.go:552

	if command == "" {
		return fmt.Errorf("command cannot be empty")
	}

	// Normalize command (extract base name if it's a path)
	baseCommand := command
	if strings.Contains(command, "/") {
		parts := strings.Split(command, "/")
		baseCommand = parts[len(parts)-1]
	}

	// Check against whitelist
	if !AllowedStdioCommands[baseCommand] {
		return fmt.Errorf("command '%s' is not in the allowed list. Allowed commands: uvx, npx, node, python, python3, deno, bun", baseCommand)
	}

	// Additional check: command should not contain path traversal
	if strings.Contains(command, "..") {
		return fmt.Errorf("command path contains invalid characters")
	}

	return nil
}

// ValidateStdioArgs validates the arguments for MCP stdio transport
// Returns an error if any argument contains dangerous patterns
func ValidateStdioArgs(args []string) error {
	if len(args) == 0 {
		return nil
	}

	for i, arg := range args {
		// Check length
		if len(arg) > 1024 {
			return fmt.Errorf("argument %d exceeds maximum length (1024 characters)", i)
		}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Remove ".." from the command path; use an absolute path whose base name is whitelisted (e.g. /usr/bin/node) or just the bare command name and rely on PATH
  2. Use path.Clean/filepath.Clean to normalize the path and confirm no ".." remains
  3. Prefer launching via the bare command name ("node") so the OS PATH resolution is used

Example fix

// before
{"command": "../bin/node", "args": ["server.js"]}
// after
{"command": "node", "args": ["server.js"]}
Defensive patterns

Strategy: validation

Validate before calling

if strings.Contains(cfg.Command, "..") {
    return fmt.Errorf("command path must not contain '..'")
}
err := ValidateStdioConfig(cfg)

Try / catch

if err := ValidateStdioConfig(cfg); err != nil {
    if strings.Contains(err.Error(), "invalid characters") {
        return fmt.Errorf("command %q contains traversal segments; use bare name or absolute path", cfg.Command)
    }
    return err
}

Prevention

When it happens

Trigger: ValidateStdioConfig called with a command such as "../node", "npx/../node", or any string containing ".." whose base name still matches the whitelist.

Common situations: Relative paths written from a config directory; hand-built command strings joining directories with ".."; copy-pasted paths from shell history with dot-dot segments.

Understand the failure class

Related errors


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