{"record":{"id":"4cb25a31cd4fdd11","repo":"crowdsecurity/crowdsec","slug":"invalid-http-status-code","errorCode":null,"errorMessage":"invalid HTTP status code","messagePattern":"invalid HTTP status code","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/http/config.go","lineNumber":152,"sourceCode":"\t\tif c.TLS.ServerKey == \"\" {\n\t\t\treturn errors.New(\"server_key is required\")\n\t\t}\n\t}\n\n\tif c.MaxBodySize != nil && *c.MaxBodySize <= 0 {\n\t\treturn errors.New(\"max_body_size must be positive\")\n\t}\n\n\t/*\n\t\tif hc.ChunkSize != nil && *hc.ChunkSize <= 0 {\n\t\t\treturn errors.New(\"chunk_size must be positive\")\n\t\t}\n\t*/\n\n\tif c.CustomStatusCode != nil {\n\t\tstatusText := http.StatusText(*c.CustomStatusCode)\n\t\tif statusText == \"\" {\n\t\t\treturn errors.New(\"invalid HTTP status code\")\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (s *Source) Configure(_ context.Context, yamlConfig []byte, logger *log.Entry, metricsLevel metrics.AcquisitionMetricsLevel) error {\n\ts.logger = logger\n\ts.metricsLevel = metricsLevel\n\n\terr := s.UnmarshalConfig(yamlConfig)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/http/config.go#L134-L170","documentation":"When a custom_status_code is configured for the HTTP source (the status returned to the client), it must map to a known HTTP status via http.StatusText. An unknown/empty status text means the number is not a recognized HTTP status code, so Validate() rejects it in pkg/acquisition/modules/http/config.go:152.","triggerScenarios":"Calling Validate() on an http source Configuration with CustomStatusCode set to a number that is not a valid HTTP status code (e.g. 0, 999, 1234).","commonSituations":"Hand-editing the YAML and typing an invalid number; setting 0 to mean 'default' instead of leaving the key unset; generated configs plugging in an uninitialized integer.","solutions":["Set custom_status_code to a valid HTTP status code between 100 and 599 that http.StatusText recognizes (e.g. 200, 404).","Remove the custom_status_code key entirely to use the default behavior.","Validate the number against the HTTP spec before writing the config (100–599, not a reserved/undefined value)."],"exampleFix":"// before (acquis.yaml)\nsource: http\ncustom_status_code: 999\n\n// after\nsource: http\ncustom_status_code: 200","handlingStrategy":"validation","validationCode":"if cfg.CustomStatusCode != nil {\n    if http.StatusText(*cfg.CustomStatusCode) == \"\" {\n        return fmt.Errorf(\"invalid custom_status_code: %d\", *cfg.CustomStatusCode)\n    }\n}","typeGuard":"func validHTTPStatus(code int) bool { return http.StatusText(code) != \"\" }","tryCatchPattern":null,"preventionTips":["Use named constants (http.StatusOK) when generating configs programmatically.","Only include custom_status_code when you actually need a non-default response status.","Lint acquisition YAML against the schema."],"tags":["config","validation","http"],"backgroundTag":"invalid-config-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"}