JuliusBrussee/caveman · error
ssrf: URL must contain a host
Error message
ssrf: URL must contain a host
What it means
Error from parseValidatedURL in the SSRF guard: the URL parsed and passed scheme checks, but contains no host component. There is nothing to resolve or port-check, and a hostless URL (e.g. a scheme-only or malformed value) is treated as invalid rather than passed through.
Solutions
- Fix the source of the empty host — check the env var / config value feeding the URL
- Validate the URL with url.Parse and assert u.Hostname() != "" before calling the library
- Add a startup-time check that required base-URL config values are non-empty
Example fix
// before
raw := "https://" + os.Getenv("PROVIDER_HOST") // empty
err := ssrf.ValidateURL(ctx, raw, cfg)
// after
host := os.Getenv("PROVIDER_HOST")
if host == "" {
return fmt.Errorf("PROVIDER_HOST is required")
}
err := ssrf.ValidateURL(ctx, "https://"+host, cfg) Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(raw)
if err != nil || u.Hostname() == "" {
return errors.New("endpoint URL must include a host")
} Type guard
func hasHost(raw string) bool {
u, err := url.Parse(raw)
return err == nil && u.Hostname() != ""
} Try / catch
if err := ssrf.ValidateURL(ctx, endpoint, cfg); err != nil {
if strings.Contains(err.Error(), "must contain a host") {
return fmt.Errorf("endpoint config is empty or malformed: %q", endpoint)
}
return err
} Prevention
- Check required URL env vars at process startup and fail fast when empty
- Use url.JoinPath/base-URL joining instead of string concatenation
- Never build URLs from possibly-empty string variables without a check
When it happens
Trigger: Calling ssrf.ValidateURL / ValidateURLNoResolve with a URL string that parses but has no authority component: "https://", "https:///api", "http://#frag", or a base URL joined onto an empty variable.
Common situations: An unset or empty environment variable interpolated into a base URL (BASE_URL="" yields "https:///path"); string concatenation like "https://"+host where host is empty; a template placeholder never filled in.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- awscreds: AWS_EC2_METADATA_SERVICE_ENDPOINT is not a valid…
- githubapp: invalid request path
- githubapp: request path escaped configured host
- githubapp: request path must be a single-host absolute path
- ssrf: credentials embedded in URL are forbidden
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/ebb56e376edace00.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/ssrf/ssrf.go:223
// parseValidatedURL applies the URL-shape policy — scheme, embedded
// credentials, managed-mode port — and returns the host/port to check.
func parseValidatedURL(raw string, cfg Config) (host, port string, err error) {
u, parseErr := url.Parse(raw)
if parseErr != nil {
// net/url.Error includes the raw URL (and may therefore include
// credentials or query secrets). Keep this error field-only and stable.
return "", "", errors.New("ssrf: invalid URL")
}
if u.Scheme != "https" && !(u.Scheme == "http" && !cfg.ManagedMode) {
return "", "", fmt.Errorf("ssrf: scheme %q not permitted (managed mode requires https)", u.Scheme)
}
if u.User != nil {
return "", "", fmt.Errorf("ssrf: credentials embedded in URL are forbidden")
}
host = u.Hostname()
if host == "" {
return "", "", fmt.Errorf("ssrf: URL must contain a host")
}
port = u.Port()
if cfg.ManagedMode && port != "" && port != "443" {
return "", "", errors.New("ssrf: managed mode requires port 443")
}
if port == "" {
if u.Scheme == "https" {
port = "443"
} else {
port = "80"
}
}
return host, port, nil
}
// ValidateHost resolves host (bare hostname or IP literal) and checks all
// resolved addresses. Use when you have a host/port pair rather than a full
// URL.View on GitHub (pinned to 3ee70a1026)