yaws icon indicating copy to clipboard operation
yaws copied to clipboard

Maximum allowed size for HTTP headers?

Open etnt opened this issue 5 years ago • 7 comments

Should Yaws have a way to limit the acceptable size of the received HTTP headers? I think so :-)

See also: https://stackoverflow.com/questions/686217/maximum-on-http-header-values

etnt avatar Dec 05 '19 11:12 etnt

Currently there's a hard-coded limit of 1000 on the number of headers; see https://github.com/klacke/yaws/blob/master/src/yaws.erl#L2697 and https://github.com/klacke/yaws/blob/master/src/yaws.erl#L2835-L2836 . I agree it would be better to have a configurable size limit instead.

vinoski avatar Dec 05 '19 12:12 vinoski

Sorry if I was unclear, but I meant the max allowed size of a header value. The reasoning behind this is to try and defend the system from malicious code sending in huge amount of data in a HTTP header causing the memory to run out.

etnt avatar Dec 11 '19 07:12 etnt

Yes, I agree that also needs to be addressed.

vinoski avatar Dec 13 '19 13:12 vinoski

Note BTW that the maximum length of a request header is controlled by the packet_size hard-coded to 16#4000 on line https://github.com/klacke/yaws/blob/master/src/yaws.erl#L2697 — if a request containing a header longer than that limit is sent, yaws:do_recv/3,4 returns {error,emsgsize}.

vinoski avatar Dec 15 '19 22:12 vinoski

Yes, and no. Getting the headers is done by calling do_recv(CliSock, 0, SSL) which will get a possibly infinite line.

gnaeser avatar Jan 21 '20 08:01 gnaeser

I don't see how it can get an infinite line given the max packet size of 16#4000 set on the socket. I've run experiments with headers that exceed the 16#4000 limit and as I mentioned earlier, {error, emsgsize} is the result. Do you have an example or test case that shows otherwise?

vinoski avatar Jan 21 '20 12:01 vinoski

Yes, a clean installation does not express the problem with long lines. I will investigate.

gnaeser avatar Jan 28 '20 13:01 gnaeser