crowdsecurity/crowdsec · error
invalid type for url: %T
Error message
invalid type for url: %T
What it means
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.
Source
Thrown at pkg/exprhelpers/http.go:74
defer resp.Body.Close()
b, err := io.ReadAll(io.LimitReader(resp.Body, exprHTTPMaxBodySize))
if err != nil {
return nil, err
}
return &HTTPResponse{
StatusCode: resp.StatusCode,
Body: string(b),
Headers: resp.Header,
}, nil
}
// HTTPGet(url string) (*HTTPResponse, error)
func HTTPGet(params ...any) (any, error) {
uri, ok := params[0].(string)
if !ok {
return nil, fmt.Errorf("invalid type for url: %T", params[0])
}
return doHTTPRequest(http.MethodGet, uri, nil, nil)
}
// HTTPHead(url string) (*HTTPResponse, error)
func HTTPHead(params ...any) (any, error) {
uri, ok := params[0].(string)
if !ok {
return nil, fmt.Errorf("invalid type for url: %T", params[0])
}
return doHTTPRequest(http.MethodHead, uri, nil, nil)
}
// HTTPPost(url string, contentType string, body string) (*HTTPResponse, error)
func HTTPPost(params ...any) (any, error) {
uri, ok := params[0].(string)View on GitHub (pinned to 909b515798)
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
Example fix
// before HTTPGet(evt.target) // target is nil sometimes // after // guard in expr: // evt.target != nil ? HTTPGet(evt.target) : nil
Defensive patterns
Strategy: type-guard
Validate before calling
// expr: evt.url != nil && type(evt.url) == string
Type guard
func isString(v interface{}) bool { _, ok := v.(string); return ok } Prevention
- Quote URL literals in expressions
- Check fields are non-nil before HTTP helpers
- Prefer building URLs via explicit string concatenation
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- invalid type for contentType: %T
- invalid type for body: %T
- invalid type for method: %T
- invalid type for headers: %T
- AverageInterval expects a slice of times
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/a76ffbd6a9dafc93.
Report an issue: GitHub.