{"record":{"id":"a76ffbd6a9dafc93","repo":"crowdsecurity/crowdsec","slug":"invalid-type-for-url-t","errorCode":null,"errorMessage":"invalid type for url: %T","messagePattern":"invalid type for url: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/http.go","lineNumber":74,"sourceCode":"\tdefer resp.Body.Close()\n\n\tb, err := io.ReadAll(io.LimitReader(resp.Body, exprHTTPMaxBodySize))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &HTTPResponse{\n\t\tStatusCode: resp.StatusCode,\n\t\tBody:       string(b),\n\t\tHeaders:    resp.Header,\n\t}, nil\n}\n\n// HTTPGet(url string) (*HTTPResponse, error)\nfunc HTTPGet(params ...any) (any, error) {\n\turi, ok := params[0].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for url: %T\", params[0])\n\t}\n\n\treturn doHTTPRequest(http.MethodGet, uri, nil, nil)\n}\n\n// HTTPHead(url string) (*HTTPResponse, error)\nfunc HTTPHead(params ...any) (any, error) {\n\turi, ok := params[0].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for url: %T\", params[0])\n\t}\n\n\treturn doHTTPRequest(http.MethodHead, uri, nil, nil)\n}\n\n// HTTPPost(url string, contentType string, body string) (*HTTPResponse, error)\nfunc HTTPPost(params ...any) (any, error) {\n\turi, ok := params[0].(string)","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/http.go#L56-L92","documentation":"HTTPGet is an expr helper whose arguments arrive as ...any. It asserts params[0] to string and returns this error when the URL argument is not a string, naming the actual Go type so you can see what was passed instead.","triggerScenarios":"Calling HTTPGet() in an expression with a non-string first argument, e.g. HTTPGet(evt.url_field) where the field is nil, a number, or an object; forgetting to wrap a literal in quotes.","commonSituations":"Event field is nil because the URL was absent from the log; numeric fields (port-only value) passed as URL; expression written with an unquoted identifier that resolves to a non-string variable.","solutions":["Ensure the argument is a string: use a quoted literal or a field known to hold a string URL","If the field may be nil/missing, wrap in a condition checking it before calling HTTPGet","Convert non-string values to string first (e.g. string(evt.port) is not a URL — build the full URL string)","Check the reported %T in the message to identify what type the field actually holds"],"exampleFix":"// before\nHTTPGet(evt.target) // target is nil sometimes\n// after\n// guard in expr:\n//   evt.target != nil ? HTTPGet(evt.target) : nil","handlingStrategy":"type-guard","validationCode":"// expr: evt.url != nil && type(evt.url) == string","typeGuard":"func isString(v interface{}) bool { _, ok := v.(string); return ok }","tryCatchPattern":null,"preventionTips":["Quote URL literals in expressions","Check fields are non-nil before HTTP helpers","Prefer building URLs via explicit string concatenation"],"tags":["expr","http","type-mismatch"],"backgroundTag":"type-mismatch","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"}