crowdsecurity/crowdsec · error

failed to parse DSN parameters: %w

Error message

failed to parse DSN parameters: %w

What it means

After splitting the DSN into the channel/file part and an optional query-string part, ConfigureByDSN parses the parameters with url.ParseQuery. This error wraps a failure of that parsing — the parameter section after `?` is not a valid URL-encoded query string (e.g. a stray `%` or malformed escape sequence).

Source

Thrown at pkg/acquisition/modules/wineventlog/config_windows.go:211

	dsn = strings.TrimPrefix(dsn, "wineventlog://")

	args := strings.Split(dsn, "?")

	if args[0] == "" {
		return errors.New("empty wineventlog:// DSN")
	}

	if len(args) > 2 {
		return errors.New("too many arguments in DSN")
	}

	s.config.EventFile = args[0]

	if len(args) == 2 && args[1] != "" {
		params, err := url.ParseQuery(args[1])
		if err != nil {
			return fmt.Errorf("failed to parse DSN parameters: %w", err)
		}

		for key, value := range params {
			switch key {
			case "log_level":
				if len(value) != 1 {
					return errors.New("log_level must be a single value")
				}
				lvl, err := log.ParseLevel(value[0])
				if err != nil {
					return fmt.Errorf("failed to parse log_level: %s", err)
				}
				s.logger.Logger.SetLevel(lvl)
			case "event_id":
				for _, id := range value {
					evtid, err := strconv.Atoi(id)
					if err != nil {
						return fmt.Errorf("failed to parse event_id: %s", err)

View on GitHub (pinned to 909b515798)

Solutions

  1. Fix the malformed percent-encoding in the DSN — e.g. `%` must be followed by two hex digits.
  2. Build the parameter section with net/url: `url.Values{"event_id": []string{"4624"}}.Encode()` and append after `?`.
  3. URL-escape special characters (&, =, %) that appear in parameter values.
  4. Simplify: omit the `?params` section entirely if no parameters are needed.

Example fix

// before
dsn := "wineventlog://Security?event_id=4625%&level=error"
// after
params := url.Values{}
params.Add("event_id", "4625")
params.Add("level", "error")
dsn := "wineventlog://Security?" + params.Encode()
Defensive patterns

Strategy: validation

Validate before calling

params := url.Values{}
params.Add("event_id", "4625")
dsn := "wineventlog://Security?" + params.Encode() // Encode guarantees parseability

Try / catch

if _, err := url.ParseQuery(strings.SplitN(dsn, "?", 2)[1]); err != nil {
	return fmt.Errorf("malformed DSN parameters: %w", err)
}

Prevention

When it happens

Trigger: A DSN like `wineventlog://Security?event_id=4625%` where the percent-encoding is malformed, or parameters containing characters url.ParseQuery cannot decode (invalid hex after %, missing = in odd spots producing errors per its rules).

Common situations: Hand-written DSNs with unescaped special characters, copy-paste mangling (e.g. `&` handling from URLs), or generating DSNs without url.Values.Encode().

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/0445d72751d78314. Report an issue: GitHub.