siyuan-note/siyuan · warning

URL has no host

Error message

URL has no host

What it means

Thrown by WebFetch after the URL parses and has an http(s) scheme, but u.Host is empty. This catches scheme-prefixed but host-less inputs such as 'https:///path' or 'https://:443/path' that pass the scheme check.

Source

Thrown at kernel/util/webfetch.go:47

	"github.com/88250/gulu"
	"github.com/88250/lute"
	"github.com/siyuan-note/httpclient"
)

const (
	maxWebFetchBytes     = 5 * 1024 * 1024  // text/html, text/plain
	maxWebFetchFileBytes = 10 * 1024 * 1024 // file/image download
	maxWebFetchChars     = 50000
)

func WebFetch(rawURL, format string) (string, error) {
	u, err := url.Parse(rawURL)
	if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
		return "", errors.New("URL must start with http:// or https://")
	}
	if u.Host == "" {
		return "", errors.New("URL has no host")
	}

	if err := CheckHostSSRF(u.Hostname()); err != nil {
		return "", err
	}

	resp, err := httpclient.NewBrowserRequest().Get(rawURL)
	if err != nil {
		return "", errors.New("fetch failed: " + err.Error())
	}
	defer resp.Body.Close()

	if resp.StatusCode >= 400 {
		return "", fmt.Errorf("HTTP %d", resp.StatusCode)
	}

	contentType := resp.Header.Get("Content-Type")
	maxReadBytes := int64(maxWebFetchBytes)

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Validate that the parsed URL has a non-empty Host before calling WebFetch.
  2. Construct URLs with url.URL{Scheme, Host} rather than string concatenation.
  3. Reject empty-host URLs at the input layer with a clear message.

Example fix

// before
util.WebFetch("https:///some/path", "markdown")

// after
util.WebFetch("https://example.com/some/path", "markdown")
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(rawURL)
if err != nil || u.Host == "" {
    return errors.New("URL must include a host, e.g. https://example.com/path")
}

Prevention

When it happens

Trigger: Input like 'https:///foo', 'https://:8080/x', or a URL whose authority is empty. The scheme guard passed but the host component is missing.

Common situations: Malformed hand-typed URLs; programmatic construction that joined a scheme with a path but no host; a trimming step that removed the host.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/065f52931c69ff16. Report an issue: GitHub.