Tencent/WeKnora · error

argument %d contains potentially dangerous pattern: %s

Error message

argument %d contains potentially dangerous pattern: %s

What it means

ValidateStdioArgs checks each argument against a list of DangerousArgPatterns regexes (shell metacharacters, injection patterns, etc.). If an argument matches any pattern it is rejected, with the argument echoed through SanitizeForLog to avoid log injection. This guards against arguments that could enable command injection when the process is spawned.

Source

Thrown at internal/utils/security.go:574

}

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

		// Check against dangerous patterns
		for _, pattern := range DangerousArgPatterns {
			if pattern.MatchString(arg) {
				return fmt.Errorf("argument %d contains potentially dangerous pattern: %s", i, SanitizeForLog(arg))
			}
		}

		// Check for null bytes
		if strings.Contains(arg, "\x00") {
			return fmt.Errorf("argument %d contains null bytes", i)
		}
	}

	return nil
}

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

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Remove or escape the dangerous characters from the argument; pass values as single argv entries without shell interpretation
  2. If the pattern is a false positive (e.g. a legitimate package spec like "foo@1.0|bar"), restructure the value (use quotes in the underlying tool's own syntax, or a config file) rather than embedding shell syntax
  3. Review DangerousArgPatterns in internal/utils/security.go to see which regex matched and adjust the argument accordingly
  4. Pass complex inputs via a file or environment variable instead of the command line

Example fix

// before
"args": ["--query", "name; rm -rf /"]
// after
"args": ["--query", "name"] // user input sanitized before building args
Defensive patterns

Strategy: validation

Validate before calling

var dangerous = regexp.MustCompile(`[;&|`'$()<>]`)
for i, a := range cfg.Args {
    if dangerous.MatchString(a) {
        return fmt.Errorf("args[%d] contains shell metacharacters", i)
    }
}

Try / catch

if err := ValidateStdioConfig(cfg); err != nil {
    if strings.Contains(err.Error(), "dangerous pattern") {
        return fmt.Errorf("sanitize argument before use: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: An args element matching a dangerous regex, e.g. containing backticks, $(), ; && |, redirect operators, or other configured shell-injection signatures.

Common situations: Passing user-supplied filter expressions or URLs that contain shell metacharacters; arguments built by string concatenation of user input; legitimate flags like "--foo|bar" or package specifiers with special characters.

Related errors


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