OLD | NEW |
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 "extensions/browser/extension_navigation_throttle.h" | 5 #include "extensions/browser/extension_navigation_throttle.h" |
6 | 6 |
7 #include "components/guest_view/browser/guest_view_base.h" | 7 #include "components/guest_view/browser/guest_view_base.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/browser/navigation_handle.h" | 9 #include "content/public/browser/navigation_handle.h" |
10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 is_guest, target_extension, owner_extension, partition_id, url.path(), | 105 is_guest, target_extension, owner_extension, partition_id, url.path(), |
106 navigation_handle()->GetPageTransition(), &allowed); | 106 navigation_handle()->GetPageTransition(), &allowed); |
107 if (!allowed) | 107 if (!allowed) |
108 return content::NavigationThrottle::BLOCK_REQUEST; | 108 return content::NavigationThrottle::BLOCK_REQUEST; |
109 } | 109 } |
110 | 110 |
111 return content::NavigationThrottle::PROCEED; | 111 return content::NavigationThrottle::PROCEED; |
112 } | 112 } |
113 | 113 |
114 // This is a subframe navigation to a |target_extension| resource. | 114 // This is a subframe navigation to a |target_extension| resource. |
115 // Enforce the web_accessible_resources restriction. | 115 // Enforce the web_accessible_resources restriction, and same-origin |
| 116 // restrictions for platform apps. |
116 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); | 117 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); |
117 | 118 |
118 // Look to see if all ancestors belong to |target_extension|. If not, | 119 // Look to see if all ancestors belong to |target_extension|. If not, |
119 // then the web_accessible_resource restriction applies. | 120 // then the web_accessible_resource restriction applies. |
120 bool external_ancestor = false; | 121 bool external_ancestor = false; |
121 for (auto* ancestor = parent; ancestor; ancestor = ancestor->GetParent()) { | 122 for (auto* ancestor = parent; ancestor; ancestor = ancestor->GetParent()) { |
122 // Look for a match on the last committed origin. This handles the | 123 // Look for a match on the last committed origin. This handles the |
123 // common case, and the about:blank case. | 124 // common case, and the about:blank case. |
124 if (ancestor->GetLastCommittedOrigin() == target_origin) | 125 if (ancestor->GetLastCommittedOrigin() == target_origin) |
125 continue; | 126 continue; |
(...skipping 15 matching lines...) Expand all Loading... |
141 | 142 |
142 if (external_ancestor) { | 143 if (external_ancestor) { |
143 // Cancel navigations to nested URLs, to match the main frame behavior. | 144 // Cancel navigations to nested URLs, to match the main frame behavior. |
144 if (!url_has_extension_scheme) | 145 if (!url_has_extension_scheme) |
145 return content::NavigationThrottle::CANCEL; | 146 return content::NavigationThrottle::CANCEL; |
146 | 147 |
147 // |url| must be in the manifest's "web_accessible_resources" section. | 148 // |url| must be in the manifest's "web_accessible_resources" section. |
148 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible(target_extension, | 149 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible(target_extension, |
149 url.path())) | 150 url.path())) |
150 return content::NavigationThrottle::BLOCK_REQUEST; | 151 return content::NavigationThrottle::BLOCK_REQUEST; |
| 152 |
| 153 // A platform app may not be loaded in an <iframe> by another origin. |
| 154 // |
| 155 // In fact, platform apps may not have any cross-origin iframes at all; for |
| 156 // non-extension origins of |url| this is enforced by means of a Content |
| 157 // Security Policy. But CSP is incapable of blocking the chrome-extension |
| 158 // scheme. Thus, this case must be handled specially here. |
| 159 if (target_extension->is_platform_app()) |
| 160 return content::NavigationThrottle::CANCEL; |
| 161 |
| 162 // A platform app may not load another extension in an <iframe>. |
| 163 const Extension* parent_extension = |
| 164 registry->enabled_extensions().GetExtensionOrAppByURL( |
| 165 parent->GetSiteInstance()->GetSiteURL()); |
| 166 if (parent_extension && parent_extension->is_platform_app()) |
| 167 return content::NavigationThrottle::BLOCK_REQUEST; |
151 } | 168 } |
152 | 169 |
153 return content::NavigationThrottle::PROCEED; | 170 return content::NavigationThrottle::PROCEED; |
154 } | 171 } |
155 | 172 |
156 content::NavigationThrottle::ThrottleCheckResult | 173 content::NavigationThrottle::ThrottleCheckResult |
157 ExtensionNavigationThrottle::WillStartRequest() { | 174 ExtensionNavigationThrottle::WillStartRequest() { |
158 return WillStartOrRedirectRequest(); | 175 return WillStartOrRedirectRequest(); |
159 } | 176 } |
160 | 177 |
161 content::NavigationThrottle::ThrottleCheckResult | 178 content::NavigationThrottle::ThrottleCheckResult |
162 ExtensionNavigationThrottle::WillRedirectRequest() { | 179 ExtensionNavigationThrottle::WillRedirectRequest() { |
163 ThrottleCheckResult result = WillStartOrRedirectRequest(); | 180 ThrottleCheckResult result = WillStartOrRedirectRequest(); |
164 if (result == BLOCK_REQUEST) { | 181 if (result == BLOCK_REQUEST) { |
165 // TODO(nick): https://crbug.com/695421 means that BLOCK_REQUEST does not | 182 // TODO(nick): https://crbug.com/695421 means that BLOCK_REQUEST does not |
166 // work here. Once PlzNavigate is enabled 100%, just return |result|. | 183 // work here. Once PlzNavigate is enabled 100%, just return |result|. |
167 return CANCEL; | 184 return CANCEL; |
168 } | 185 } |
169 return result; | 186 return result; |
170 } | 187 } |
171 | 188 |
172 const char* ExtensionNavigationThrottle::GetNameForLogging() { | 189 const char* ExtensionNavigationThrottle::GetNameForLogging() { |
173 return "ExtensionNavigationThrottle"; | 190 return "ExtensionNavigationThrottle"; |
174 } | 191 } |
175 | 192 |
176 } // namespace extensions | 193 } // namespace extensions |
OLD | NEW |