OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/extension_protocols.h" | 5 #include "chrome/browser/extensions/extension_protocols.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/sha1.h" | 18 #include "base/sha1.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 #include "chrome/browser/extensions/extension_info_map.h" | 25 #include "chrome/browser/extensions/extension_info_map.h" |
| 26 #include "chrome/browser/extensions/extension_renderer_state.h" |
26 #include "chrome/browser/extensions/image_loader.h" | 27 #include "chrome/browser/extensions/image_loader.h" |
27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/extensions/background_info.h" | 29 #include "chrome/common/extensions/background_info.h" |
29 #include "chrome/common/extensions/csp_handler.h" | 30 #include "chrome/common/extensions/csp_handler.h" |
30 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
31 #include "chrome/common/extensions/extension_file_util.h" | 32 #include "chrome/common/extensions/extension_file_util.h" |
32 #include "chrome/common/extensions/incognito_handler.h" | 33 #include "chrome/common/extensions/incognito_handler.h" |
33 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 34 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
34 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" | 35 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" |
35 #include "chrome/common/extensions/manifest_url_handler.h" | 36 #include "chrome/common/extensions/manifest_url_handler.h" |
36 #include "chrome/common/extensions/web_accessible_resources_handler.h" | 37 #include "chrome/common/extensions/web_accessible_resources_handler.h" |
| 38 #include "chrome/common/extensions/webview_handler.h" |
37 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
38 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
39 #include "content/public/browser/resource_request_info.h" | 41 #include "content/public/browser/resource_request_info.h" |
40 #include "extensions/common/constants.h" | 42 #include "extensions/common/constants.h" |
41 #include "extensions/common/extension_resource.h" | 43 #include "extensions/common/extension_resource.h" |
42 #include "grit/component_extension_resources_map.h" | 44 #include "grit/component_extension_resources_map.h" |
43 #include "net/base/mime_util.h" | 45 #include "net/base/mime_util.h" |
44 #include "net/base/net_errors.h" | 46 #include "net/base/net_errors.h" |
45 #include "net/http/http_response_headers.h" | 47 #include "net/http/http_response_headers.h" |
46 #include "net/http/http_response_info.h" | 48 #include "net/http/http_response_info.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 333 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
332 | 334 |
333 // We have seen crashes where info is NULL: crbug.com/52374. | 335 // We have seen crashes where info is NULL: crbug.com/52374. |
334 if (!info) { | 336 if (!info) { |
335 LOG(ERROR) << "Allowing load of " << request->url().spec() | 337 LOG(ERROR) << "Allowing load of " << request->url().spec() |
336 << "from unknown origin. Could not find user data for " | 338 << "from unknown origin. Could not find user data for " |
337 << "request."; | 339 << "request."; |
338 return true; | 340 return true; |
339 } | 341 } |
340 | 342 |
341 if (is_incognito && !ExtensionCanLoadInIncognito(info, request->url().host(), | |
342 extension_info_map)) { | |
343 return false; | |
344 } | |
345 | |
346 // The following checks are meant to replicate similar set of checks in the | 343 // The following checks are meant to replicate similar set of checks in the |
347 // renderer process, performed by ResourceRequestPolicy::CanRequestResource. | 344 // renderer process, performed by ResourceRequestPolicy::CanRequestResource. |
348 // These are not exactly equivalent, because we don't have the same bits of | 345 // These are not exactly equivalent, because we don't have the same bits of |
349 // information. The two checks need to be kept in sync as much as possible, as | 346 // information. The two checks need to be kept in sync as much as possible, as |
350 // an exploited renderer can bypass the checks in ResourceRequestPolicy. | 347 // an exploited renderer can bypass the checks in ResourceRequestPolicy. |
351 | 348 |
352 // Check if the extension for which this request is made is indeed loaded in | 349 // Check if the extension for which this request is made is indeed loaded in |
353 // the process sending the request. If not, we need to explicitly check if | 350 // the process sending the request. If not, we need to explicitly check if |
354 // the resource is explicitly accessible or fits in a set of exception cases. | 351 // the resource is explicitly accessible or fits in a set of exception cases. |
355 // Note: This allows a case where two extensions execute in the same renderer | 352 // Note: This allows a case where two extensions execute in the same renderer |
356 // process to request each other's resources. We can't do a more precise | 353 // process to request each other's resources. We can't do a more precise |
357 // check, since the renderer can lie about which extension has made the | 354 // check, since the renderer can lie about which extension has made the |
358 // request. | 355 // request. |
359 if (extension_info_map->process_map().Contains( | 356 if (extension_info_map->process_map().Contains( |
360 request->url().host(), info->GetChildID())) { | 357 request->url().host(), info->GetChildID())) { |
361 return true; | 358 return true; |
362 } | 359 } |
363 | 360 |
| 361 // Extensions with webview: allow loading certain resources by guest renderers |
| 362 // with privileged partition IDs as specified in the manifest file. |
| 363 ExtensionRendererState* renderer_state = |
| 364 ExtensionRendererState::GetInstance(); |
| 365 ExtensionRendererState::WebViewInfo webview_info; |
| 366 bool is_guest = renderer_state->GetWebViewInfo(info->GetChildID(), |
| 367 info->GetRouteID(), |
| 368 &webview_info); |
| 369 std::string resource_path = request->url().path(); |
| 370 if (is_guest && |
| 371 extensions::WebviewInfo::IsResourceWebviewAccessible( |
| 372 extension, webview_info.partition_id, resource_path)) { |
| 373 return true; |
| 374 } |
| 375 |
364 if (!content::PageTransitionIsWebTriggerable(info->GetPageTransition())) | 376 if (!content::PageTransitionIsWebTriggerable(info->GetPageTransition())) |
365 return false; | 377 return false; |
366 | 378 |
367 // The following checks require that we have an actual extension object. If we | 379 // The following checks require that we have an actual extension object. If we |
368 // don't have it, allow the request handling to continue with the rest of the | 380 // don't have it, allow the request handling to continue with the rest of the |
369 // checks. | 381 // checks. |
370 if (!extension) | 382 if (!extension) |
371 return true; | 383 return true; |
372 | 384 |
373 // Disallow loading of packaged resources for hosted apps. We don't allow | 385 // Disallow loading of packaged resources for hosted apps. We don't allow |
(...skipping 14 matching lines...) Expand all Loading... |
388 // Extensions with web_accessible_resources: allow loading by regular | 400 // Extensions with web_accessible_resources: allow loading by regular |
389 // renderers. Since not all subresources are required to be listed in a v2 | 401 // renderers. Since not all subresources are required to be listed in a v2 |
390 // manifest, we must allow all loads if there are any web accessible | 402 // manifest, we must allow all loads if there are any web accessible |
391 // resources. See http://crbug.com/179127. | 403 // resources. See http://crbug.com/179127. |
392 if (extension->manifest_version() < 2 || | 404 if (extension->manifest_version() < 2 || |
393 extensions::WebAccessibleResourcesInfo::HasWebAccessibleResources( | 405 extensions::WebAccessibleResourcesInfo::HasWebAccessibleResources( |
394 extension)) { | 406 extension)) { |
395 return true; | 407 return true; |
396 } | 408 } |
397 | 409 |
| 410 if (is_incognito && !ExtensionCanLoadInIncognito(info, request->url().host(), |
| 411 extension_info_map)) { |
| 412 return false; |
| 413 } |
| 414 |
| 415 |
398 // If there aren't any explicitly marked web accessible resources, the | 416 // If there aren't any explicitly marked web accessible resources, the |
399 // load should be allowed only if it is by DevTools. A close approximation is | 417 // load should be allowed only if it is by DevTools. A close approximation is |
400 // checking if the extension contains a DevTools page. | 418 // checking if the extension contains a DevTools page. |
401 if (extensions::ManifestURL::GetDevToolsPage(extension).is_empty()) | 419 if (extensions::ManifestURL::GetDevToolsPage(extension).is_empty()) |
402 return false; | 420 return false; |
403 | 421 |
404 return true; | 422 return true; |
405 } | 423 } |
406 | 424 |
407 // Returns true if the given URL references an icon in the given extension. | 425 // Returns true if the given URL references an icon in the given extension. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 send_cors_header); | 583 send_cors_header); |
566 } | 584 } |
567 | 585 |
568 } // namespace | 586 } // namespace |
569 | 587 |
570 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 588 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
571 bool is_incognito, | 589 bool is_incognito, |
572 ExtensionInfoMap* extension_info_map) { | 590 ExtensionInfoMap* extension_info_map) { |
573 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 591 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
574 } | 592 } |
OLD | NEW |