Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/net/chrome_extensions_network_delegate.h" | 5 #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "extensions/features/features.h" | 10 #include "extensions/features/features.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 | 12 |
| 13 #if BUILDFLAG(ENABLE_EXTENSIONS) | 13 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 14 #include "base/debug/alias.h" | |
| 15 #include "base/debug/dump_without_crashing.h" | |
| 16 #include "base/strings/string_util.h" | |
| 17 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/extensions/api/proxy/proxy_api.h" | 15 #include "chrome/browser/extensions/api/proxy/proxy_api.h" |
| 19 #include "chrome/browser/extensions/event_router_forwarder.h" | 16 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" | 18 #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" |
| 22 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/child_process_security_policy.h" | |
| 24 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| 26 #include "content/public/common/browser_side_navigation_policy.h" | 22 #include "content/public/common/browser_side_navigation_policy.h" |
| 27 #include "extensions/browser/api/web_request/web_request_api.h" | 23 #include "extensions/browser/api/web_request/web_request_api.h" |
| 28 #include "extensions/browser/extension_navigation_ui_data.h" | 24 #include "extensions/browser/extension_navigation_ui_data.h" |
| 29 #include "extensions/browser/info_map.h" | 25 #include "extensions/browser/info_map.h" |
| 30 #include "extensions/browser/process_manager.h" | 26 #include "extensions/browser/process_manager.h" |
| 31 #include "extensions/common/permissions/api_permission.h" | 27 #include "extensions/common/permissions/api_permission.h" |
| 32 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| 33 | 29 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 | 160 |
| 165 void ChromeExtensionsNetworkDelegateImpl::ForwardDoneRequestStatus( | 161 void ChromeExtensionsNetworkDelegateImpl::ForwardDoneRequestStatus( |
| 166 net::URLRequest* request) { | 162 net::URLRequest* request) { |
| 167 ForwardRequestStatus(REQUEST_DONE, request, profile_); | 163 ForwardRequestStatus(REQUEST_DONE, request, profile_); |
| 168 } | 164 } |
| 169 | 165 |
| 170 int ChromeExtensionsNetworkDelegateImpl::OnBeforeURLRequest( | 166 int ChromeExtensionsNetworkDelegateImpl::OnBeforeURLRequest( |
| 171 net::URLRequest* request, | 167 net::URLRequest* request, |
| 172 const net::CompletionCallback& callback, | 168 const net::CompletionCallback& callback, |
| 173 GURL* new_url) { | 169 GURL* new_url) { |
| 174 const content::ResourceRequestInfo* info = | |
| 175 content::ResourceRequestInfo::ForRequest(request); | |
| 176 const GURL& url(request->url()); | |
| 177 | |
| 178 // Block top-level navigations to blob: or filesystem: URLs with extension | |
| 179 // origin from non-extension processes. See https://crbug.com/645028. | |
| 180 // | |
| 181 // TODO(alexmos): This check is redundant with the one in | |
| 182 // ExtensionNavigationThrottle::WillStartRequest, which was introduced in | |
| 183 // M56. This check is reintroduced temporarily to tighten this blocking for | |
| 184 // apps with a "webview" permission on M55/54 (see https://crbug.com/656752). | |
| 185 // It will be removed after it's merged. Unlike the check in | |
| 186 // ExtensionNavigationThrottle, this check is incompatible with PlzNavigate | |
| 187 // and is disabled for that mode. | |
| 188 bool is_nested_url = url.SchemeIsFileSystem() || url.SchemeIsBlob(); | |
| 189 bool is_navigation = | |
| 190 info && content::IsResourceTypeFrame(info->GetResourceType()); | |
| 191 if (is_nested_url && is_navigation && info->IsMainFrame()) { | |
| 192 // Nested conditional so we don't always pay the GURL -> Origin conversion. | |
| 193 url::Origin origin = url::Origin(url); | |
| 194 if (origin.scheme() == extensions::kExtensionScheme && | |
| 195 !extension_info_map_->process_map().Contains(info->GetChildID()) && | |
| 196 !content::IsBrowserSideNavigationEnabled()) { | |
| 197 // Relax this restriction for apps that use <webview>. See | |
| 198 // https://crbug.com/652077. | |
| 199 const extensions::Extension* extension = | |
| 200 extension_info_map_->extensions().GetByID(origin.host()); | |
| 201 bool has_webview_permission = | |
| 202 extension && | |
| 203 extension->permissions_data()->HasAPIPermission( | |
| 204 extensions::APIPermission::kWebView); | |
| 205 // Check whether the request is coming from a <webview> guest process via | |
| 206 // ChildProcessSecurityPolicy. A guest process should have already been | |
| 207 // granted permission to request |origin| when its WebContents was | |
| 208 // created. See https://crbug.com/656752. | |
| 209 auto* policy = content::ChildProcessSecurityPolicy::GetInstance(); | |
| 210 bool from_guest = | |
| 211 policy->HasSpecificPermissionForOrigin(info->GetChildID(), origin); | |
|
alexmos
2017/05/10 17:12:19
Can't remove this from the API, unfortunately, bec
| |
| 212 if (!has_webview_permission || !from_guest) { | |
| 213 // TODO(alexmos): Temporary instrumentation to find any regressions for | |
| 214 // this blocking. Remove after verifying that this is not breaking any | |
| 215 // legitimate use cases. | |
| 216 char origin_copy[256]; | |
| 217 base::strlcpy(origin_copy, origin.Serialize().c_str(), | |
| 218 arraysize(origin_copy)); | |
| 219 base::debug::Alias(&origin_copy); | |
| 220 base::debug::Alias(&from_guest); | |
| 221 base::debug::DumpWithoutCrashing(); | |
|
alexmos
2017/05/10 17:12:19
I checked the stats on this, and it's rare (40 ins
| |
| 222 return net::ERR_ABORTED; | |
| 223 } | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( | 170 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( |
| 228 profile_, extension_info_map_.get(), request, callback, new_url); | 171 profile_, extension_info_map_.get(), request, callback, new_url); |
| 229 } | 172 } |
| 230 | 173 |
| 231 int ChromeExtensionsNetworkDelegateImpl::OnBeforeStartTransaction( | 174 int ChromeExtensionsNetworkDelegateImpl::OnBeforeStartTransaction( |
| 232 net::URLRequest* request, | 175 net::URLRequest* request, |
| 233 const net::CompletionCallback& callback, | 176 const net::CompletionCallback& callback, |
| 234 net::HttpRequestHeaders* headers) { | 177 net::HttpRequestHeaders* headers) { |
| 235 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( | 178 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( |
| 236 profile_, extension_info_map_.get(), request, callback, headers); | 179 profile_, extension_info_map_.get(), request, callback, headers); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 } | 346 } |
| 404 | 347 |
| 405 net::NetworkDelegate::AuthRequiredResponse | 348 net::NetworkDelegate::AuthRequiredResponse |
| 406 ChromeExtensionsNetworkDelegate::OnAuthRequired( | 349 ChromeExtensionsNetworkDelegate::OnAuthRequired( |
| 407 net::URLRequest* request, | 350 net::URLRequest* request, |
| 408 const net::AuthChallengeInfo& auth_info, | 351 const net::AuthChallengeInfo& auth_info, |
| 409 const AuthCallback& callback, | 352 const AuthCallback& callback, |
| 410 net::AuthCredentials* credentials) { | 353 net::AuthCredentials* credentials) { |
| 411 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; | 354 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; |
| 412 } | 355 } |
| OLD | NEW |