From a6fd4f12a838750098d0423b47140ed601983fa0 Mon Sep 17 00:00:00 2001 From: Jose M Perez Date: Tue, 5 Oct 2021 18:21:03 +0200 Subject: [PATCH] Disable ws compression if constraints clash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the client does not provide the "client_max_window_bits" option, the server must be able to handle a sliding window of up to 32,768 bytes. In case that the window has a lower limit set by options, compression must be disabled. Co-authored-by: Ignacio Martínez --- src/cow_ws.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cow_ws.erl b/src/cow_ws.erl index 3bb46c5..db6be6d 100644 --- a/src/cow_ws.erl +++ b/src/cow_ws.erl @@ -133,6 +133,8 @@ negotiate_permessage_deflate1(Params, Extensions, Opts) -> ignore; {#{client_max_window_bits := CB}, _} when CB > ClientMaxWindowBits -> ignore; + {Negotiated, _} when not is_map_key(client_max_window_bits_set, Negotiated), ClientMaxWindowBits < 15 -> + ignore; {Negotiated, RespParams2} -> %% We add the configured max window bits if necessary. RespParams = case Negotiated of @@ -165,12 +167,14 @@ negotiate_params([{<<"client_max_window_bits">>, Max}|Tail], Negotiated, RespPar error -> ignore; CB when CB =< CB0 -> - negotiate_params(Tail, Negotiated#{client_max_window_bits => CB}, + negotiate_params(Tail, + Negotiated#{client_max_window_bits => CB, + client_max_window_bits_set => true}, [<<"; client_max_window_bits=">>, Max|RespParams]); %% When the client sends window bits larger than the server wants %% to use, we use what the server defined. _ -> - negotiate_params(Tail, Negotiated, + negotiate_params(Tail, Negotiated#{client_max_window_bits_set => true}, [<<"; client_max_window_bits=">>, integer_to_binary(CB0)|RespParams]) end; negotiate_params([{<<"server_max_window_bits">>, Max}|Tail], Negotiated, RespParams) ->