Tencent/WeKnora · warning
empty url
Error message
empty url
What it means
parseHostForHint is a best-effort helper that extracts a hostname from a raw URL to echo back in SSRF error hints. It returns the 'empty url' error when given an empty string. Callers (FormatSSRFError) fall back to the raw URL, so this is usually swallowed and rarely surfaces directly to users.
Source
Thrown at internal/utils/security.go:1158
}
host := rawURL
if parsed, perr := parseHostForHint(rawURL); perr == nil && parsed != "" {
host = parsed
}
return fmt.Sprintf(
"%s 未通过安全校验:%v。如该地址确实可信,请联系运维在服务端环境变量 "+
"SSRF_WHITELIST_EXTRA 中加入该主机(支持精确域名 / *.example.com 通配 / IP / CIDR),"+
"示例:SSRF_WHITELIST_EXTRA=%s,*.example.com,10.0.0.0/8",
label, err, host,
)
}
// parseHostForHint extracts a hostname from rawURL purely so we can echo
// it back inside the SSRF hint. Best-effort — returns ("", err) for
// completely unparseable input and the caller falls back to the raw URL.
func parseHostForHint(rawURL string) (string, error) {
if rawURL == "" {
return "", fmt.Errorf("empty url")
}
norm := rawURL
if !strings.Contains(norm, "://") {
norm = "https://" + norm
}
u, err := url.Parse(norm)
if err != nil {
return "", err
}
return u.Hostname(), nil
}
// ValidateURLForSSRF is the centralised entry-point that all handlers should
// call to validate a user-supplied URL. It first checks the SSRF_WHITELIST;
// whitelisted hosts skip the full isSSRFSafeURL check.
//
// rawURL may be a full URL ("https://example.com/v1") or a bare host/host:port
// (for cases like ReconnectDocReader). If a scheme is missing the functionView on GitHub (pinned to 988cbb0330)
Solutions
- Ensure the URL being validated is non-empty before calling the SSRF path; fail fast with a clearer 'endpoint not configured' message
- Guard the formatter: skip hint generation when rawURL == ""
- Populate the endpoint config value that is arriving empty
Example fix
// before
hint := FormatSSRFError(rawURL, reason) // rawURL == ""
// after
if rawURL == "" {
return fmt.Errorf("endpoint URL is not configured")
}
hint := FormatSSRFError(rawURL, reason) Defensive patterns
Strategy: validation
Validate before calling
if rawURL == "" {
return errors.New("endpoint URL is not configured")
} Type guard
func hasURL(u string) bool { return strings.TrimSpace(u) != "" } Try / catch
hint, err := parseHostForHint(rawURL)
if err != nil {
hint = rawURL // library falls back to raw URL; mirror that
} Prevention
- Fail fast on empty endpoint config before entering SSRF validation
- Check required env vars at startup
- Treat this as a symptom: the real bug is the empty URL upstream
When it happens
Trigger: FormatSSRFError is called with an empty rawURL string — e.g. the SSRF validation failure was recorded before the URL was normalized, or a caller passed an empty config field through to the error formatter.
Common situations: Empty endpoint configuration (unset OBS/OSS/S3 URL env var) causing both a validation failure and an empty URL in the error path; logging code calling FormatSSRFError with a blank variable.
Related errors
- invalid URL: %w
- URL has no hostname
- unsafe MinIO endpoint: %w
- unsafe OSS endpoint: %w
- unsafe S3 endpoint: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/a9f8951477a754a5.
Report an issue: GitHub.