chenhg5/cc-connect · warning

invalid remote image URL

Error message

invalid remote image URL

What it means

fetchRichCardRemoteImage validates the supplied URL before fetching an image for a rich Feishu card. It parses the URL and requires an http/https scheme and a non-empty host; anything else returns this error without any network activity. This guards against malformed input and non-HTTP schemes (file:, data:, ftp:) being used for SSRF or file access.

Source

Thrown at platform/feishu/feishu.go:6585

	u, err := url.Parse(rawURL)
	if err != nil {
		return false
	}
	return (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""
}

func richCardImageURLHost(rawURL string) string {
	u, err := url.Parse(rawURL)
	if err != nil || u.Host == "" {
		return ""
	}
	return u.Hostname()
}

func fetchRichCardRemoteImage(ctx context.Context, rawURL string) ([]byte, string, error) {
	u, err := url.Parse(rawURL)
	if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
		return nil, "", errors.New("invalid remote image URL")
	}

	client := &http.Client{
		Timeout: richCardImageFinalWait,
		Transport: &http.Transport{
			DialContext:           dialPublicRichCardImageContext,
			ResponseHeaderTimeout: richCardImageFinalWait,
		},
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			if len(via) >= 3 {
				return errors.New("too many redirects")
			}
			if !isRemoteRichCardImageURL(req.URL.String()) {
				return errors.New("redirected to unsupported image URL")
			}
			return nil
		},
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix the source URL to be an absolute http(s) URL with a valid host.
  2. Upload local/data-URI images through Feishu's image upload API instead of a remote URL.
  3. Validate image URLs (scheme + host) before embedding them in card content.

Example fix

// before
card.ImageURL = "data:image/png;base64,iVBOR..."
// after
// upload data URI bytes via Feishu image API and use the returned image_key
card.ImageKey = uploadFeishuImage(ctx, dataURIBytes)
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(rawURL)
valid := err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""

Type guard

func isFetchableImageURL(raw string) bool {
    u, err := url.Parse(raw)
    return err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""
}

Try / catch

data, mime, err := fetchRichCardRemoteImage(ctx, rawURL)
if err != nil {
    // fall back to placeholder card or upload-through-API path
}

Prevention

When it happens

Trigger: A rich card image URL fails url.Parse, has a scheme other than http/https (e.g. ftp://, file://, data:), or lacks a host (protocol-relative malformed input) — checked at platform/feishu/feishu.go:6585.

Common situations: Agent output embeds a data: URI or relative path as an image URL; markdown image link is malformed or missing scheme; config/content supplies "localhost-only" style URLs without a proper host part; typos like htp://.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/317561c0aafe8393. Report an issue: GitHub.