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

Side by Side Diff: extensions/browser/api/web_request/web_request_permissions.cc

Issue 2886573003: Limit protection of clients[0-9]*.google.com to requests from browser. (Closed)
Patch Set: Created 3 years, 7 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
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 "extensions/browser/api/web_request/web_request_permissions.h" 5 #include "extensions/browser/api/web_request/web_request_permissions.h"
6 6
7 #include "base/strings/string_piece.h" 7 #include "base/strings/string_piece.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chromeos/login/login_state.h" 10 #include "chromeos/login/login_state.h"
11 #include "content/public/browser/child_process_security_policy.h"
11 #include "content/public/browser/resource_request_info.h" 12 #include "content/public/browser/resource_request_info.h"
12 #include "extensions/browser/extension_navigation_ui_data.h" 13 #include "extensions/browser/extension_navigation_ui_data.h"
13 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" 14 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
14 #include "extensions/browser/info_map.h" 15 #include "extensions/browser/info_map.h"
15 #include "extensions/common/constants.h" 16 #include "extensions/common/constants.h"
16 #include "extensions/common/extension.h" 17 #include "extensions/common/extension.h"
17 #include "extensions/common/extension_urls.h" 18 #include "extensions/common/extension_urls.h"
18 #include "extensions/common/permissions/permissions_data.h" 19 #include "extensions/common/permissions/permissions_data.h"
19 #include "net/url_request/url_request.h" 20 #include "net/url_request/url_request.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
(...skipping 14 matching lines...) Expand all
35 url.SchemeIs(extensions::kExtensionScheme) || url.SchemeIsWSOrWSS()); 36 url.SchemeIs(extensions::kExtensionScheme) || url.SchemeIsWSOrWSS());
36 } 37 }
37 38
38 bool g_allow_all_extension_locations_in_public_session = false; 39 bool g_allow_all_extension_locations_in_public_session = false;
39 40
40 } // namespace 41 } // namespace
41 42
42 // Returns true if the URL is sensitive and requests to this URL must not be 43 // Returns true if the URL is sensitive and requests to this URL must not be
43 // modified/canceled by extensions, e.g. because it is targeted to the webstore 44 // modified/canceled by extensions, e.g. because it is targeted to the webstore
44 // to check for updates, extension blacklisting, etc. 45 // to check for updates, extension blacklisting, etc.
45 bool IsSensitiveURL(const GURL& url) { 46 bool IsSensitiveURL(const GURL& url,
47 bool is_request_from_browser_or_webui_renderer) {
46 // TODO(battre) Merge this, CanExtensionAccessURL and 48 // TODO(battre) Merge this, CanExtensionAccessURL and
47 // PermissionsData::CanAccessPage into one function. 49 // PermissionsData::CanAccessPage into one function.
48 bool sensitive_chrome_url = false; 50 bool sensitive_chrome_url = false;
49 const base::StringPiece& host = url.host_piece(); 51 base::StringPiece host = url.host_piece();
52 while (host.ends_with("."))
53 host.remove_suffix(1u);
50 const char kGoogleCom[] = "google.com"; 54 const char kGoogleCom[] = "google.com";
51 const char kClient[] = "clients"; 55 const char kClient[] = "clients";
52 if (url.DomainIs(kGoogleCom)) { 56 if (url.DomainIs(kGoogleCom)) {
53 // Check for "clients[0-9]*.google.com" hosts. 57 // Check for "clients[0-9]*.google.com" hosts.
54 // This protects requests to several internal services such as sync, 58 // This protects requests to several internal services such as sync,
55 // extension update pings, captive portal detection, fraudulent certificate 59 // extension update pings, captive portal detection, fraudulent certificate
56 // reporting, autofill and others. 60 // reporting, autofill and others.
57 if (base::StartsWith(host, kClient, base::CompareCase::SENSITIVE)) { 61 //
58 bool match = true; 62 // These URLs are only protected for requests from the browser and webui
59 for (base::StringPiece::const_iterator 63 // renderers, not for requests from common renderers, because
60 i = host.begin() + strlen(kClient), 64 // clients*.google.com are also used by websites.
61 end = host.end() - (strlen(kGoogleCom) + 1); 65 if (is_request_from_browser_or_webui_renderer) {
62 i != end; ++i) { 66 base::StringPiece::size_type pos = host.rfind(kClient);
63 if (!isdigit(*i)) { 67 if (pos != base::StringPiece::npos) {
68 bool match = true;
69 if (pos > 0 && host[pos - 1] != '.') {
64 match = false; 70 match = false;
65 break; 71 } else {
72 for (base::StringPiece::const_iterator
73 i = host.begin() + pos + strlen(kClient),
74 end = host.end() - (strlen(kGoogleCom) + 1);
75 i != end; ++i) {
76 if (!isdigit(*i)) {
77 match = false;
78 break;
79 }
80 }
66 } 81 }
82 sensitive_chrome_url = sensitive_chrome_url || match;
67 } 83 }
68 sensitive_chrome_url = sensitive_chrome_url || match;
69 } 84 }
70 // This protects requests to safe browsing, link doctor, and possibly 85
71 // others. 86 // Safebrowsing and Chrome Webstore URLs are always protected, i.e. also
87 // for requests from common renderers.
72 sensitive_chrome_url = sensitive_chrome_url || 88 sensitive_chrome_url = sensitive_chrome_url ||
73 url.DomainIs("clients.google.com") ||
74 url.DomainIs("sb-ssl.google.com") || 89 url.DomainIs("sb-ssl.google.com") ||
75 (url.DomainIs("chrome.google.com") && 90 (url.DomainIs("chrome.google.com") &&
76 base::StartsWith(url.path_piece(), "/webstore", 91 base::StartsWith(url.path_piece(), "/webstore",
77 base::CompareCase::SENSITIVE)); 92 base::CompareCase::SENSITIVE));
78 } 93 }
79 return sensitive_chrome_url || extension_urls::IsWebstoreUpdateUrl(url) || 94 return sensitive_chrome_url || extension_urls::IsWebstoreUpdateUrl(url) ||
80 extension_urls::IsBlacklistUpdateUrl(url); 95 extension_urls::IsBlacklistUpdateUrl(url);
81 } 96 }
82 97
83 // static 98 // static
84 bool WebRequestPermissions::HideRequest( 99 bool WebRequestPermissions::HideRequest(
85 const extensions::InfoMap* extension_info_map, 100 const extensions::InfoMap* extension_info_map,
86 const net::URLRequest* request, 101 const net::URLRequest* request,
87 extensions::ExtensionNavigationUIData* navigation_ui_data) { 102 extensions::ExtensionNavigationUIData* navigation_ui_data) {
88 // Hide requests from the Chrome WebStore App or signin process. 103 // Hide requests from the Chrome WebStore App, signin process and WebUI.
89 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 104 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
105
106 // Requests from the browser and webui get special protection for
107 // clients*.google.com URLs.
108 bool is_request_from_browser = true;
109 bool is_request_from_webui_renderer = false;
90 if (info) { 110 if (info) {
91 int process_id = info->GetChildID(); 111 int process_id = info->GetChildID();
92 // Never hide requests from guest processes. 112 // Never hide requests from guest processes.
93 if (extensions::WebViewRendererState::GetInstance()->IsGuest(process_id) || 113 if (extensions::WebViewRendererState::GetInstance()->IsGuest(process_id) ||
94 (navigation_ui_data && navigation_ui_data->is_web_view())) { 114 (navigation_ui_data && navigation_ui_data->is_web_view())) {
95 return false; 115 return false;
96 } 116 }
97 117
98 if (extension_info_map && 118 if (extension_info_map &&
99 extension_info_map->process_map().Contains(extensions::kWebStoreAppId, 119 extension_info_map->process_map().Contains(extensions::kWebStoreAppId,
100 process_id)) { 120 process_id)) {
101 return true; 121 return true;
102 } 122 }
123
124 is_request_from_browser = false;
125 is_request_from_webui_renderer =
126 content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
127 process_id);
103 } 128 }
104 129
105 const GURL& url = request->url(); 130 const GURL& url = request->url();
106 return IsSensitiveURL(url) || !HasWebRequestScheme(url); 131 return IsSensitiveURL(
132 url, is_request_from_browser || is_request_from_webui_renderer) ||
133 !HasWebRequestScheme(url);
107 } 134 }
108 135
109 // static 136 // static
110 void WebRequestPermissions:: 137 void WebRequestPermissions::
111 AllowAllExtensionLocationsInPublicSessionForTesting(bool value) { 138 AllowAllExtensionLocationsInPublicSessionForTesting(bool value) {
112 g_allow_all_extension_locations_in_public_session = value; 139 g_allow_all_extension_locations_in_public_session = value;
113 } 140 }
114 141
115 // static 142 // static
116 PermissionsData::AccessType WebRequestPermissions::CanExtensionAccessURL( 143 PermissionsData::AccessType WebRequestPermissions::CanExtensionAccessURL(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 break; 193 break;
167 case REQUIRE_ALL_URLS: 194 case REQUIRE_ALL_URLS:
168 if (extension->permissions_data()->HasEffectiveAccessToAllHosts()) 195 if (extension->permissions_data()->HasEffectiveAccessToAllHosts())
169 access = PermissionsData::ACCESS_ALLOWED; 196 access = PermissionsData::ACCESS_ALLOWED;
170 // else ACCESS_DENIED 197 // else ACCESS_DENIED
171 break; 198 break;
172 } 199 }
173 200
174 return access; 201 return access;
175 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698