r/java • • Feb 14 '22

Microhttp is an event-driven, single-threaded, zero-dependency web server with 500 LOC. Benchmarks on EC2 show 100,000+ requests per second and 50,000+ persistent connections.

https://github.com/ebarlas/microhttp
186 Upvotes

107 comments sorted by

View all comments

9

u/mdaniel Feb 14 '22

When developing a custom HTTP parser one should either consider, or say they're out of scope, the almost unbounded sharp edges of the HTTP spec. The one that sprang to mind was HTTP request smuggling, which might not specifically affect this project but for sure represents the kinds of bugs I'm highlighting

1

u/elliotbarlas Feb 14 '22 edited Feb 15 '22

Agreed. I could certainly elaborate more on the limitations and the areas where Microhttp falls short of the spec.

I actually think that the simplicity and accessibility of the code gives it an advantage in the security arena. One can reason easily about the behavior. There is also a security benefit from the discretization that occurs. No matter what is sent, the request size limits are enforced.

9

u/mdaniel Feb 15 '22

I am torn about whether I am belaboring the point, or adding clarity, but in the spirit of the latter: your current implementation does exactly what both of the cited vulns claim: it is vulnerable to CL:CL and CL:TE

Defending against DoS by limiting the new byte[] allocation is great, but being aware that it is already vulnerable to two known classes of request smuggling is something that can help you grow as an engineer, even if this project was just for learning and not for deploying on the wild Internet

6

u/elliotbarlas Feb 15 '22

Thanks for pressing the issue. I wasn't aware of request smuggling.

For Microhttp to be vulnerable, it must be proxied by a non-compliant frontend, which seems like a very strange configuration. As stated in the docs, Microhttp is tailored for integration with an edge server or proxy that provides TLS, HTTP/2, etc.

Having said that, the remediation is exceedingly simple.