Skip to content

Commit c632534

Browse files
committed
Don't treat max_inflate_ratio as a permessage deflate wire parameter
1 parent b084b37 commit c632534

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/bandit/websocket/permessage_deflate.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ defmodule Bandit.WebSocket.PerMessageDeflate do
2121
deflate_context: nil,
2222
max_inflate_ratio: nil
2323

24-
@valid_params ~w[server_no_context_takeover client_no_context_takeover server_max_window_bits client_max_window_bits max_inflate_ratio]
24+
# The four extension parameters defined by RFC7692§7. Note that max_inflate_ratio is a
25+
# Bandit-internal option (sourced from server config in init/2), NOT a wire parameter:
26+
# including it here would both accept it in client offers and echo it back in the
27+
# handshake response, and RFC7692§7 forbids a server from including parameters not
28+
# defined for the extension
29+
@valid_params ~w[server_no_context_takeover client_no_context_takeover server_max_window_bits client_max_window_bits]
2530

2631
def negotiate(requested_extensions, opts) do
2732
:proplists.get_all_values("permessage-deflate", requested_extensions)

test/bandit/websocket/http1_handshake_test.exs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,31 @@ defmodule WebSocketHTTP1HandshakeTest do
274274
refute Keyword.get(headers, :"sec-websocket-extensions")
275275
end
276276

277+
test "declines permessage-deflate offers containing the internal max_inflate_ratio option",
278+
context do
279+
client = SimpleWebSocketClient.tcp_client(context)
280+
281+
SimpleHTTP1Client.send(client, "GET", "/compress", [
282+
"Host: server.example.com",
283+
"Upgrade: WeBsOcKeT",
284+
"Connection: UpGrAdE",
285+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==",
286+
"Sec-WebSocket-Version: 13",
287+
"Sec-WebSocket-Extensions: permessage-deflate;max_inflate_ratio=5"
288+
])
289+
290+
assert {:ok, "101 Switching Protocols", headers, <<>>} =
291+
SimpleHTTP1Client.recv_reply(client)
292+
293+
assert Keyword.get(headers, :upgrade) == "websocket"
294+
assert Keyword.get(headers, :connection) == "Upgrade"
295+
assert Keyword.get(headers, :"sec-websocket-accept") == "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
296+
297+
# max_inflate_ratio is a Bandit config option, not an RFC7692 extension parameter;
298+
# an offer containing it is declined (and it must never be echoed in the response)
299+
refute Keyword.get(headers, :"sec-websocket-extensions")
300+
end
301+
277302
test "does not negotiate permessage-deflate if the client sends repeat option values",
278303
context do
279304
client = SimpleWebSocketClient.tcp_client(context)

0 commit comments

Comments
 (0)