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

Side by Side Diff: net/url_request/url_request.cc

Issue 1017583002: Set Origin header to "null" for cross origin redirects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Address more of David's comments Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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/url_request/url_request.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 19 matching lines...) Expand all
30 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
31 #include "net/http/http_util.h" 31 #include "net/http/http_util.h"
32 #include "net/ssl/ssl_cert_request_info.h" 32 #include "net/ssl/ssl_cert_request_info.h"
33 #include "net/url_request/redirect_info.h" 33 #include "net/url_request/redirect_info.h"
34 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
35 #include "net/url_request/url_request_error_job.h" 35 #include "net/url_request/url_request_error_job.h"
36 #include "net/url_request/url_request_job.h" 36 #include "net/url_request/url_request_job.h"
37 #include "net/url_request/url_request_job_manager.h" 37 #include "net/url_request/url_request_job_manager.h"
38 #include "net/url_request/url_request_netlog_params.h" 38 #include "net/url_request/url_request_netlog_params.h"
39 #include "net/url_request/url_request_redirect_job.h" 39 #include "net/url_request/url_request_redirect_job.h"
40 #include "url/gurl.h"
41 #include "url/origin.h"
40 42
41 using base::Time; 43 using base::Time;
42 using std::string; 44 using std::string;
43 45
44 namespace net { 46 namespace net {
45 47
46 namespace { 48 namespace {
47 49
48 // Max number of http redirects to follow. Same number as gecko. 50 // Max number of http redirects to follow. Same number as gecko.
49 const int kMaxRedirects = 20; 51 const int kMaxRedirects = 20;
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // the POST and don't have meaning in other methods. For example the 935 // the POST and don't have meaning in other methods. For example the
934 // inclusion of a multipart Content-Type header in GET can cause problems 936 // inclusion of a multipart Content-Type header in GET can cause problems
935 // with some servers: 937 // with some servers:
936 // http://code.google.com/p/chromium/issues/detail?id=843 938 // http://code.google.com/p/chromium/issues/detail?id=843
937 StripPostSpecificHeaders(&extra_request_headers_); 939 StripPostSpecificHeaders(&extra_request_headers_);
938 } 940 }
939 upload_data_stream_.reset(); 941 upload_data_stream_.reset();
940 method_ = redirect_info.new_method; 942 method_ = redirect_info.new_method;
941 } 943 }
942 944
945 // Cross-origin redirects should not result in an Origin header value that is
946 // equal to the original request's Origin header. This is necessary to prevent
947 // a reflection of POST requests to bypass CSRF protections. If the header was
948 // not set to "null", a POST request from origin A to a malicious origin M
949 // could be redirected by M back to A.
950 //
951 // In the Section 4.2, Step 4.10 of the Fetch spec
952 // (https://fetch.spec.whatwg.org/#concept-http-fetch), it states that on
953 // cross-origin 301, 302, 303, 307, and 308 redirects, the user agent should
954 // set the Origin header to an "opaque identifier," in this case "null." This
davidben 2015/03/27 22:46:51 Nit: 'Origin header' -> 'request's origin' 'i
jww 2015/03/30 18:50:37 Done.
955 // matches Firefox and IE behavior, although it supercedes the suggested
956 // behavior in RFC 6454, "The Web Origin Concept."
957 //
958 // See also https://crbug.com/465517.
959 if (redirect_info.new_url.GetOrigin() != url().GetOrigin() &&
960 extra_request_headers_.HasHeader(HttpRequestHeaders::kOrigin)) {
961 extra_request_headers_.SetHeader(HttpRequestHeaders::kOrigin,
962 url::Origin().string());
davidben 2015/03/27 22:46:52 Could you add a TODO to this block and the Origin
jww 2015/03/30 18:50:37 Done.
963 }
964
943 referrer_ = redirect_info.new_referrer; 965 referrer_ = redirect_info.new_referrer;
944 first_party_for_cookies_ = redirect_info.new_first_party_for_cookies; 966 first_party_for_cookies_ = redirect_info.new_first_party_for_cookies;
945 967
946 url_chain_.push_back(redirect_info.new_url); 968 url_chain_.push_back(redirect_info.new_url);
947 --redirect_limit_; 969 --redirect_limit_;
948 970
949 Start(); 971 Start();
950 return OK; 972 return OK;
951 } 973 }
952 974
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 new base::debug::StackTrace(NULL, 0); 1210 new base::debug::StackTrace(NULL, 0);
1189 *stack_trace_copy = stack_trace; 1211 *stack_trace_copy = stack_trace;
1190 stack_trace_.reset(stack_trace_copy); 1212 stack_trace_.reset(stack_trace_copy);
1191 } 1213 }
1192 1214
1193 const base::debug::StackTrace* URLRequest::stack_trace() const { 1215 const base::debug::StackTrace* URLRequest::stack_trace() const {
1194 return stack_trace_.get(); 1216 return stack_trace_.get();
1195 } 1217 }
1196 1218
1197 } // namespace net 1219 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698