From f758fe52c4ec2a5ff5ebf2b1a784ca2fe9ff839b Mon Sep 17 00:00:00 2001 From: Adrian-Stefan Mares Date: Tue, 19 Dec 2023 18:49:15 +0200 Subject: [PATCH] console: Disable WebSocket compression for Safari --- go.mod | 1 + go.sum | 2 ++ pkg/console/internal/events/events.go | 14 +++++++++++++- tools/go.mod | 1 + tools/go.sum | 2 ++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index be8e476f53..1b7361d68f 100644 --- a/go.mod +++ b/go.mod @@ -55,6 +55,7 @@ require ( github.com/klauspost/compress v1.17.2 github.com/kr/pretty v0.3.1 github.com/lib/pq v1.10.9 + github.com/mileusna/useragent v1.3.4 github.com/mitchellh/mapstructure v1.5.0 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/nats-io/nats-server/v2 v2.10.4 diff --git a/go.sum b/go.sum index f2db5ff523..3b61876c02 100644 --- a/go.sum +++ b/go.sum @@ -548,6 +548,8 @@ github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvls github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= +github.com/mileusna/useragent v1.3.4 h1:MiuRRuvGjEie1+yZHO88UBYg8YBC/ddF6T7F56i3PCk= +github.com/mileusna/useragent v1.3.4/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc= github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= diff --git a/pkg/console/internal/events/events.go b/pkg/console/internal/events/events.go index e1f66c33db..3d8a106d8c 100644 --- a/pkg/console/internal/events/events.go +++ b/pkg/console/internal/events/events.go @@ -22,6 +22,7 @@ import ( "time" "github.com/gorilla/mux" + "github.com/mileusna/useragent" "go.thethings.network/lorawan-stack/v3/pkg/auth/rights" "go.thethings.network/lorawan-stack/v3/pkg/config" "go.thethings.network/lorawan-stack/v3/pkg/console/internal/events/eventsmux" @@ -90,10 +91,21 @@ func (h *eventsHandler) handleEvents(w http.ResponseWriter, r *http.Request) { return } + // Safari versions above 15 cannot handle compression correctly when the + // `NSURLSession Websocket` experimental feature is enabled (it is enabled by default). + // Versions above 17 still show the same issues, but the experimental feature is baseline. + // As such, we disable compression for Safari for all versions in order to ensure the best + // user experience. + // https://github.com/TheThingsNetwork/lorawan-stack/issues/6782 + compressionMode := websocket.CompressionContextTakeover + if ua := useragent.Parse(r.UserAgent()); ua.Name == useragent.Safari { + compressionMode = websocket.CompressionDisabled + } + conn, err := websocket.Accept(w, r, &websocket.AcceptOptions{ Subprotocols: []string{protocolV1}, InsecureSkipVerify: true, // CORS is not enabled for APIs. - CompressionMode: websocket.CompressionContextTakeover, + CompressionMode: compressionMode, }) if err != nil { logger.WithError(err).Debug("Failed to accept WebSocket") diff --git a/tools/go.mod b/tools/go.mod index e767a14246..b615441896 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -150,6 +150,7 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + github.com/mileusna/useragent v1.3.4 // indirect github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.1 // indirect diff --git a/tools/go.sum b/tools/go.sum index d5263f63d2..187d51fe46 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -562,6 +562,8 @@ github.com/mattn/goveralls v0.0.12/go.mod h1:44ImGEUfmqH8bBtaMrYKsM65LXfNLWmwaxF github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= +github.com/mileusna/useragent v1.3.4 h1:MiuRRuvGjEie1+yZHO88UBYg8YBC/ddF6T7F56i3PCk= +github.com/mileusna/useragent v1.3.4/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc= github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=