bugfix: #173 Websocket fixes 1) The upgrader was refusing reverse proxies, 2) The upgrader was "listening" on /, not /websocket (#177)

This commit is contained in:
James Read 2023-10-24 05:48:16 +01:00 committed by GitHub
parent 311f9a1d00
commit 3db8ae53b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 8 deletions

View File

@ -15,7 +15,6 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
)
// StartSingleHTTPFrontend will create a reverse proxy that proxies the API
@ -38,13 +37,14 @@ func StartSingleHTTPFrontend(cfg *config.Config) {
apiProxy.ServeHTTP(w, r)
})
mux.HandleFunc("/websocket", func(w http.ResponseWriter, r *http.Request) {
log.Debugf("websocket req: %q", r.URL)
websocket.HandleWebsocket(w, r)
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.Header.Get("Connection"), "Upgrade") {
websocket.HandleWebsocket(w, r)
} else {
log.Debugf("ui req: %q", r.URL)
webuiProxy.ServeHTTP(w, r)
}
log.Debugf("ui req: %q", r.URL)
webuiProxy.ServeHTTP(w, r)
})
srv := &http.Server{

View File

@ -9,7 +9,9 @@ import (
"net/http"
)
var upgrader = ws.Upgrader{}
var upgrader = ws.Upgrader{
CheckOrigin: checkOriginPermissive,
}
type WebsocketClient struct {
conn *ws.Conn
@ -35,6 +37,23 @@ func (WebsocketExecutionListener) OnExecutionStarted(title string) {
*/
}
/*
The default checkOrigin function checks that the origin (browser) matches the
request origin. However in OliveTin we expect many users to deliberately proxy
the connection with reverse proxies.
So, we just permit any origin. After some searching I'm not sure if this exposes
OliveTin to security issues, but it seems probably not. It would be possible to
create a config option like PermitWebsocketConnectionsFrom or something, but
I'd prefer if OliveTin works as much as possible "out of the box".
If this does expose OliveTin to security issues, it will be changed in the
future obviously.
*/
func checkOriginPermissive(r *http.Request) bool {
return true
}
func (WebsocketExecutionListener) OnExecutionFinished(logEntry *executor.InternalLogEntry) {
le := &pb.LogEntry{
ActionTitle: logEntry.ActionTitle,