The vulnerability, identified as GHSA-q355-h244-969h, is a classic case of Cross-Site WebSocket Hijacking (CSWSH). The root cause is the disabled origin check in multiple WebSocket endpoint handlers within the Komari application. The github.com/gorilla/websocket library's Upgrader has a CheckOrigin field, which is a function that should validate if the request's Origin header is allowed. In the vulnerable versions of Komari, this function was set to func(r *http.Request) bool { return true }, completely bypassing this critical security check.
This misconfiguration allows any third-party website to initiate a WebSocket connection to the Komari instance's WebSocket endpoints. Since browsers automatically include cookies with cross-origin requests, an authenticated administrator visiting a malicious webpage could have their session hijacked. The malicious page could then establish a WebSocket connection in the background and send commands to the administrator's managed nodes, as demonstrated in the Proof of Concept, resulting in unauthorized remote code execution.
The fixing commit 53171affcaf050145810efaaef420651a6e630be addresses this by introducing a centralized, secure ws.CheckOrigin function that properly validates the Origin header against the Host header of the request. This new function is then applied to the WebSocket upgraders in the affected parts of the codebase, ensuring that only requests from trusted origins can establish WebSocket connections. The analysis identified four distinct functions (api.RequestTerminal, client.EstablishConnection, client.WebSocketReport, and ws.GetClients) that were vulnerable due to this issue.