larksuite/cli · error

invalid remote IP

Error message

invalid remote IP

What it means

validateConnRemoteIP parses the host portion of the connection's remote address string with net.ParseIP. This error means the address string could not be parsed as an IP (even after trimming IPv6 brackets and tolerating a failed SplitHostPort), so the SSRF restriction check cannot be performed. The connection is rejected rather than trusted.

Source

Thrown at internal/validate/url.go:561

		err,
	).WithCause(err)
}

func validateConnRemoteIP(conn net.Conn) error {
	if conn == nil {
		return fmt.Errorf("nil connection")
	}
	raddr := conn.RemoteAddr()
	if raddr == nil {
		return fmt.Errorf("missing remote address")
	}
	host, _, err := net.SplitHostPort(raddr.String())
	if err != nil {
		host = raddr.String()
	}
	ip := net.ParseIP(strings.Trim(host, "[]"))
	if ip == nil {
		return fmt.Errorf("invalid remote IP")
	}
	if isRestrictedDownloadIP(ip) {
		return fmt.Errorf("local/internal host is not allowed")
	}
	return nil
}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Ensure the connection's RemoteAddr is a standard *net.TCPAddr/*net.UDPAddr whose String() contains an IP
  2. Fix custom Addr types to report an IP-based address
  3. If a wrapper reformats the address, keep the IP literal in String() output

Example fix

// before
func (a pipeAddr) String() string { return "local-pipe" }
// after
func (a pipeAddr) String() string { return a.ip.String() }
Defensive patterns

Strategy: type-guard

Validate before calling

raddr := conn.RemoteAddr()
if tcp, ok := raddr.(*net.TCPAddr); !ok || tcp.IP == nil {
    return errors.New("remote address is not an IP-based TCP address")
}

Type guard

func remoteIP(conn net.Conn) net.IP {
    if tcp, ok := conn.RemoteAddr().(*net.TCPAddr); ok {
        return tcp.IP
    }
    return nil
}

Try / catch

if err != nil && strings.Contains(err.Error(), "invalid remote IP") {
    return fmt.Errorf("connection peer has no IP address; check custom Addr implementations: %w", err)
}

Prevention

When it happens

Trigger: RemoteAddr().String() yields something non-IP-shaped, e.g. a custom Addr whose String() returns a name or opaque token instead of host:port with an IP literal.

Common situations: Custom net.Addr implementations on wrapped connections; connections over unusual network types (unix pipes misused in an HTTP client); test fakes returning human-readable addresses.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/40c544858d36a8fe. Report an issue: GitHub.