meh / elixir-socket

Socket wrapping for Elixir.
691 stars 119 forks source link

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

Open Speedkore opened 7 years ago

Speedkore commented 7 years ago

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

meh commented 7 years ago

The server/client should fragment the packets.

Speedkore commented 7 years ago

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!!