Repository navigation
Description
Describe the bug
I stumbled upon an edge case where the server responds with HTTP/2 without an upgrade response to or from the client. Browsers, Burpsuite, curl, and some other tools take this in stride but the underly Golang libraries used by Nuclei are more strict.
Nuclei version
v2.3.2, compiled from github 05/23/2021.
Screenshot of the error or bug
I can't upload an image from here, so:
GET / HTTP/1.1
Host: <redacted>
User-Agent: Nuclei - Open-source project (github.com/projectdiscovery/nuclei)
HTTP/2 200 OK
Date: Thu, 13 May 2021 19:18:13 GMT
Content-Type: text/html;charset=UTF-8
Set-Cookie:...
I changed some of Nuclei's error handling so I could see more, and got:
net/http: HTTP/1.x transport connection broken: malformed HTTP version "HTTP/2"
Details
- I don't see that nuclei is specifically disabling HTTP/2, and it should be enabled by default as of 1.6. I can confirm Nuclei works against https://http2.golang.org/.
- After digging into Go's net/http quite too far, I think the problem lies in the fact that http/2 is supported but not very well implemented. This post details the exact some condition I found in the code--that Golang's request.go does not validate that
HTTP/2is valid (it would validateHTTP/2.0though :/). The logic can be seen here in the ParseHTTPVersion function (line 783), and per this issue it's just simply not supported by Golang unless using net/http2. - According it's own page, net/http2 is a work in progress and the "client work has just started"
Suggestions
As this is an edge case and I'm not sure how many servers this may impact, so I'm not sure what the right answer is for Nuclei.
- Obvious option is to start testing and using net/http2.
- Don't use Golang's built-in http modules, instead use lower-level functionality where you manually build requests (I think I saw nuclei has some of this already). This might be a better long-term strategy as Nuclei grows and tries to support more complex and non-standard requests.
- "Override" the Golang error by forcing the response to be
HTTP/2.0as talked about here or here (the latter seeming more straightforward). - Ignore me and my edge case. I used Burp to change the HTTP version. But perhaps spit out a warning that suggests a user do that.
I don't mind working on this and test it if I can get some direction from the core team as to how it could be fixed, or if this shouldn't be considered now. FWIW, back in the day I had to quickly move off perl's built in HTTP libraries because of things like this, so Nuclei should consider the future.
Cheers!
Activity
ehsandeep commentedon May 13, 2021
@sullo woah! Just wanted to say, thank you for writing this well-detailed issue with a list of suggestions to address this. We are looking into this and will be addressing this in the coming release of nuclei.
sullo commentedon May 14, 2021
No problem @ehsandeep. Glad to help.
Adding http2 auto fallback - proxy compatible
Mzack9999 commentedon May 25, 2021
@sullo Thanks again for the very detailed analysis. After further tests, it looks like that the http2 connection upgrade is already supported by the standard
net/httplibrary. I wasn't able to find a target replying directly withhttp/2and noticed the behavior happens mostly when using Burp as a proxy, as a conversion layer wraps thehttp/1.xprotocol to the binaryhttp/2one, but leaves thehttp/2version when converting back tohttp/1.xrepresentation, basically:The returned version lacks the minor version number required by the
net/httplibrary. I think the library implementation might be the correct one, as the stream happens within thehttp/1.xcontext and according to RFC2145, both major and minor version needs to be specified.I've implemented a patch in retryablehttp consisting of a retry strategy with a transport layer compatible with
http/2if the go error is related tohttp/2overhttp/1.x. Most likely, we will implement some low-level libraries to support non-standard requests (e.g., forhttp/2smuggling). Please let us know if this fixes the issue.sullo commentedon May 27, 2021
Trying those changes out but I'm experiencing the same behavior.
Curl:
When connecting directly , it still doesn't see the response from the server:
However, going through burpsuite (without changing HTTP/2 to HTTP/2.0 manually via a replace), it does see the 404:
It seems likely Burp is fixing the HTTP/2 in the background.
ehsandeep commentedon Jun 3, 2021
Hi @sullo,
Just to double-check, we pushed the fix in the following PR #731. Can you please confirm if you tested the fix with binary built from this PR, otherwise do you have an example host with this edge case that you can share will be helpful to confirm or prepare a new fix on our side?
dpnishant commentedon Jun 7, 2021
Doesn't seem to be fixed yet.

ehsandeep commentedon Jun 7, 2021
@dpnishant thanks for checking, I'm not sure if you checked out the PR branch and build binary to test changes, here is how you can do it if not already.
Building Nuclei from
bugfix-709-http2branch.Running nuclei binary build from
bugfix-709-http2branch.dpnishant commentedon Jun 8, 2021
@ehsandeep Yes I haven't tried with a local PR build. Will give it a shot.
ehsandeep commentedon Jun 12, 2021
Closing as this has been resolved and fixed in the latest release, fix is verified locally, we can reopen this again if we encounter more new edge cases to handle.
sullo commentedon Jun 17, 2021
Sorry I fell into a black-hole for a week here... but can confirm this is resolved. Thanks for the great support!
ehsandeep commentedon Jun 17, 2021
Thanks again for confirming @sullo