elixir-socket icon indicating copy to clipboard operation
elixir-socket copied to clipboard

Is it possible to limit the transfer size in a correct way?

Open Speedkore opened this issue 6 years ago • 2 comments

i had to modify the source code in my way to limit big transfers, how could i do it in a right way? i never receive fragment packets or anything, if i send for example a file of 100MB it is done in one step by Socket.Web.recv() in memory

this is what i did, in file web.ex, line 577:

@spec recv(t, boolean, non_neg_integer, Keyword.t) :: { :ok, binary } | { :error, error } defp recv(%W{socket: socket, version: 13}, mask, length, options) do length = cond do length == 127 -> case socket |> Socket.Stream.recv(8, options) do { :ok, << length :: 64 >> } -> if length > 5_000_000 do {:error, :transfer_too_large} else length end

Speedkore avatar Oct 31 '17 11:10 Speedkore

The server/client should fragment the packets.

meh avatar Oct 31 '17 14:10 meh

I'm doing this to avoid a malicious attack from the client side that eats all the memory of the server, sending a large bunch of data. How do i tell the server to fragment packets when receiving them? or it's just enough what i did to avoid this kind of attack?

Thanks a lot for the response , you made a great library and it works very well!!

Speedkore avatar Oct 31 '17 16:10 Speedkore