{"record":{"id":"7dc0627c519d1876","repo":"crowdsecurity/crowdsec","slug":"on-route-not-found-w","errorCode":null,"errorMessage":"on_route_not_found: %w","messagePattern":"on_route_not_found: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/appsec/api_validation/api_validation.go","lineNumber":313,"sourceCode":"\t\t}\n\n\t\treturn nil\n\t}\n}\n\nfunc (rv *RequestValidator) LoadSchema(ref string, schema string, opts *SchemaOptions) error {\n\tif ref == \"\" {\n\t\treturn errors.New(\"ref cannot be empty\")\n\t}\n\trv.logger.Debugf(\"loading schema for ref %s\", ref)\n\n\tif _, exists := rv.loaders[ref]; exists {\n\t\treturn fmt.Errorf(\"attempting to load a new schema for existing ref %s\", ref)\n\t}\n\n\toptions := opts.withDefaults()\n\tif err := options.OnRouteNotFound.validate(); err != nil {\n\t\treturn fmt.Errorf(\"on_route_not_found: %w\", err)\n\t}\n\tif err := options.OnMethodNotAllowed.validate(); err != nil {\n\t\treturn fmt.Errorf(\"on_method_not_allowed: %w\", err)\n\t}\n\tif err := options.OnUnsupportedSecurityScheme.validate(); err != nil {\n\t\treturn fmt.Errorf(\"on_unsupported_security_scheme: %w\", err)\n\t}\n\n\tloader := openapi3.NewLoader()\n\trv.loaders[ref] = loader\n\n\tdoc, err := loader.LoadFromData([]byte(schema))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load schema %s: %w\", ref, err)\n\t}\n\n\t// Is it a valid OpenAPI schema?\n\t// TODO: look into opts, should we expose some of them to the user ?","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/appsec/api_validation/api_validation.go#L295-L331","documentation":"LoadSchema validates the OnRouteNotFound policy option before loading the schema. A Policy is only valid when it equals \"drop\" or \"ignore\"; anything else (empty string, typo, wrong casing) fails validation and the error is wrapped as \"on_route_not_found: ...\".","triggerScenarios":"Calling LoadSchema with SchemaOptions whose OnRouteNotFound is set to an invalid string, e.g. Policy(\"block\"), \"\", or \"Drop\" (case-sensitive), typically from a YAML appsec config mapping on_route_not_found to an unsupported value.","commonSituations":"Typos in the appsec config YAML (\"droped\", \"bloc\"); wrong casing after hand-editing; a config key copied from an older/other product that used different policy names; passing a zero-value struct with an explicitly empty policy.","solutions":["Set on_route_not_found to exactly \"drop\" or \"ignore\" in the appsec config.","Check casing — the values are lowercase and case-sensitive.","If the field was explicitly set to \"\", remove the key so defaults apply.","Validate config values before constructing SchemaOptions in embedding code."],"exampleFix":"// before\nopts.OnRouteNotFound = api_validation.Policy(\"block\")\n\n// after\nopts.OnRouteNotFound = api_validation.PolicyDrop // \"drop\"","handlingStrategy":"validation","validationCode":"func validPolicy(p api_validation.Policy) bool {\n    return p == api_validation.PolicyDrop || p == api_validation.PolicyIgnore\n}\n// call before LoadSchema\nif !validPolicy(opts.OnRouteNotFound) { return fmt.Errorf(\"bad on_route_not_found: %q\", opts.OnRouteNotFound) }","typeGuard":"func isPolicy(s string) bool { return s == \"drop\" || s == \"ignore\" }","tryCatchPattern":"if err := rv.LoadSchema(ref, schema, opts); err != nil {\n    var pe *fmt.WrapError // or inspect the wrapped text\n    if strings.Contains(err.Error(), \"on_route_not_found:\") {\n        log.Errorf(\"fix on_route_not_found in config (drop|ignore): %v\", err)\n    }\n    return err\n}","preventionTips":["Use only \"drop\" or \"ignore\" for policy options","Use the PolicyDrop/PolicyIgnore constants in Go code","Omit unset policy keys in YAML instead of writing empty strings","Validate policy strings when parsing appsec config"],"tags":["appsec","configuration","enum","policy"],"backgroundTag":"invalid-enum-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"}