siyuan-note/siyuan · warning

URL must start with http:// or https://

Error message

URL must start with http:// or https://

What it means

Thrown by WebFetch at the top when url.Parse fails or the scheme is neither http nor https. It is the scheme precondition before any network activity. Only http(s) URLs are accepted; ftp/file/javascript/data schemes are rejected.

Source

Thrown at kernel/util/webfetch.go:44

	"path"
	"path/filepath"
	"strings"

	"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)
	}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Prepend 'https://' to bare-domain inputs before calling WebFetch.
  2. Validate the scheme client-side and reject non-http(s) values.
  3. Use url.Parse upstream and inspect u.Scheme to give a precise error.

Example fix

// before
util.WebFetch("example.com/page", "markdown")

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

Strategy: validation

Validate before calling

u, err := url.Parse(rawURL)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
    if !strings.Contains(rawURL, "://") {
        rawURL = "https://" + rawURL // auto-fix bare domains
    }
    u, err = url.Parse(rawURL)
    if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
        return errors.New("only http and https URLs are supported")
    }
}

Prevention

When it happens

Trigger: Passing a URL without a scheme (e.g. 'example.com/page'); a URL with a non-http scheme (file://, ftp://); a malformed URL that url.Parse rejects; a relative path.

Common situations: User submitted a bare domain; the URL field was auto-filled without https://; an internal caller passed a path rather than a full URL; copy-paste dropped the scheme.

Related errors


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