Hello guys,
We are now managing a reverse proxy using seastar as its network stack. We recently ran into this issue in which an http resonse (coming form the backend) which has the wrong format causes an sstring overflow exception to occur in the parsing stage. I have traced and found out that this happened somewhere in the file response_parser.hh. This eventually leads to that response (although not in the correct format, see below) never reaches its destination.In particular, the response has a whitespace in front of one of its field names, like this:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
That's quite an old page.
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
Content-Length: 88
Content-Type: text/html
Here are the relevant lines from response_parser.rl:
header_1st = (field sp_ht* ':' value :> crlf) %assign_field;
header_cont = (sp_ht+ value sp_ht* crlf) %extend_field;
So as far as I can tell, the parser should treat it as one long
header:
Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32)
Notice the whitespace before the "Server" field name.I'm aksing for anyway to handle this situation other than raising an sstring overflow, for example: ignoring the whole line and the response can still be futher processed. Any help would be greatly appriaciated!
Per my reading of the code it should work. Can you catch the
exception in gdb and see where it comes from?
Regards,Dũng
--
You received this message because you are subscribed to the Google Groups "seastar-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seastar-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/seastar-dev/9cb1040d-5fb3-4267-a4c1-83be69732a96n%40googlegroups.com.
Hello guys,We are now managing a reverse proxy using seastar as its network stack. We recently ran into this issue in which an http resonse (coming form the backend) which has the wrong format causes an sstring overflow exception to occur in the parsing stage. I have traced and found out that this happened somewhere in the file response_parser.hh. This eventually leads to that response (although not in the correct format, see below) never reaches its destination.In particular, the response has a whitespace in front of one of its field names, like this:HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMTContent-Length: 88Content-Type: text/htmlNotice the whitespace before the "Server" field name.I'm aksing for anyway to handle this situation other than raising an sstring overflow, for example: ignoring the whole line and the response can still be futher processed. Any help would be greatly appriaciated!
Note that this server, Apache 2.2.14, is 12 years old by now, so it's still possible that it is using this deprecated protocol feature, but...Actually that is just an example I made up, so no need for speculate about that old Apache server, the real response I ran into looks like this:Notice the space in front of enableVersionHeader.
What is a "sstring overflow"? Do we have some sort of buffer overflow (a serious security risk!) or we throw an exception (which sounds fine)?Luckily it threw an exception :)I agree that it's reasonable to let protocol errors like this one be ignored, instead of failing the request. We could even make the client code's strict RFC compliance optional.I totally agree with this. This is our current situation at the momment and I guess the best way to handle this is not to fail the request.
A proxy or gateway that receives an obs-fold in a response message that is not within a message/http container MUST either discard the message and replace it with a 502 (Bad Gateway) response, preferably with a representation explaining that unacceptable line folding was received, or replace each received obs-fold with one or more SP octets prior to interpreting the field value or forwarding the message downstream.
To view this discussion on the web visit https://groups.google.com/d/msgid/seastar-dev/3bcf0cdb-3d0b-49ee-ad43-c1e798a68597n%40googlegroups.com.
Hello guys,
Regarding handling obs-fold in http header, I have finally found the root cause to the problem. However, I want to hear you guys' opinion on this, since there is a high chance that this is a seastar bug.
Steps to reproduce:Foward to the client a http response (from the backend) with a segment like this (obs-fold style):Expectation: The client will receive something like this:Reality: an sstring overflow is thrown, parsing fails so the reponse never reaches the client.What I found out is that the problem comes this:header_cont = (sp_ht+ value sp_ht* crlf) %extend_field;Notice that value and sp_ht* stay next to each other. I can see that it is intended to eliminate trailing whitespaces (or tabs). However, I suspect that they conflict with each other, causing the parser to fail, since both can either contain spaces or not. Putting them together will cause a logical error (trailing whitespace(s) can belong to any of them, or both).
The field-content does not include any leading or trailing LWS: linear white space occurring before the first non-whitespace character of the field-value or after the last non-whitespace character of the field-value. Such leading or trailing LWS MAY be removed without changing the semantics of the field value.
To view this discussion on the web visit https://groups.google.com/d/msgid/seastar-dev/1e12cd5e-fba0-42bc-83de-5aa628758a69n%40googlegroups.com.
The strange thing is that it seems that in response_parser.rl only header_cont has this broken attempt to recognize trailing whitespace - the "header_1st" rule doesn't! So why do we need it in header_cont? I don't see any reason. It's a pure and simple bug.I totally agree. It makes no sense to check for only "header_cont" and then do nothing with "header_1st", my only guess is that the author tried it for "header_1st" too and and then parser failed (of course). I tried it myself and now any request (even without obs-fold) failed the exact same way. The fact that you said "initially as some sort of test / demo" makes me believe this even more.Come to think of it, I don't even know why (accept for historic accident) we have separate code for HTTP client and server header parsing. It should have been the same code :-(Agree! They are basically the same code doing the exact same thing.Now I want to fix this bug, can you tell me where do I start? Do I have to register an issue on https://github.com/scylladb/seastar/issues,
To view this discussion on the web visit https://groups.google.com/d/msgid/seastar-dev/38c9b26b-3523-4bd2-8be8-ea4c3fbf74d3n%40googlegroups.com.