{"record":{"id":"accb52207757cc55","repo":"crowdsecurity/crowdsec","slug":"invalid-filter","errorCode":null,"errorMessage":"invalid filter","messagePattern":"invalid filter","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/database/errors.go","lineNumber":20,"sourceCode":"\nimport \"errors\"\n\nvar (\n\tUserExists        = errors.New(\"user already exist\")\n\tUserNotExists     = errors.New(\"user doesn't exist\")\n\tHashError         = errors.New(\"unable to hash\")\n\tInsertFail        = errors.New(\"unable to insert row\")\n\tQueryFail         = errors.New(\"unable to query\")\n\tUpdateFail        = errors.New(\"unable to update\")\n\tDeleteFail        = errors.New(\"unable to delete\")\n\tItemNotFound      = errors.New(\"object not found\")\n\tParseTimeFail     = errors.New(\"unable to parse time\")\n\tParseDurationFail = errors.New(\"unable to parse duration\")\n\tMarshalFail       = errors.New(\"unable to serialize\")\n\tBulkError         = errors.New(\"unable to insert bulk\")\n\tParseType         = errors.New(\"unable to parse type\")\n\tInvalidIPOrRange  = errors.New(\"invalid ip address / range\")\n\tInvalidFilter     = errors.New(\"invalid filter\")\n)\n","sourceCodeStart":2,"sourceCodeEnd":22,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/errors.go#L2-L22","documentation":"InvalidFilter is a sentinel error meaning a database filter expression is structurally invalid: an unknown key/value combination, an unparseable boolean for 'contains', an unknown IP size class, or any other rejection inside alert/decision predicate building. Unlike ParseType (wrong value type) it usually means the filter itself is malformed or unsupported.","triggerScenarios":"alertPredicatesFromFilter with contains=<not-a-bool>; handleAlertIPPredicates hitting 'unknown ip size'; applyDecisionFilter/decisionIPFilter/ExpireDecisionsWithFilter with unsupported filter keys or malformed value shapes.","commonSituations":"Scripts building LAPI query strings with typo'd keys (\"contain\" instead of \"contains\") or wrong value formats, old clients using removed filter names after an upgrade, multi-value filters assembled incorrectly.","solutions":["Check the wrapped inner error message for the exact rejected part of the filter.","Verify filter keys against the current LAPI docs (keys: scope, value, ip, contains, since, until, has_active_decision, ...).","Use strconv.ParseBool-compatible values for contains (true/false).","Update the client library/cscli version to match the server if filter semantics changed."],"exampleFix":"// before\nfilter := map[string][]string{\"contains\": {\"yes\"}}\nalerts, err := client.ListAlerts(ctx, filter) // InvalidFilter\n// after\nfilter := map[string][]string{\"contains\": {\"true\"}}\nalerts, err := client.ListAlerts(ctx, filter)","handlingStrategy":"validation","validationCode":"// Go: whitelist filter keys and validate value formats before calling\nvar allowedKeys = map[string]bool{\"scope\": true, \"value\": true, \"ip\": true, \"contains\": true, \"since\": true, \"until\": true, \"has_active_decision\": true}\nfunc validFilter(f map[string][]string) error {\n    for k, vs := range f {\n        if !allowedKeys[k] { return fmt.Errorf(\"unknown filter key %q\", k) }\n        for _, v := range vs {\n            if k == \"contains\" { if _, err := strconv.ParseBool(v); err != nil { return err } }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := validFilter(filter); err != nil { return err }\nalerts, err := client.ListAlerts(ctx, filter)\nif errors.Is(err, database.InvalidFilter) {\n    return fmt.Errorf(\"rejected filter: %w\", err)\n}","preventionTips":["Validate filter keys/values client-side against the documented set","Keep client/cscli versions aligned with the server","Unit-test filter builders with the exact keys LAPI accepts"],"tags":["database","crowdsec","filter","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}