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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 if (response_header_start_offset_ >= 0) { | 961 if (response_header_start_offset_ >= 0) { |
962 received_bytes_ += end_offset; | 962 received_bytes_ += end_offset; |
963 headers = new HttpResponseHeaders( | 963 headers = new HttpResponseHeaders( |
964 HttpUtil::AssembleRawHeaders(read_buf_->StartOfBuffer(), end_offset)); | 964 HttpUtil::AssembleRawHeaders(read_buf_->StartOfBuffer(), end_offset)); |
965 } else { | 965 } else { |
966 // Enough data was read -- there is no status line, so this is HTTP/0.9, or | 966 // Enough data was read -- there is no status line, so this is HTTP/0.9, or |
967 // the server is broken / doesn't speak HTTP. | 967 // the server is broken / doesn't speak HTTP. |
968 | 968 |
969 // If the port is not the default for the scheme, assume it's not a real | 969 // If the port is not the default for the scheme, assume it's not a real |
970 // HTTP/0.9 response, and fail the request. | 970 // HTTP/0.9 response, and fail the request. |
971 // TODO(crbug.com/624462): Further restrict the cases in which we allow | 971 base::StringPiece scheme(request_->url.scheme_piece()); |
eroman
2017/01/24 00:37:29
[optional] style-nit: use assignment
mmenke
2017/01/24 17:27:02
Done. I find I tend to default to this style beca
| |
972 // HTTP/0.9. | |
973 std::string scheme(request_->url.scheme()); | |
974 if (!http_09_on_non_default_ports_enabled_ && | 972 if (!http_09_on_non_default_ports_enabled_ && |
975 url::DefaultPortForScheme(scheme.c_str(), scheme.length()) != | 973 url::DefaultPortForScheme(scheme.data(), scheme.length()) != |
976 request_->url.EffectiveIntPort()) { | 974 request_->url.EffectiveIntPort()) { |
977 return ERR_INVALID_HTTP_RESPONSE; | 975 // Allow Shoutcast responses over HTTP through, as it's somewhat common |
eroman
2017/01/24 00:37:29
nit: delete "through" as it feels redundant with "
mmenke
2017/01/24 17:27:02
Done.
| |
976 // and relies on HTTP/0.9 on weird ports to work. | |
eroman
2017/01/24 00:37:29
Can you add a link to an explanation of what the i
mmenke
2017/01/24 17:27:02
Done, link to the intent to implement (Bug has way
| |
977 if (read_buf_->offset() < 3 || scheme != "http" || | |
978 !base::LowerCaseEqualsASCII( | |
979 base::StringPiece(read_buf_->StartOfBuffer(), 3), "icy")) { | |
980 return ERR_INVALID_HTTP_RESPONSE; | |
981 } | |
978 } | 982 } |
979 | 983 |
980 headers = new HttpResponseHeaders(std::string("HTTP/0.9 200 OK")); | 984 headers = new HttpResponseHeaders(std::string("HTTP/0.9 200 OK")); |
981 } | 985 } |
982 | 986 |
983 // Check for multiple Content-Length headers when the response is not | 987 // Check for multiple Content-Length headers when the response is not |
984 // chunked-encoded. If they exist, and have distinct values, it's a potential | 988 // chunked-encoded. If they exist, and have distinct values, it's a potential |
985 // response smuggling attack. | 989 // response smuggling attack. |
986 if (!headers->IsChunkEncoded()) { | 990 if (!headers->IsChunkEncoded()) { |
987 if (HeadersContainMultipleCopiesOfField(*headers, "Content-Length")) | 991 if (HeadersContainMultipleCopiesOfField(*headers, "Content-Length")) |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 } | 1178 } |
1175 return false; | 1179 return false; |
1176 } | 1180 } |
1177 | 1181 |
1178 bool HttpStreamParser::SendRequestBuffersEmpty() { | 1182 bool HttpStreamParser::SendRequestBuffersEmpty() { |
1179 return request_headers_ == nullptr && request_body_send_buf_ == nullptr && | 1183 return request_headers_ == nullptr && request_body_send_buf_ == nullptr && |
1180 request_body_read_buf_ == nullptr; | 1184 request_body_read_buf_ == nullptr; |
1181 } | 1185 } |
1182 | 1186 |
1183 } // namespace net | 1187 } // namespace net |
OLD | NEW |