nats-io/nats-server · error
unable to parse allowed origin: %v
Error message
unable to parse allowed origin: %v
What it means
Returned by validateWebsocketOptions() when an entry in the websocket allowed_origins option cannot be parsed by url.ParseRequestURI(). Startup aborts because an origin that cannot be parsed can never match, indicating a configuration typo or malformed value.
Source
Thrown at server/websocket.go:1140
// Validate the websocket related options.
func validateWebsocketOptions(o *Options) error {
wo := &o.Websocket
// If no port is defined, we don't care about other options
if wo.Port == 0 {
return nil
}
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
}
}View on GitHub (pinned to 3a66a489d2)
Solutions
- Fix the malformed allowed_origins entry in the server configuration
- Use absolute URLs like https://example.com instead of hostnames or wildcards
- Quote values containing special characters in the config file
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at server/websocket.go:1140 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/e1ce6155eb52be90.
Report an issue: GitHub.