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

Side by Side Diff: extensions/browser/extension_navigation_throttle.cc

Issue 2042483002: Fix web_accesible_resources enforcement for Site Isolation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes for code review, removed filter exceptions. Created 4 years, 6 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 2016 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 "extensions/browser/extension_navigation_throttle.h"
6
7 #include "content/public/browser/browser_thread.h"
8 #include "content/public/browser/navigation_handle.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/common/url_constants.h"
12 #include "extensions/browser/extension_registry.h"
13 #include "extensions/common/constants.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/common/extension_set.h"
16 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
17
18 namespace extensions {
19
20 ExtensionNavigationThrottle::ExtensionNavigationThrottle(
21 content::NavigationHandle* navigation_handle)
22 : content::NavigationThrottle(navigation_handle) {}
23
24 ExtensionNavigationThrottle::~ExtensionNavigationThrottle() {}
25
26 content::NavigationThrottle::ThrottleCheckResult
27 ExtensionNavigationThrottle::WillStartRequest() {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
29
30 // This method for now enforces only web_accessible_resources for navigations.
31 // Top-level navigations should always be allowed.
32 DCHECK(!navigation_handle()->IsInMainFrame());
33
34 // If the navigation is not to a chrome-extension:// URL, no need to perform
35 // any more checks.
36 if (!navigation_handle()->GetURL().SchemeIs(extensions::kExtensionScheme))
37 return content::NavigationThrottle::PROCEED;
38
39 // The subframe which is navigated needs to have all of its ancestors be
40 // at the same origin, otherwise the resource needs to be explicitly listed
41 // in web_accessible_resources.
42 // Since the RenderFrameHost is not known until navigation has committed,
43 // we can't get it from NavigationHandle. However, this code only cares about
44 // the ancestor chain, so find the current RenderFrameHost and use it to
45 // traverse up to the main frame.
46 content::RenderFrameHost* navigating_frame = nullptr;
47 for (auto frame : navigation_handle()->GetWebContents()->GetAllFrames()) {
48 if (frame->GetFrameTreeNodeId() ==
49 navigation_handle()->GetFrameTreeNodeId()) {
50 navigating_frame = frame;
51 break;
52 }
53 }
54 DCHECK(navigating_frame);
55
56 // Traverse the chain of parent frames, checking if they are the same origin
57 // as the URL of this navigation.
58 content::RenderFrameHost* ancestor = navigating_frame->GetParent();
59 bool external_ancestor = false;
60 while (ancestor) {
61 if (ancestor->GetLastCommittedURL().GetOrigin() !=
62 navigation_handle()->GetURL().GetOrigin()) {
63 // Ignore DevTools, as it is allowed to embed extension pages.
64 if (!ancestor->GetLastCommittedURL().SchemeIs(
65 content::kChromeDevToolsScheme)) {
66 external_ancestor = true;
67 break;
68 }
69 }
70 ancestor = ancestor->GetParent();
71 }
72
73 if (!external_ancestor)
74 return content::NavigationThrottle::PROCEED;
75
76 // Since there was at least one origin different than the navigation URL,
77 // explicitly check for the resource in web_accessible_resources.
78 std::string resource_path = navigation_handle()->GetURL().path();
79 ExtensionRegistry* registry = ExtensionRegistry::Get(
80 navigation_handle()->GetWebContents()->GetBrowserContext());
81 const extensions::Extension* extension =
82 registry->enabled_extensions().GetByID(
83 navigation_handle()->GetURL().host());
84
85 if (WebAccessibleResourcesInfo::IsResourceWebAccessible(extension,
86 resource_path)) {
87 return content::NavigationThrottle::PROCEED;
88 }
89
90 return content::NavigationThrottle::BLOCK_REQUEST;
91 }
92
93 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698