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

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

Issue 1783813002: SameSite: Strict/Lax behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@strict-lax
Patch Set: Comment. Created 4 years, 9 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
« no previous file with comments | « net/cookies/cookie_store_unittest.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/file_version_info.h" 12 #include "base/file_version_info.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/metrics/field_trial.h" 15 #include "base/metrics/field_trial.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/profiler/scoped_tracker.h" 17 #include "base/profiler/scoped_tracker.h"
18 #include "base/rand_util.h" 18 #include "base/rand_util.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "net/base/host_port_pair.h" 24 #include "net/base/host_port_pair.h"
25 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
26 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
27 #include "net/base/network_delegate.h" 27 #include "net/base/network_delegate.h"
28 #include "net/base/network_quality_estimator.h" 28 #include "net/base/network_quality_estimator.h"
29 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
29 #include "net/base/sdch_manager.h" 30 #include "net/base/sdch_manager.h"
30 #include "net/base/sdch_net_log_params.h" 31 #include "net/base/sdch_net_log_params.h"
31 #include "net/base/url_util.h" 32 #include "net/base/url_util.h"
32 #include "net/cert/cert_status_flags.h" 33 #include "net/cert/cert_status_flags.h"
33 #include "net/cookies/cookie_store.h" 34 #include "net/cookies/cookie_store.h"
34 #include "net/http/http_content_disposition.h" 35 #include "net/http/http_content_disposition.h"
35 #include "net/http/http_network_session.h" 36 #include "net/http/http_network_session.h"
36 #include "net/http/http_request_headers.h" 37 #include "net/http/http_request_headers.h"
37 #include "net/http/http_response_headers.h" 38 #include "net/http/http_response_headers.h"
38 #include "net/http/http_response_info.h" 39 #include "net/http/http_response_info.h"
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 void URLRequestHttpJob::AddCookieHeaderAndStart() { 719 void URLRequestHttpJob::AddCookieHeaderAndStart() {
719 // If the request was destroyed, then there is no more work to do. 720 // If the request was destroyed, then there is no more work to do.
720 if (!request_) 721 if (!request_)
721 return; 722 return;
722 723
723 CookieStore* cookie_store = request_->context()->cookie_store(); 724 CookieStore* cookie_store = request_->context()->cookie_store();
724 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { 725 if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) {
725 CookieOptions options; 726 CookieOptions options;
726 options.set_include_httponly(); 727 options.set_include_httponly();
727 728
728 // TODO(mkwst): If same-site cookies aren't enabled, pretend the request is 729 // Set SameSiteCookieMode according to the rules laid out in
729 // same-site regardless, in order to include all cookies. Drop this check 730 // https://tools.ietf.org/html/draft-west-first-party-cookies:
730 // once we decide whether or not we're shipping this feature: 731 //
731 // https://crbug.com/459154 732 // * Include both "strict" and "lax" same-site cookies if the request's
733 // |url|, |initiator|, and |first_party_for_cookies| all have the same
734 // registrable domain.
735 //
736 // * Include only "lax" same-site cookies if the request's |URL| and
737 // |first_party_for_cookies| have the same registrable domain, _and_ the
738 // request's |method| is "safe" ("GET" or "HEAD").
739 //
740 // Note that this will generally be the case only for cross-site requests
741 // which target a top-level browsing context.
742 //
743 // * Otherwise, do not include same-site cookies.
732 url::Origin requested_origin(request_->url()); 744 url::Origin requested_origin(request_->url());
745 url::Origin site_for_cookies(request_->first_party_for_cookies());
746
733 if (!network_delegate() || 747 if (!network_delegate() ||
734 !network_delegate()->AreExperimentalCookieFeaturesEnabled()) { 748 !network_delegate()->AreExperimentalCookieFeaturesEnabled()) {
735 options.set_include_same_site(); 749 // TODO(mkwst): If same-site cookies aren't enabled, then tag the request
736 } else if (requested_origin.IsSameOriginWith( 750 // as including both strict and lax same-site cookies. Drop this check
737 url::Origin(request_->first_party_for_cookies())) && 751 // once the feature is no longer behind a flag: https://crbug.com/459154.
738 (IsMethodSafe(request_->method()) || 752 options.set_same_site_cookie_mode(
739 requested_origin.IsSameOriginWith(request_->initiator()))) { 753 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
740 options.set_include_same_site(); 754 } else if (registry_controlled_domains::SameDomainOrHost(
755 requested_origin, site_for_cookies,
756 registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) {
757 if (registry_controlled_domains::SameDomainOrHost(
758 requested_origin, request_->initiator(),
759 registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) {
760 options.set_same_site_cookie_mode(
761 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
762 } else if (IsMethodSafe(request_->method())) {
763 options.set_same_site_cookie_mode(
764 CookieOptions::SameSiteCookieMode::INCLUDE_LAX);
765 }
741 } 766 }
742 767
743 cookie_store->GetCookieListWithOptionsAsync( 768 cookie_store->GetCookieListWithOptionsAsync(
744 request_->url(), options, 769 request_->url(), options,
745 base::Bind(&URLRequestHttpJob::SetCookieHeaderAndStart, 770 base::Bind(&URLRequestHttpJob::SetCookieHeaderAndStart,
746 weak_factory_.GetWeakPtr())); 771 weak_factory_.GetWeakPtr()));
747 } else { 772 } else {
748 DoStartTransaction(); 773 DoStartTransaction();
749 } 774 }
750 } 775 }
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 return override_response_headers_.get() ? 1626 return override_response_headers_.get() ?
1602 override_response_headers_.get() : 1627 override_response_headers_.get() :
1603 transaction_->GetResponseInfo()->headers.get(); 1628 transaction_->GetResponseInfo()->headers.get();
1604 } 1629 }
1605 1630
1606 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1631 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1607 awaiting_callback_ = false; 1632 awaiting_callback_ = false;
1608 } 1633 }
1609 1634
1610 } // namespace net 1635 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_store_unittest.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698