OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 // HTTP/0.9 responses, but it was most likely an error, so just return | 776 // HTTP/0.9 responses, but it was most likely an error, so just return |
777 // ERR_EMPTY_RESPONSE instead. If the connection was reused, just pass | 777 // ERR_EMPTY_RESPONSE instead. If the connection was reused, just pass |
778 // on the original connection close error, as rather than being an | 778 // on the original connection close error, as rather than being an |
779 // empty HTTP/0.9 response it's much more likely the server closed the | 779 // empty HTTP/0.9 response it's much more likely the server closed the |
780 // socket before it received the request. | 780 // socket before it received the request. |
781 if (!connection_->is_reused()) | 781 if (!connection_->is_reused()) |
782 return ERR_EMPTY_RESPONSE; | 782 return ERR_EMPTY_RESPONSE; |
783 return result; | 783 return result; |
784 } | 784 } |
785 | 785 |
786 // Accepting truncated headers over HTTPS is a potential security | |
787 // vulnerability, so just return an error in that case. Accepting a < 8 | |
davidben
2015/08/06 19:01:46
Maybe new paragraph after "in that case." and
"Ac
mmenke
2015/08/06 19:12:44
Done.
| |
788 // byte response over HTTPS would allow a MITM to truncate an HTTP response | |
davidben
2015/08/06 19:01:46
(Strictly speaking, this is only possible if the p
davidben
2015/08/06 19:01:46
Maybe HTTP response -> HTTP/1.x status line
mmenke
2015/08/06 19:12:44
Done.
mmenke
2015/08/06 19:12:44
Done.
| |
789 // to look like a short HTTP/0.9 responses. Out of paranoia, defend against | |
davidben
2015/08/06 19:01:46
Maybe "Out of paranoia" -> "To ensure that all res
davidben
2015/08/06 19:01:46
responses -> response
mmenke
2015/08/06 19:12:44
Done. Though I still say concern about the bogus
mmenke
2015/08/06 19:12:44
Done.
| |
790 // that case here as well. | |
791 // TODO(mmenke): Returning ERR_RESPONSE_HEADERS_TRUNCATED when a response | |
792 // looks like an HTTP/0.9 response is weird. Should either come up with | |
793 // another error code, or, better, disable HTTP/0.9 over HTTPS (and give | |
794 // that a new error code). | |
795 if (request_->url.SchemeIsCryptographic()) { | |
796 io_state_ = STATE_DONE; | |
797 return ERR_RESPONSE_HEADERS_TRUNCATED; | |
798 } | |
799 | |
786 // Parse things as well as we can and let the caller decide what to do. | 800 // Parse things as well as we can and let the caller decide what to do. |
787 int end_offset; | 801 int end_offset; |
788 if (response_header_start_offset_ >= 0) { | 802 if (response_header_start_offset_ >= 0) { |
789 // The response looks to be a truncated set of HTTP headers. | 803 // The response looks to be a truncated set of HTTP headers. |
790 | |
791 // Accepting truncated headers over HTTPS is a potential security | |
792 // vulnerability, so just return an error in that case. | |
793 if (request_->url.SchemeIsCryptographic()) { | |
794 io_state_ = STATE_DONE; | |
795 return ERR_RESPONSE_HEADERS_TRUNCATED; | |
796 } | |
797 | |
798 io_state_ = STATE_READ_BODY_COMPLETE; | 804 io_state_ = STATE_READ_BODY_COMPLETE; |
799 end_offset = read_buf_->offset(); | 805 end_offset = read_buf_->offset(); |
800 RecordHeaderParserEvent(HEADER_ALLOWED_TRUNCATED_HEADERS); | 806 RecordHeaderParserEvent(HEADER_ALLOWED_TRUNCATED_HEADERS); |
801 } else { | 807 } else { |
802 // The response is apparently using HTTP/0.9. Treat the entire response | 808 // The response is apparently using HTTP/0.9. Treat the entire response |
803 // as the body. | 809 // as the body. |
804 end_offset = 0; | 810 end_offset = 0; |
805 } | 811 } |
806 int rv = ParseResponseHeaders(end_offset); | 812 int rv = ParseResponseHeaders(end_offset); |
807 if (rv < 0) | 813 if (rv < 0) |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 request_body->IsInMemory() && | 1105 request_body->IsInMemory() && |
1100 request_body->size() > 0) { | 1106 request_body->size() > 0) { |
1101 uint64 merged_size = request_headers.size() + request_body->size(); | 1107 uint64 merged_size = request_headers.size() + request_body->size(); |
1102 if (merged_size <= kMaxMergedHeaderAndBodySize) | 1108 if (merged_size <= kMaxMergedHeaderAndBodySize) |
1103 return true; | 1109 return true; |
1104 } | 1110 } |
1105 return false; | 1111 return false; |
1106 } | 1112 } |
1107 | 1113 |
1108 } // namespace net | 1114 } // namespace net |
OLD | NEW |