cmd/derper, control/controlhttp: disable WebSocket compression

The data that we send over WebSockets is encrypted and thus not
compressible. Additionally, Safari has a broken implementation of compression
(see nhooyr/websocket#218) that makes enabling it actively harmful.

Fixes tailscale/corp#6943

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
pull/5654/head
Mihai Parparita 2 years ago committed by Mihai Parparita
parent 74674b110d
commit 1ce0e558a7

@ -33,6 +33,12 @@ func addWebSocketSupport(s *derp.Server, base http.Handler) http.Handler {
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
Subprotocols: []string{"derp"}, Subprotocols: []string{"derp"},
OriginPatterns: []string{"*"}, OriginPatterns: []string{"*"},
// Disable compression because we transmit WireGuard messages that
// are not compressible.
// Additionally, Safari has a broken implementation of compression
// (see https://github.com/nhooyr/websocket/issues/218) that makes
// enabling it actively harmful.
CompressionMode: websocket.CompressionDisabled,
}) })
if err != nil { if err != nil {
log.Printf("websocket.Accept: %v", err) log.Printf("websocket.Accept: %v", err)

@ -82,6 +82,12 @@ func acceptWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
Subprotocols: []string{upgradeHeaderValue}, Subprotocols: []string{upgradeHeaderValue},
OriginPatterns: []string{"*"}, OriginPatterns: []string{"*"},
// Disable compression because we transmit Noise messages that are not
// compressible.
// Additionally, Safari has a broken implementation of compression
// (see https://github.com/nhooyr/websocket/issues/218) that makes
// enabling it actively harmful.
CompressionMode: websocket.CompressionDisabled,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not accept WebSocket connection %v", err) return nil, fmt.Errorf("Could not accept WebSocket connection %v", err)

Loading…
Cancel
Save