Watch out for DoS when using Rust’s Hyper package
jfrog.com
jfrog.com
I see that there's an 1.0 RC release and the offending API seems to have changed and is probably not amenable to this type of misuse any more. The article authors could have easily added some info about that -- I certainly would have appreciated not having to go looking for that myself.
Perhaps the view taken is that this isn't a hyper problem? i.e. hyper is open and unrestricted by design and it is the package users responsibility to not point said unrestricted gun at their foot
Agree though that either way some mention of hyper interaction would be good here
Highlighting “unsafe” in red in an article about a Rust package when talking about something which is not Unsafe is so cursed.
I don't think Hyper itself was the problem though, frameworks like Axum are where things should be fixed. Hyper is intended to be used as a low-level library, so it should allocate exactly what size the programmer requested and the responsibility of length checking should be the system programmer's burden.
Ideally they want to be using formal methods, dependent typing, but instead bring that to Rust and put unsafe even on code that doesn't do anything related to low level memory handling or concurrency.
to_bytes(body) -> Bytes
function at all ?Only a
to_bytes(body: B, max_size: Option<usize>)
This way if someone REALLY wants the behavior that potentially results in a crash, they still have access to it, but have to be really explicit about it.But HTTP implementations like these are not really meant to directly face the internet. They usually sit behind reverse proxies/API gateways/CDNs.
I am a bit disconcerted that something that apparently is warned against in the docs, is done across several "big" packages that use Hyper. Maybe with a more appropriate name exposed by the library, for example `to_bytes_unchecked`, such "bad" uses would be less wide-spread.
Also for ref :)
AFAIK there's a proposal: https://rust-lang.github.io/rfcs/2116-alloc-me-maybe.html
but that's not entirely sufficient. Even ignoring overcommit shenanigans of Linux, an ever-growing request can cause a lot of strain on the process or the OS before it finally makes allocations fail.
Hell, a streaming consumer which doesn't require and check the content-length might even spin forever on CPU if a malicious client keeps sending data.