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

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 2689653003: PlzNavigate: Enforce 'form-action' CSP on the browser-side. (Closed)
Patch Set: Add TODO. Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/frame_host/navigation_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/appcache/appcache_navigation_handle.h" 10 #include "content/browser/appcache/appcache_navigation_handle.h"
11 #include "content/browser/appcache/appcache_service_impl.h" 11 #include "content/browser/appcache/appcache_service_impl.h"
12 #include "content/browser/browsing_data/clear_site_data_throttle.h" 12 #include "content/browser/browsing_data/clear_site_data_throttle.h"
13 #include "content/browser/child_process_security_policy_impl.h" 13 #include "content/browser/child_process_security_policy_impl.h"
14 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 14 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
15 #include "content/browser/frame_host/ancestor_throttle.h" 15 #include "content/browser/frame_host/ancestor_throttle.h"
16 #include "content/browser/frame_host/debug_urls.h" 16 #include "content/browser/frame_host/debug_urls.h"
17 #include "content/browser/frame_host/form_submission_throttle.h"
17 #include "content/browser/frame_host/frame_tree_node.h" 18 #include "content/browser/frame_host/frame_tree_node.h"
18 #include "content/browser/frame_host/mixed_content_navigation_throttle.h" 19 #include "content/browser/frame_host/mixed_content_navigation_throttle.h"
19 #include "content/browser/frame_host/navigation_controller_impl.h" 20 #include "content/browser/frame_host/navigation_controller_impl.h"
20 #include "content/browser/frame_host/navigation_entry_impl.h" 21 #include "content/browser/frame_host/navigation_entry_impl.h"
21 #include "content/browser/frame_host/navigator.h" 22 #include "content/browser/frame_host/navigator.h"
22 #include "content/browser/frame_host/navigator_delegate.h" 23 #include "content/browser/frame_host/navigator_delegate.h"
23 #include "content/browser/loader/resource_dispatcher_host_impl.h" 24 #include "content/browser/loader/resource_dispatcher_host_impl.h"
24 #include "content/browser/service_worker/service_worker_context_wrapper.h" 25 #include "content/browser/service_worker/service_worker_context_wrapper.h"
25 #include "content/browser/service_worker/service_worker_navigation_handle.h" 26 #include "content/browser/service_worker/service_worker_navigation_handle.h"
26 #include "content/common/frame_messages.h" 27 #include "content/common/frame_messages.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // static 59 // static
59 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 60 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
60 const GURL& url, 61 const GURL& url,
61 const std::vector<GURL>& redirect_chain, 62 const std::vector<GURL>& redirect_chain,
62 FrameTreeNode* frame_tree_node, 63 FrameTreeNode* frame_tree_node,
63 bool is_renderer_initiated, 64 bool is_renderer_initiated,
64 bool is_same_page, 65 bool is_same_page,
65 const base::TimeTicks& navigation_start, 66 const base::TimeTicks& navigation_start,
66 int pending_nav_entry_id, 67 int pending_nav_entry_id,
67 bool started_from_context_menu, 68 bool started_from_context_menu,
68 bool should_bypass_main_world_csp) { 69 bool should_bypass_main_world_csp,
70 bool is_form_submission) {
69 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( 71 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl(
70 url, redirect_chain, frame_tree_node, is_renderer_initiated, is_same_page, 72 url, redirect_chain, frame_tree_node, is_renderer_initiated, is_same_page,
71 navigation_start, pending_nav_entry_id, started_from_context_menu, 73 navigation_start, pending_nav_entry_id, started_from_context_menu,
72 should_bypass_main_world_csp)); 74 should_bypass_main_world_csp, is_form_submission));
73 } 75 }
74 76
75 NavigationHandleImpl::NavigationHandleImpl( 77 NavigationHandleImpl::NavigationHandleImpl(
76 const GURL& url, 78 const GURL& url,
77 const std::vector<GURL>& redirect_chain, 79 const std::vector<GURL>& redirect_chain,
78 FrameTreeNode* frame_tree_node, 80 FrameTreeNode* frame_tree_node,
79 bool is_renderer_initiated, 81 bool is_renderer_initiated,
80 bool is_same_page, 82 bool is_same_page,
81 const base::TimeTicks& navigation_start, 83 const base::TimeTicks& navigation_start,
82 int pending_nav_entry_id, 84 int pending_nav_entry_id,
83 bool started_from_context_menu, 85 bool started_from_context_menu,
84 bool should_bypass_main_world_csp) 86 bool should_bypass_main_world_csp,
87 bool is_form_submission)
85 : url_(url), 88 : url_(url),
86 has_user_gesture_(false), 89 has_user_gesture_(false),
87 transition_(ui::PAGE_TRANSITION_LINK), 90 transition_(ui::PAGE_TRANSITION_LINK),
88 is_external_protocol_(false), 91 is_external_protocol_(false),
89 net_error_code_(net::OK), 92 net_error_code_(net::OK),
90 render_frame_host_(nullptr), 93 render_frame_host_(nullptr),
91 is_renderer_initiated_(is_renderer_initiated), 94 is_renderer_initiated_(is_renderer_initiated),
92 is_same_page_(is_same_page), 95 is_same_page_(is_same_page),
93 was_redirected_(false), 96 was_redirected_(false),
94 did_replace_entry_(false), 97 did_replace_entry_(false),
(...skipping 10 matching lines...) Expand all
105 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable), 108 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable),
106 should_replace_current_entry_(false), 109 should_replace_current_entry_(false),
107 redirect_chain_(redirect_chain), 110 redirect_chain_(redirect_chain),
108 is_download_(false), 111 is_download_(false),
109 is_stream_(false), 112 is_stream_(false),
110 started_from_context_menu_(started_from_context_menu), 113 started_from_context_menu_(started_from_context_menu),
111 reload_type_(ReloadType::NONE), 114 reload_type_(ReloadType::NONE),
112 restore_type_(RestoreType::NONE), 115 restore_type_(RestoreType::NONE),
113 navigation_type_(NAVIGATION_TYPE_UNKNOWN), 116 navigation_type_(NAVIGATION_TYPE_UNKNOWN),
114 should_bypass_main_world_csp_(should_bypass_main_world_csp), 117 should_bypass_main_world_csp_(should_bypass_main_world_csp),
118 is_form_submission_(is_form_submission),
115 weak_factory_(this) { 119 weak_factory_(this) {
116 DCHECK(!navigation_start.is_null()); 120 DCHECK(!navigation_start.is_null());
117 if (redirect_chain_.empty()) 121 if (redirect_chain_.empty())
118 redirect_chain_.push_back(url); 122 redirect_chain_.push_back(url);
119 123
120 starting_site_instance_ = 124 starting_site_instance_ =
121 frame_tree_node_->current_frame_host()->GetSiteInstance(); 125 frame_tree_node_->current_frame_host()->GetSiteInstance();
122 126
123 if (pending_nav_entry_id_) { 127 if (pending_nav_entry_id_) {
124 NavigationControllerImpl* nav_controller = 128 NavigationControllerImpl* nav_controller =
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 // Register the navigation throttles. The vector returned by 903 // Register the navigation throttles. The vector returned by
900 // CreateThrottlesForNavigation is not assigned to throttles_ directly because 904 // CreateThrottlesForNavigation is not assigned to throttles_ directly because
901 // it would overwrite any throttles previously added with 905 // it would overwrite any throttles previously added with
902 // RegisterThrottleForTesting. 906 // RegisterThrottleForTesting.
903 // TODO(carlosk, arthursonzogni): should simplify this to either use 907 // TODO(carlosk, arthursonzogni): should simplify this to either use
904 // |throttles_| directly (except for the case described above) or 908 // |throttles_| directly (except for the case described above) or
905 // |throttles_to_register| for registering all throttles. 909 // |throttles_to_register| for registering all throttles.
906 std::vector<std::unique_ptr<NavigationThrottle>> throttles_to_register = 910 std::vector<std::unique_ptr<NavigationThrottle>> throttles_to_register =
907 GetDelegate()->CreateThrottlesForNavigation(this); 911 GetDelegate()->CreateThrottlesForNavigation(this);
908 912
913 std::unique_ptr<content::NavigationThrottle> ancestor_throttle =
914 content::AncestorThrottle::MaybeCreateThrottleFor(this);
915 if (ancestor_throttle)
916 throttles_.push_back(std::move(ancestor_throttle));
917
918 std::unique_ptr<content::NavigationThrottle> form_submission_throttle =
919 content::FormSubmissionThrottle::MaybeCreateThrottleFor(this);
920 if (form_submission_throttle)
921 throttles_.push_back(std::move(form_submission_throttle));
922
923 // Check for mixed content. We do this after the AncestorThrottle and the
nasko 2017/03/16 21:49:47 nit: s/We do this/This is done/
arthursonzogni 2017/03/17 14:58:25 Done.
924 // FormSubmissionThrottle so that when folks block mixed content with a CSP
925 // policy, they don't get a warning. They'll still get a warning in the
926 // console about CSP blocking the load.
909 std::unique_ptr<NavigationThrottle> mixed_content_throttle = 927 std::unique_ptr<NavigationThrottle> mixed_content_throttle =
910 MixedContentNavigationThrottle::CreateThrottleForNavigation(this); 928 MixedContentNavigationThrottle::CreateThrottleForNavigation(this);
911 if (mixed_content_throttle) 929 if (mixed_content_throttle)
912 throttles_to_register.push_back(std::move(mixed_content_throttle)); 930 throttles_to_register.push_back(std::move(mixed_content_throttle));
913 931
914 std::unique_ptr<NavigationThrottle> devtools_throttle = 932 std::unique_ptr<NavigationThrottle> devtools_throttle =
915 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); 933 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this);
916 if (devtools_throttle) 934 if (devtools_throttle)
917 throttles_to_register.push_back(std::move(devtools_throttle)); 935 throttles_to_register.push_back(std::move(devtools_throttle));
918 936
919 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = 937 std::unique_ptr<NavigationThrottle> clear_site_data_throttle =
920 ClearSiteDataThrottle::CreateThrottleForNavigation(this); 938 ClearSiteDataThrottle::CreateThrottleForNavigation(this);
921 if (clear_site_data_throttle) 939 if (clear_site_data_throttle)
922 throttles_to_register.push_back(std::move(clear_site_data_throttle)); 940 throttles_to_register.push_back(std::move(clear_site_data_throttle));
923 941
924 std::unique_ptr<content::NavigationThrottle> ancestor_throttle =
925 content::AncestorThrottle::MaybeCreateThrottleFor(this);
926 if (ancestor_throttle)
927 throttles_.push_back(std::move(ancestor_throttle));
928
929 throttles_.insert(throttles_.begin(), 942 throttles_.insert(throttles_.begin(),
930 std::make_move_iterator(throttles_to_register.begin()), 943 std::make_move_iterator(throttles_to_register.begin()),
931 std::make_move_iterator(throttles_to_register.end())); 944 std::make_move_iterator(throttles_to_register.end()));
932 } 945 }
933 946
934 bool NavigationHandleImpl::IsSelfReferentialURL() { 947 bool NavigationHandleImpl::IsSelfReferentialURL() {
935 // about: URLs should be exempted since they are reserved for other purposes 948 // about: URLs should be exempted since they are reserved for other purposes
936 // and cannot be the source of infinite recursion. See 949 // and cannot be the source of infinite recursion. See
937 // https://crbug.com/341858 . 950 // https://crbug.com/341858 .
938 if (url_.SchemeIs("about")) 951 if (url_.SchemeIs("about"))
(...skipping 11 matching lines...) Expand all
950 if (node->current_url().EqualsIgnoringRef(url_)) { 963 if (node->current_url().EqualsIgnoringRef(url_)) {
951 if (found_self_reference) 964 if (found_self_reference)
952 return true; 965 return true;
953 found_self_reference = true; 966 found_self_reference = true;
954 } 967 }
955 } 968 }
956 return false; 969 return false;
957 } 970 }
958 971
959 } // namespace content 972 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698