JuliusBrussee/caveman · error

ssrf: managed mode requires port 443

Error message

ssrf: managed mode requires port 443

What it means

In managed mode (the strictest SSRF posture) the library only permits HTTPS on port 443. If the URL carries an explicit port that is anything other than 443, parseValidatedURL rejects it because non-standard ports are a common way to reach internal services. URLs with no explicit port are fine — the default 443 is applied.

Solutions

  1. Move the service behind standard port 443 (reverse proxy/load balancer) or drop the explicit :port from the URL and serve on 443.
  2. If the alternate port is genuinely required and safe, construct the client without managed mode so http/custom ports are allowed per cfg.ManagedMode=false semantics.
  3. Route through your operator proxy/gateway that terminates TLS on 443 and forwards to the service's real port.

Example fix

// before (managed mode)
client, err := ssrf.ValidateURL("https://payments.internal:8443/v1/charge")
// after
client, err := ssrf.ValidateURL("https://payments.internal/v1/charge") // serve on 443
Defensive patterns

Strategy: validation

Validate before calling

func okForManagedMode(raw string) bool {
    u, err := url.Parse(raw)
    if err != nil || u.Scheme != "https" {
        return false
    }
    p := u.Port()
    return p == "" || p == "443"
}

Try / catch

if err := ssrf.ValidateURL(raw); err != nil && strings.Contains(err.Error(), "managed mode requires port 443") {
    return fmt.Errorf("endpoint %s must be served on 443 in managed mode", raw)
}

Prevention

When it happens

Trigger: Calling ValidateURL or ValidateURLNoResolve in managed mode (cfg.ManagedMode = true) with URLs like "https://host:8443/x", "https://host:8080/" — an explicit non-443 port triggers this; "https://host/" (no port) does not.

Common situations: Pointing the client at a self-hosted service on a custom HTTPS port (8443, 9443) while managed mode is on; a dev/staging endpoint with an explicit port leaked into prod config; forgetting that managed mode forbids even https on alternate ports.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/5f6724883f5fc103. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/ssrf/ssrf.go:227

	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.
func ValidateHost(ctx context.Context, host string, cfg Config) error {
	return validateHostPort(ctx, host, "", cfg)
}

View on GitHub (pinned to 3ee70a1026)