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

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

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

Powered by Google App Engine
This is Rietveld 408576698