Skip to content

The agent that grows with you

refactor(dashboard): single origin_mismatch return in WS origin guard

kshitijk4poor1cb25c3e335a
diff --git a/hermes_cli/web_server_chat.py b/hermes_cli/web_server_chat.py
index fba2869b750..d92b2e08506 100644
--- a/hermes_cli/web_server_chat.py
+++ b/hermes_cli/web_server_chat.py
@@ -185,11 +185,11 @@ def _ws_host_origin_reason(ws: "WebSocket") -> Optional[str]:
return None
try:
parsed = urllib.parse.urlparse(origin)
- except ValueError:
- return f"origin_mismatch origin={origin} bound={bound_host}"
- if parsed.scheme not in {"http", "https"}:
+ except ValueError: # malformed authority, e.g. "http://[::1" — fail closed
+ parsed = None
+ if parsed is not None and parsed.scheme not in {"http", "https"}:
return None
- if not parsed.netloc or not _is_accepted_host(parsed.netloc, bound_host, trusted_public_hosts):
+ if parsed is None or not parsed.netloc or not _is_accepted_host(parsed.netloc, bound_host, trusted_public_hosts):
return f"origin_mismatch origin={origin} bound={bound_host}"
return None