-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Request with Transfer-Encoding: chunked and Content-Length is valid per RFC, but rejected with HPE_UNEXPECTED_CONTENT_LENGTH #517
Comments
There is one more sentence right after your quote:
|
I believe that there is an identical code path in http-parser with regards to handling this. |
One more sentence later it states how this requests must be handled by proxies, which indicates that they should be processed, not outright rejected:
|
😄
So "ought to be handled as an error" at best translates as "SHOULD be handled as an error". There is a paragraph in RFC 6919 as well (even though it is not referenced in RFC 7230):
|
I'm inclined to close this issue as it seems that the requirements of protocol specification are very clear on this. |
Also nginx's header parser: https://github.com/nginx/nginx/blob/76ac67b36f2db9acb2aeb4672f0aeaa8008e7d93/src/http/ngx_http_request.c#L1954-L1962
Can't agree with that. The whole paragraph is about how to handle this situation instead of 'server MUST treat it as protocol error'. |
FWIW i would agree with @veshij that in RFC terms "MUST" beats both "ought to" and "SHOULD". Also smuggling is not an issue if "Content-Length" is removed. |
MUST obviously applies only when the request gets "proxied"/forwarded to downstream:
If there is an error during the parsing step and it doesn't get forwarded at all - the above statement has no effect. |
Is there any downsides which I might be missing in trying to serve traffic with removed Content-Length header as RFC allows such behaviour? As @SaveTheRbtz mentioned - smuggling won't be an issue. There are some amount of clients in wild which behave in such way (both headers set) and they are successfully served if there is a proxy such an nginx in front of application using http-parser, but it's not possible to use http-parser in a proxy itself. |
This is a good question. It is not convincing that removing With this in mind, let's see if other maintainers have different opinion on this: @bnoordhuis @mscdex @nodejs/http |
Just for historical context...The behavior for proxies removing content-length exists specifically because attackers were leveraging differences in how various implementations handled the presence of the content-length header. Specifically, some would give the chunked encoding precedence while others would give content length precedence. This difference could be used by attackers to effectively smuggle multiple requests through a proxy that implemented one behavior to an origin server implementing the other. Node.js is not designed as a proxy (even if it can be used as such) so the must requirement that the spec assigns to proxies does not apply here. And our strict handling of the header when using chunked falls is compliant with the spec which recommends that it be treated as an error. That said, the spec also gives us room to be lenient and simply ignore the header, in which case we should not pass it on to application code. I would not want to change the default strict behavior, but adding an option to allow more lenient handling would be fine I think so long as the presence of the header is completely ignored. |
Heh... I just saw that this issue is in the http-parser repo and not the node repo... Same answer tho ;) providing an option for lenient handling should be fine. |
To summarize: the ask is to allow both What are the exact semantics?
How should the opt-in work? There's not much wiggle room in |
My personal opinion based on reading RFC:
Consider requests with both
Ignore
Same as above, ignore
Same as above, ignore |
Also as there is some active work on envoyproxy/envoy#5155 - It'd be nice to have consistent change in llhttp library. |
What do you think @bnoordhuis @indutny ? |
will additional field in |
Can someone take a look at the PR, please? |
Fixes: nodejs#517 PR-URL: nodejs#518 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Pierce Lopez <[email protected]>
Current implementation rejects requests with
Transfer-Encoding: chunked
andContent-Length
headers with HPE_UNEXPECTED_CONTENT_LENGTH.https://github.com/nodejs/http-parser/blob/master/http_parser.c#L1804-L1815
But per https://tools.ietf.org/html/rfc7230#section-3.3.3 that's a valid http request,
Content-Length
must be ignored:llhttp parser has the correct behavior: https://github.com/nodejs/llhttp/blob/master/src/native/http.c#L50
The text was updated successfully, but these errors were encountered: