You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The doc comment for Response::into_reader() says this:
Note: If you use read_to_end() on the resulting reader, a malicious server might return enough bytes to exhaust available memory. If you’re making requests to untrusted servers, you should use .take() to limit the response bytes read.
This is all well and good, but it makes me interpret the example snippet below as being intended to handle that threat model, wherein the server may return a response crafted to cause you to crash in some way.
(Note that I am ignoring the asserts here, as well as .unwrap(), "don't panic if you care about not panicking when the server does something wrong" is well known enough anyway...)
The problem here is that the Content-Length header is being trusted to be okay to pass to Vec::with_capacity(), when it's server controlled in exactly the same way as the actual size of the body. If a user is using .take(10_000_000) to limit the size of the body they'll process, they should also use std::cmp::min(len, 10_000_000) when computing what to pass into Vec::with_capacity() there.
The text was updated successfully, but these errors were encountered:
I will accepts PRs against the two 2.x branches: 2.11.x-msrv1.67 and 2.12.x-msrv1.71 though I think the more important issue is to clarify this in the 3.x/main branch and the API there is different.
The doc comment for
Response::into_reader()
says this:This is all well and good, but it makes me interpret the example snippet below as being intended to handle that threat model, wherein the server may return a response crafted to cause you to crash in some way.
(Note that I am ignoring the asserts here, as well as
.unwrap()
, "don't panic if you care about not panicking when the server does something wrong" is well known enough anyway...)The problem here is that the
Content-Length
header is being trusted to be okay to pass toVec::with_capacity()
, when it's server controlled in exactly the same way as the actual size of the body. If a user is using.take(10_000_000)
to limit the size of the body they'll process, they should also usestd::cmp::min(len, 10_000_000)
when computing what to pass intoVec::with_capacity()
there.The text was updated successfully, but these errors were encountered: