nats-io/nats-server · error

unable to parse allowed origin %q: host is required

Error message

unable to parse allowed origin %q: host is required

What it means

Returned by validateWebsocketOptions() when an allowed_origins entry parses as an absolute http(s) URL but has an empty host component (e.g. 'https:///path'). Without a host the origin cannot be meaningfully compared against the Origin header of incoming websocket requests, so startup is aborted.

Source

Thrown at server/websocket.go:1146

	}
	if !wsAllowedFIPS() {
		return fmt.Errorf("websocket: cannot be used in FIPS-140 mode when built with this Go version, use Go 1.26 or later")
	}
	// Enforce TLS... unless NoTLS is set to true.
	if wo.TLSConfig == nil && !wo.NoTLS {
		return errors.New("websocket requires TLS configuration")
	}
	// Make sure that allowed origins, if specified, can be parsed.
	for _, ao := range wo.AllowedOrigins {
		u, err := url.ParseRequestURI(ao)
		if err != nil {
			return fmt.Errorf("unable to parse allowed origin: %v", err)
		}
		if u.Scheme != "http" && u.Scheme != "https" {
			return fmt.Errorf("unable to parse allowed origin %q: allowed origins must be absolute URLs with http or https scheme", ao)
		}
		if u.Host == _EMPTY_ {
			return fmt.Errorf("unable to parse allowed origin %q: host is required", ao)
		}
		if _, _, err := wsGetHostAndPort(u.Scheme == "https", u.Host); err != nil {
			return fmt.Errorf("unable to parse allowed origin: %v", err)
		}
	}
	// If there is a NoAuthUser, we need to have Users defined and
	// the user to be present.
	if wo.NoAuthUser != _EMPTY_ {
		if err := validateNoAuthUser(o, wo.NoAuthUser); err != nil {
			return err
		}
	}
	// Token/Username not possible if there are users/nkeys
	if len(o.Users) > 0 || len(o.Nkeys) > 0 {
		if wo.Username != _EMPTY_ {
			return fmt.Errorf("websocket authentication username not compatible with presence of users/nkeys")
		}
		if wo.Token != _EMPTY_ {

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Add the hostname to the origin value, e.g. https://example.com/path
  2. Remove entries that contain no host portion
  3. Verify the config was not mangled (missing host after scheme)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/websocket.go:1146 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/3f3752476c7d0fd7. Report an issue: GitHub.