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

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

Issue 2689653003: PlzNavigate: Enforce 'form-action' CSP on the browser-side. (Closed)
Patch Set: Rebase. 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/frame_host/form_submission_throttle.h"
6 #include "content/browser/frame_host/navigation_handle_impl.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "content/public/browser/navigation_handle.h"
9 #include "content/public/browser/navigation_throttle.h"
10 #include "content/public/common/browser_side_navigation_policy.h"
11
12 namespace content {
13
14 FormSubmissionThrottle::FormSubmissionThrottle(NavigationHandle* handle)
15 : NavigationThrottle(handle) {}
16
17 // static
18 std::unique_ptr<NavigationThrottle>
19 FormSubmissionThrottle::MaybeCreateThrottleFor(NavigationHandle* handle) {
20 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
21
22 if (!IsBrowserSideNavigationEnabled())
23 return nullptr;
24
25 NavigationHandleImpl* handle_impl =
26 static_cast<NavigationHandleImpl*>(handle);
27
28 if (!handle_impl->is_form_submission())
29 return nullptr;
30
31 return std::unique_ptr<NavigationThrottle>(
32 new FormSubmissionThrottle(handle));
33 }
34
35 FormSubmissionThrottle::~FormSubmissionThrottle() {}
36
37 NavigationThrottle::ThrottleCheckResult
38 FormSubmissionThrottle::WillStartRequest() {
39 return CheckContentSecurityPolicyFormAction(false /* is_redirect */);
40 }
41
42 NavigationThrottle::ThrottleCheckResult
43 FormSubmissionThrottle::WillRedirectRequest() {
44 return CheckContentSecurityPolicyFormAction(true /* is_redirect */);
45 }
46
47 NavigationThrottle::ThrottleCheckResult
48 FormSubmissionThrottle::CheckContentSecurityPolicyFormAction(bool is_redirect) {
49 NavigationHandleImpl* handle =
50 static_cast<NavigationHandleImpl*>(navigation_handle());
51
52 if (handle->should_check_main_world_csp() == CSPDisposition::DO_NOT_CHECK)
53 return NavigationThrottle::PROCEED;
54
55 const GURL& url = handle->GetURL();
56 RenderFrameHostImpl* render_frame =
57 handle->frame_tree_node()->current_frame_host();
58
59 if (render_frame->IsAllowedByCsp(CSPDirective::FormAction, url, is_redirect))
60 return NavigationThrottle::PROCEED;
61
62 return NavigationThrottle::CANCEL;
63 }
64
65 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698