Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect responses for invalid or multiple content-length #900

Closed
vladtcvs opened this issue Feb 2, 2018 · 10 comments
Closed

Incorrect responses for invalid or multiple content-length #900

vladtcvs opened this issue Feb 2, 2018 · 10 comments
Assignees

Comments

@vladtcvs
Copy link
Contributor

vladtcvs commented Feb 2, 2018

According to RFC7230 3.3.3.4, if we have 2 or more different content-length, for response we must respond 400 to client, and for backend response we must response 502.

Now we have 403 and 500

@vladtcvs
Copy link
Contributor Author

vladtcvs commented Feb 2, 2018

virtualbox_tempesta_02_02_2018_14_24_36
virtualbox_tempesta_02_02_2018_14_25_06

@vladtcvs
Copy link
Contributor Author

vladtcvs commented Feb 2, 2018

Tests for this case created as part of #619

@krizhanovsky
Copy link
Contributor

This is also subject for #541, protection against HTTP Request Splitting attack, so please update the Wiki page when the issue is finished. We don't need Frang rules since this is prohibited by the RFC, so the parser must be adjusted instead.

@krizhanovsky krizhanovsky added this to the 0.6 KTLS milestone Feb 2, 2018
@vladtcvs
Copy link
Contributor Author

vladtcvs commented Feb 2, 2018

https://tools.ietf.org/html/rfc7230#section-3.3.3

In requests like

Content-Length: 123
Content-Length: 124

,

Content-Length: invalid

,

Content-Length: 123, 124

we must reply 400

In same cases for responses we must reply 502

In cases of equal content length in request

Content-Length: 123
Content-Length: 123

,

Content-Length: 123, 123

we must reject OR merge into 1 header

Content-Length: 123

@vladtcvs
Copy link
Contributor Author

vladtcvs commented Feb 2, 2018

I think, in case of multiple equal content-length in response, we should also merge them or reject.
I haven't found this in rfc, but it looks like good idea

@vladtcvs
Copy link
Contributor Author

vladtcvs commented Feb 2, 2018

also i think we should remove content-length header in case of chunked body

@vankoven
Copy link
Contributor

vankoven commented Feb 2, 2018

we should also merge them or reject. I haven't found this in rfc, but it looks like good idea

You're absolutely right:
RFC 7230 3.3.2

If a message is received that has multiple Content-Length header
fields with field-values consisting of the same decimal value, or a
single Content-Length header field with a field value containing a
list of identical decimal values (e.g., "Content-Length: 42, 42"),
indicating that duplicate Content-Length header fields have been
generated or combined by an upstream message processor, then the
recipient MUST either reject the message as invalid or replace the
duplicated field-values with a single valid Content-Length field
containing that decimal value prior to determining the message body
length or forwarding the message.

@vladtcvs
Copy link
Contributor Author

vladtcvs commented Feb 2, 2018

I've misunderstood "If a message is received" as request message. It looks that case of response is also related here

@vankoven
Copy link
Contributor

vankoven commented Feb 2, 2018

also i think we should remove content-length header in case of chunked body

Yes, we must do that. RFC 7230 3.3.3 point 3:

If a message is received with both a Transfer-Encoding and a
Content-Length header field, the Transfer-Encoding overrides the
Content-Length. Such a message might indicate an attempt to
perform request smuggling (Section 9.5) or response splitting
(Section 9.4) and ought to be handled as an error. A sender MUST
remove the received Content-Length field prior to forwarding such
a message downstream.

@aleksostapenko
Copy link
Contributor

aleksostapenko commented Aug 10, 2018

All specified above cases are already handled in Tempesta FW code, according the most strict scenario described in RFC: all HTTP messages with misused Content-Length headers (multiple headers, multiple values, usage with Transfer-Encoding header) are rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants