XTLS/Xray-core · error

invalid redirect port: {}

Error message

invalid redirect port: {}

What it means

Thrown when the freedom outbound's 'redirect' address splits into host:port but the port substring is not a valid port per xnet.PortFromString. This catches out-of-range ports (>65535), non-numeric ports, and empty port strings after the SplitHostPort stage has already succeeded.

Source

Thrown at infra/conf/freedom.go:168

		for _, n := range c.Noises {
			NConfig, err := ParseNoise(n)
			if err != nil {
				return nil, err
			}
			config.Noises = append(config.Noises, NConfig)
		}
	}

	config.UserLevel = c.UserLevel

	if len(c.Redirect) > 0 {
		host, portStr, err := net.SplitHostPort(c.Redirect)
		if err != nil {
			return nil, errors.New("invalid redirect address: ", c.Redirect, ": ", err).Base(err)
		}
		port, err := xnet.PortFromString(portStr)
		if err != nil {
			return nil, errors.New("invalid redirect port: ", c.Redirect, ": ", err).Base(err)
		}
		config.DestinationOverride = &freedom.DestinationOverride{
			Server: &protocol.ServerEndpoint{
				Port: uint32(port),
			},
		}

		if len(host) > 0 {
			config.DestinationOverride.Server.Address = xnet.NewIPOrDomain(xnet.ParseAddress(host))
		}
	}

	if c.ProxyProtocol > 0 && c.ProxyProtocol <= 2 {
		config.ProxyProtocol = c.ProxyProtocol
	}

	for _, r := range c.FinalRules {
		rule, err := r.Build()

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Use a numeric port between 1 and 65535, e.g. "example.com:443".
  2. Replace service-name ports ("https", "http") with their numbers.
  3. If only redirecting traffic regardless of port, keep an explicit valid port — the field requires one.

Example fix

// before
"redirect": "example.com:70000"

// after
"redirect": "example.com:443"
Defensive patterns

Strategy: validation

Validate before calling

_, portStr, _ := net.SplitHostPort(redirect)
if p, err := strconv.ParseUint(portStr, 10, 16); err != nil || p == 0 {
    return fmt.Errorf("redirect port %q must be 1-65535", portStr)
}

Prevention

When it happens

Trigger: "redirect": "example.com:70000" (exceeds 65535), "redirect": "example.com:https" (service name not accepted), "redirect": "example.com:" (empty port). The chained base error identifies the port parse failure.

Common situations: Typos in port numbers; expecting symbolic port names to resolve; trailing colon after deleting a port.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/d77836f329bfd94b. Report an issue: GitHub.