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

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

Issue 2756913002: Revert of PlzNavigate: Enforce 'frame-src' CSP on the browser. (Closed)
Patch Set: 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ancestor_throttle.h" 5 #include "content/browser/frame_host/ancestor_throttle.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "content/browser/frame_host/frame_tree.h" 11 #include "content/browser/frame_host/frame_tree.h"
12 #include "content/browser/frame_host/frame_tree_node.h" 12 #include "content/browser/frame_host/frame_tree_node.h"
13 #include "content/browser/frame_host/navigation_handle_impl.h" 13 #include "content/browser/frame_host/navigation_handle_impl.h"
14 #include "content/browser/frame_host/navigation_request.h"
15 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/navigation_handle.h" 15 #include "content/public/browser/navigation_handle.h"
17 #include "content/public/browser/navigation_throttle.h" 16 #include "content/public/browser/navigation_throttle.h"
18 #include "content/public/common/browser_side_navigation_policy.h"
19 #include "content/public/common/console_message_level.h" 17 #include "content/public/common/console_message_level.h"
20 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
21 #include "url/origin.h" 19 #include "url/origin.h"
22 20
23 namespace content { 21 namespace content {
24 22
25 namespace { 23 namespace {
26 const char kXFrameOptionsSameOriginHistogram[] = "Security.XFrameOptions"; 24 const char kXFrameOptionsSameOriginHistogram[] = "Security.XFrameOptions";
27 25
28 // This enum is used for UMA metrics. Keep these enums up to date with 26 // This enum is used for UMA metrics. Keep these enums up to date with
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 RecordXFrameOptionsUsage(BYPASS); 158 RecordXFrameOptionsUsage(BYPASS);
161 return NavigationThrottle::PROCEED; 159 return NavigationThrottle::PROCEED;
162 case HeaderDisposition::ALLOWALL: 160 case HeaderDisposition::ALLOWALL:
163 RecordXFrameOptionsUsage(ALLOWALL); 161 RecordXFrameOptionsUsage(ALLOWALL);
164 return NavigationThrottle::PROCEED; 162 return NavigationThrottle::PROCEED;
165 } 163 }
166 NOTREACHED(); 164 NOTREACHED();
167 return NavigationThrottle::BLOCK_RESPONSE; 165 return NavigationThrottle::BLOCK_RESPONSE;
168 } 166 }
169 167
170 NavigationThrottle::ThrottleCheckResult
171 AncestorThrottle::CheckContentSecurityPolicyFrameSrc(bool is_redirect) {
172 // If PlzNavigate is enabled, "frame-src" is enforced on the browser side,
173 // else on the renderer side.
174 if (!IsBrowserSideNavigationEnabled())
175 return NavigationThrottle::PROCEED;
176
177 const GURL& url = navigation_handle()->GetURL();
178 if (url.SchemeIs(url::kAboutScheme))
179 return NavigationThrottle::PROCEED;
180
181 NavigationHandleImpl* handle =
182 static_cast<NavigationHandleImpl*>(navigation_handle());
183
184 if (handle->should_check_main_world_csp() == CSPDisposition::DO_NOT_CHECK)
185 return NavigationThrottle::PROCEED;
186
187 FrameTreeNode* parent_ftn = handle->frame_tree_node()->parent();
188 DCHECK(parent_ftn);
189 RenderFrameHostImpl* parent = parent_ftn->current_frame_host();
190 DCHECK(parent);
191
192 if (!parent->IsAllowedByCsp(CSPDirective::FrameSrc, url, is_redirect))
193 return NavigationThrottle::BLOCK_REQUEST;
194
195 return NavigationThrottle::PROCEED;
196 }
197
198 NavigationThrottle::ThrottleCheckResult AncestorThrottle::WillStartRequest() {
199 return CheckContentSecurityPolicyFrameSrc(false);
200 }
201
202 NavigationThrottle::ThrottleCheckResult
203 AncestorThrottle::WillRedirectRequest() {
204 return CheckContentSecurityPolicyFrameSrc(true);
205 }
206
207 AncestorThrottle::AncestorThrottle(NavigationHandle* handle) 168 AncestorThrottle::AncestorThrottle(NavigationHandle* handle)
208 : NavigationThrottle(handle) {} 169 : NavigationThrottle(handle) {}
209 170
210 void AncestorThrottle::ParseError(const std::string& value, 171 void AncestorThrottle::ParseError(const std::string& value,
211 HeaderDisposition disposition) { 172 HeaderDisposition disposition) {
212 DCHECK(disposition == HeaderDisposition::CONFLICT || 173 DCHECK(disposition == HeaderDisposition::CONFLICT ||
213 disposition == HeaderDisposition::INVALID); 174 disposition == HeaderDisposition::INVALID);
214 if (!navigation_handle()->GetRenderFrameHost()) 175 if (!navigation_handle()->GetRenderFrameHost())
215 return; // Some responses won't have a RFH (i.e. 204/205s or downloads). 176 return; // Some responses won't have a RFH (i.e. 204/205s or downloads).
216 177
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 HeadersContainFrameAncestorsCSP(headers)) { 260 HeadersContainFrameAncestorsCSP(headers)) {
300 // TODO(mkwst): 'frame-ancestors' is currently handled in Blink. We should 261 // TODO(mkwst): 'frame-ancestors' is currently handled in Blink. We should
301 // handle it here instead. Until then, don't block the request, and let 262 // handle it here instead. Until then, don't block the request, and let
302 // Blink handle it. https://crbug.com/555418 263 // Blink handle it. https://crbug.com/555418
303 return HeaderDisposition::BYPASS; 264 return HeaderDisposition::BYPASS;
304 } 265 }
305 return result; 266 return result;
306 } 267 }
307 268
308 } // namespace content 269 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/ancestor_throttle.h ('k') | content/browser/frame_host/frame_tree_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698