| 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" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 net::URLRequest* request) { | 166 net::URLRequest* request) { |
| 167 ForwardRequestStatus(REQUEST_DONE, request, profile_); | 167 ForwardRequestStatus(REQUEST_DONE, request, profile_); |
| 168 } | 168 } |
| 169 | 169 |
| 170 int ChromeExtensionsNetworkDelegateImpl::OnBeforeURLRequest( | 170 int ChromeExtensionsNetworkDelegateImpl::OnBeforeURLRequest( |
| 171 net::URLRequest* request, | 171 net::URLRequest* request, |
| 172 const net::CompletionCallback& callback, | 172 const net::CompletionCallback& callback, |
| 173 GURL* new_url) { | 173 GURL* new_url) { |
| 174 const content::ResourceRequestInfo* info = | 174 const content::ResourceRequestInfo* info = |
| 175 content::ResourceRequestInfo::ForRequest(request); | 175 content::ResourceRequestInfo::ForRequest(request); |
| 176 GURL url(request->url()); | 176 const GURL& url(request->url()); |
| 177 | 177 |
| 178 // Block top-level navigations to blob: or filesystem: URLs with extension | 178 // Block top-level navigations to blob: or filesystem: URLs with extension |
| 179 // origin from non-extension processes. See https://crbug.com/645028. | 179 // origin from non-extension processes. See https://crbug.com/645028. |
| 180 // | 180 // |
| 181 // TODO(alexmos): This check is redundant with the one in | 181 // TODO(alexmos): This check is redundant with the one in |
| 182 // ExtensionNavigationThrottle::WillStartRequest, which was introduced in | 182 // ExtensionNavigationThrottle::WillStartRequest, which was introduced in |
| 183 // M56. This check is reintroduced temporarily to tighten this blocking for | 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). | 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 | 185 // It will be removed after it's merged. Unlike the check in |
| 186 // ExtensionNavigationThrottle, this check is incompatible with PlzNavigate | 186 // ExtensionNavigationThrottle, this check is incompatible with PlzNavigate |
| 187 // and is disabled for that mode. | 187 // and is disabled for that mode. |
| 188 bool is_nested_url = url.SchemeIsFileSystem() || url.SchemeIsBlob(); | 188 bool is_nested_url = url.SchemeIsFileSystem() || url.SchemeIsBlob(); |
| 189 bool is_navigation = | 189 bool is_navigation = |
| 190 info && content::IsResourceTypeFrame(info->GetResourceType()); | 190 info && content::IsResourceTypeFrame(info->GetResourceType()); |
| 191 url::Origin origin(url); | 191 if (is_nested_url && is_navigation && info->IsMainFrame()) { |
| 192 if (is_nested_url && is_navigation && info->IsMainFrame() && | 192 // Nested conditional so we don't always pay the GURL -> Origin conversion. |
| 193 origin.scheme() == extensions::kExtensionScheme && | 193 url::Origin origin = url::Origin(url); |
| 194 !extension_info_map_->process_map().Contains(info->GetChildID()) && | 194 if (origin.scheme() == extensions::kExtensionScheme && |
| 195 !content::IsBrowserSideNavigationEnabled()) { | 195 !extension_info_map_->process_map().Contains(info->GetChildID()) && |
| 196 // Relax this restriction for apps that use <webview>. See | 196 !content::IsBrowserSideNavigationEnabled()) { |
| 197 // https://crbug.com/652077. | 197 // Relax this restriction for apps that use <webview>. See |
| 198 const extensions::Extension* extension = | 198 // https://crbug.com/652077. |
| 199 extension_info_map_->extensions().GetByID(origin.host()); | 199 const extensions::Extension* extension = |
| 200 bool has_webview_permission = | 200 extension_info_map_->extensions().GetByID(origin.host()); |
| 201 extension && | 201 bool has_webview_permission = |
| 202 extension->permissions_data()->HasAPIPermission( | 202 extension && |
| 203 extensions::APIPermission::kWebView); | 203 extension->permissions_data()->HasAPIPermission( |
| 204 // Check whether the request is coming from a <webview> guest process via | 204 extensions::APIPermission::kWebView); |
| 205 // ChildProcessSecurityPolicy. A guest process should have already been | 205 // Check whether the request is coming from a <webview> guest process via |
| 206 // granted permission to request |origin| when its WebContents was created. | 206 // ChildProcessSecurityPolicy. A guest process should have already been |
| 207 // See https://crbug.com/656752. | 207 // granted permission to request |origin| when its WebContents was |
| 208 auto* policy = content::ChildProcessSecurityPolicy::GetInstance(); | 208 // created. See https://crbug.com/656752. |
| 209 bool from_guest = | 209 auto* policy = content::ChildProcessSecurityPolicy::GetInstance(); |
| 210 policy->HasSpecificPermissionForOrigin(info->GetChildID(), origin); | 210 bool from_guest = |
| 211 if (!has_webview_permission || !from_guest) { | 211 policy->HasSpecificPermissionForOrigin(info->GetChildID(), origin); |
| 212 // TODO(alexmos): Temporary instrumentation to find any regressions for | 212 if (!has_webview_permission || !from_guest) { |
| 213 // this blocking. Remove after verifying that this is not breaking any | 213 // TODO(alexmos): Temporary instrumentation to find any regressions for |
| 214 // legitimate use cases. | 214 // this blocking. Remove after verifying that this is not breaking any |
| 215 char origin_copy[256]; | 215 // legitimate use cases. |
| 216 base::strlcpy(origin_copy, origin.Serialize().c_str(), | 216 char origin_copy[256]; |
| 217 arraysize(origin_copy)); | 217 base::strlcpy(origin_copy, origin.Serialize().c_str(), |
| 218 base::debug::Alias(&origin_copy); | 218 arraysize(origin_copy)); |
| 219 base::debug::Alias(&from_guest); | 219 base::debug::Alias(&origin_copy); |
| 220 base::debug::DumpWithoutCrashing(); | 220 base::debug::Alias(&from_guest); |
| 221 return net::ERR_ABORTED; | 221 base::debug::DumpWithoutCrashing(); |
| 222 return net::ERR_ABORTED; |
| 223 } |
| 222 } | 224 } |
| 223 } | 225 } |
| 224 | 226 |
| 225 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( | 227 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( |
| 226 profile_, extension_info_map_.get(), request, callback, new_url); | 228 profile_, extension_info_map_.get(), request, callback, new_url); |
| 227 } | 229 } |
| 228 | 230 |
| 229 int ChromeExtensionsNetworkDelegateImpl::OnBeforeStartTransaction( | 231 int ChromeExtensionsNetworkDelegateImpl::OnBeforeStartTransaction( |
| 230 net::URLRequest* request, | 232 net::URLRequest* request, |
| 231 const net::CompletionCallback& callback, | 233 const net::CompletionCallback& callback, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 403 } |
| 402 | 404 |
| 403 net::NetworkDelegate::AuthRequiredResponse | 405 net::NetworkDelegate::AuthRequiredResponse |
| 404 ChromeExtensionsNetworkDelegate::OnAuthRequired( | 406 ChromeExtensionsNetworkDelegate::OnAuthRequired( |
| 405 net::URLRequest* request, | 407 net::URLRequest* request, |
| 406 const net::AuthChallengeInfo& auth_info, | 408 const net::AuthChallengeInfo& auth_info, |
| 407 const AuthCallback& callback, | 409 const AuthCallback& callback, |
| 408 net::AuthCredentials* credentials) { | 410 net::AuthCredentials* credentials) { |
| 409 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; | 411 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; |
| 410 } | 412 } |
| OLD | NEW |