Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(724)

Unified Diff: net/http/http_stream_parser.cc

Issue 2253653002: Only allow HTTP/0.9 support on default ports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_stream_parser.h ('k') | net/http/http_stream_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_stream_parser.cc
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index b543af5c68b6bb9b513d82fbe7ba621251865bfd..87e34da7bd470eefcff36af46b9ca22bc562299e 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -25,6 +25,7 @@
#include "net/socket/client_socket_handle.h"
#include "net/socket/ssl_client_socket.h"
#include "net/ssl/token_binding.h"
+#include "url/url_canon.h"
namespace net {
@@ -207,6 +208,7 @@ HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection,
request_(request),
request_headers_(nullptr),
request_headers_length_(0),
+ http_09_on_non_default_ports_enabled_(false),
read_buf_(read_buffer),
read_buf_unused_offset_(0),
response_header_start_offset_(-1),
@@ -997,7 +999,20 @@ int HttpStreamParser::ParseResponseHeaders(int end_offset) {
std::string(read_buf_->StartOfBuffer(), raw_headers.find('\0')));
headers = new HttpResponseHeaders(raw_headers);
} else {
- // Enough data was read -- there is no status line.
+ // Enough data was read -- there is no status line, so this is HTTP/0.9, or
+ // the server is broken / doesn't speak HTTP.
+
+ // If the port is not the default for the scheme, assume it's not a real
+ // HTTP/0.9 response, and fail the request.
+ // TODO(crbug.com/624462): Further restrict the cases in which we allow
+ // HTTP/0.9.
+ std::string scheme(request_->url.scheme());
+ if (!http_09_on_non_default_ports_enabled_ &&
+ url::DefaultPortForScheme(scheme.c_str(), scheme.length()) !=
+ request_->url.EffectiveIntPort()) {
+ return ERR_INVALID_HTTP_RESPONSE;
+ }
+
headers = new HttpResponseHeaders(std::string("HTTP/0.9 200 OK"));
if (request_->url.SchemeIsCryptographic()) {
« no previous file with comments | « net/http/http_stream_parser.h ('k') | net/http/http_stream_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698