Chromium Code Reviews| 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 "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 Loading... | |
| 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, bool is_request_from_renderer) { |
| 46 // TODO(battre) Merge this, CanExtensionAccessURL and | 47 // TODO(battre) Merge this, CanExtensionAccessURL and |
| 47 // PermissionsData::CanAccessPage into one function. | 48 // PermissionsData::CanAccessPage into one function. |
| 48 bool sensitive_chrome_url = false; | 49 bool sensitive_chrome_url = false; |
| 49 const base::StringPiece& host = url.host_piece(); | 50 base::StringPiece host = url.host_piece(); |
| 51 while (host.ends_with(".")) | |
| 52 host.remove_suffix(1u); | |
| 50 const char kGoogleCom[] = "google.com"; | 53 const char kGoogleCom[] = "google.com"; |
| 51 const char kClient[] = "clients"; | 54 const char kClient[] = "clients"; |
| 52 if (url.DomainIs(kGoogleCom)) { | 55 if (url.DomainIs(kGoogleCom)) { |
| 53 // Check for "clients[0-9]*.google.com" hosts. | 56 // Check for "clients[0-9]*.google.com" hosts. |
| 54 // This protects requests to several internal services such as sync, | 57 // This protects requests to several internal services such as sync, |
| 55 // extension update pings, captive portal detection, fraudulent certificate | 58 // extension update pings, captive portal detection, fraudulent certificate |
| 56 // reporting, autofill and others. | 59 // reporting, autofill and others. |
| 57 if (base::StartsWith(host, kClient, base::CompareCase::SENSITIVE)) { | 60 // |
| 61 // These URLs are only protected for requests from the browser, not | |
| 62 // for requests from renderers, because clients*.google.com also used | |
| 63 // by websites. | |
| 64 base::StringPiece::size_type pos = host.rfind(kClient); | |
|
Devlin
2017/05/04 15:33:29
Is this change to protect subdomains of clients*.g
Devlin
2017/05/04 15:33:29
nit: given the area of code this is called in and
battre
2017/05/04 15:53:46
Sure, will do this if Matt is ok with the general
battre
2017/05/04 15:53:46
Yes, this is to generalize the code. A couple of v
battre
2017/05/10 09:18:38
Done.
| |
| 65 if (!is_request_from_renderer && pos != base::StringPiece::npos) { | |
|
mmenke
2017/05/04 15:54:41
So we're only filtering out sensitive requests not
Devlin
2017/05/04 17:31:25
I'm not comfortable with that (yet). We have a *t
mmenke
2017/05/04 17:33:16
So what if those thumbnails are from a clients.goo
Devlin
2017/05/04 18:06:00
For want of a better solution, we'll protect them.
mmenke
2017/05/05 14:35:14
Could we instead have the initiators tag sensitive
Devlin
2017/05/05 16:16:03
Yes - that's what I was mentioning about relying o
mmenke
2017/05/05 16:18:03
Sorry, completely missed that.
battre
2017/05/10 09:18:37
Acknowledged.
| |
| 58 bool match = true; | 66 bool match = true; |
| 59 for (base::StringPiece::const_iterator | 67 if (pos > 0 && host[pos - 1] != '.') { |
| 60 i = host.begin() + strlen(kClient), | 68 match = false; |
| 61 end = host.end() - (strlen(kGoogleCom) + 1); | 69 } else { |
| 62 i != end; ++i) { | 70 for (base::StringPiece::const_iterator |
|
Devlin
2017/05/04 15:33:29
I think this loop is right, but it's kind of a sha
battre
2017/05/10 09:18:37
Leaving this as is. I did not find anything better
| |
| 63 if (!isdigit(*i)) { | 71 i = host.begin() + pos + strlen(kClient), |
| 64 match = false; | 72 end = host.end() - (strlen(kGoogleCom) + 1); |
| 65 break; | 73 i != end; ++i) { |
| 74 if (!isdigit(*i)) { | |
| 75 match = false; | |
| 76 break; | |
| 77 } | |
| 66 } | 78 } |
| 67 } | 79 } |
| 68 sensitive_chrome_url = sensitive_chrome_url || match; | 80 sensitive_chrome_url = sensitive_chrome_url || match; |
| 69 } | 81 } |
| 70 // This protects requests to safe browsing, link doctor, and possibly | 82 |
| 71 // others. | 83 // Safebrowsing and Chrome Webstore URLs are also protected for requests |
| 84 // from renderers. | |
| 72 sensitive_chrome_url = sensitive_chrome_url || | 85 sensitive_chrome_url = sensitive_chrome_url || |
| 73 url.DomainIs("clients.google.com") || | |
| 74 url.DomainIs("sb-ssl.google.com") || | 86 url.DomainIs("sb-ssl.google.com") || |
| 75 (url.DomainIs("chrome.google.com") && | 87 (url.DomainIs("chrome.google.com") && |
| 76 base::StartsWith(url.path_piece(), "/webstore", | 88 base::StartsWith(url.path_piece(), "/webstore", |
| 77 base::CompareCase::SENSITIVE)); | 89 base::CompareCase::SENSITIVE)); |
| 78 } | 90 } |
| 79 return sensitive_chrome_url || extension_urls::IsWebstoreUpdateUrl(url) || | 91 return sensitive_chrome_url || extension_urls::IsWebstoreUpdateUrl(url) || |
| 80 extension_urls::IsBlacklistUpdateUrl(url); | 92 extension_urls::IsBlacklistUpdateUrl(url); |
| 81 } | 93 } |
| 82 | 94 |
| 83 // static | 95 // static |
| 84 bool WebRequestPermissions::HideRequest( | 96 bool WebRequestPermissions::HideRequest( |
| 85 const extensions::InfoMap* extension_info_map, | 97 const extensions::InfoMap* extension_info_map, |
| 86 const net::URLRequest* request, | 98 const net::URLRequest* request, |
| 87 extensions::ExtensionNavigationUIData* navigation_ui_data) { | 99 extensions::ExtensionNavigationUIData* navigation_ui_data) { |
| 88 // Hide requests from the Chrome WebStore App or signin process. | 100 // Hide requests from the Chrome WebStore App, signin process and WebUI. |
| 89 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 101 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 90 if (info) { | 102 if (info) { |
| 91 int process_id = info->GetChildID(); | 103 int process_id = info->GetChildID(); |
| 92 // Never hide requests from guest processes. | 104 // Never hide requests from guest processes. |
| 93 if (extensions::WebViewRendererState::GetInstance()->IsGuest(process_id) || | 105 if (extensions::WebViewRendererState::GetInstance()->IsGuest(process_id) || |
| 94 (navigation_ui_data && navigation_ui_data->is_web_view())) { | 106 (navigation_ui_data && navigation_ui_data->is_web_view())) { |
| 95 return false; | 107 return false; |
| 96 } | 108 } |
| 97 | 109 |
| 98 if (extension_info_map && | 110 if (extension_info_map && |
| 99 extension_info_map->process_map().Contains(extensions::kWebStoreAppId, | 111 extension_info_map->process_map().Contains(extensions::kWebStoreAppId, |
| 100 process_id)) { | 112 process_id)) { |
| 101 return true; | 113 return true; |
| 102 } | 114 } |
| 115 | |
| 116 // Always hide requests from WebUI. This is ok based on the assumption | |
| 117 // that WebUI and regular sites never share the same renderer process | |
| 118 // and the assumption that WebUI deserves protection from extensions. | |
| 119 if (content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( | |
| 120 process_id)) { | |
|
Devlin
2017/05/04 15:33:29
I'd actually prefer we only do this in the case of
battre
2017/05/04 15:53:46
Sure, will do this if Matt is ok with the general
mmenke
2017/05/04 15:56:33
I'm fine with that.
Devlin
2017/05/04 17:31:25
We could just pass a bool is_webui_process to IsSe
battre
2017/05/10 09:18:37
Done.
| |
| 121 return true; | |
| 122 } | |
| 103 } | 123 } |
| 104 | 124 |
| 105 const GURL& url = request->url(); | 125 const GURL& url = request->url(); |
| 106 return IsSensitiveURL(url) || !HasWebRequestScheme(url); | 126 bool is_request_from_renderer = info != nullptr; |
| 127 return IsSensitiveURL(url, is_request_from_renderer) || | |
| 128 !HasWebRequestScheme(url); | |
| 107 } | 129 } |
| 108 | 130 |
| 109 // static | 131 // static |
| 110 void WebRequestPermissions:: | 132 void WebRequestPermissions:: |
| 111 AllowAllExtensionLocationsInPublicSessionForTesting(bool value) { | 133 AllowAllExtensionLocationsInPublicSessionForTesting(bool value) { |
| 112 g_allow_all_extension_locations_in_public_session = value; | 134 g_allow_all_extension_locations_in_public_session = value; |
| 113 } | 135 } |
| 114 | 136 |
| 115 // static | 137 // static |
| 116 PermissionsData::AccessType WebRequestPermissions::CanExtensionAccessURL( | 138 PermissionsData::AccessType WebRequestPermissions::CanExtensionAccessURL( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 break; | 188 break; |
| 167 case REQUIRE_ALL_URLS: | 189 case REQUIRE_ALL_URLS: |
| 168 if (extension->permissions_data()->HasEffectiveAccessToAllHosts()) | 190 if (extension->permissions_data()->HasEffectiveAccessToAllHosts()) |
| 169 access = PermissionsData::ACCESS_ALLOWED; | 191 access = PermissionsData::ACCESS_ALLOWED; |
| 170 // else ACCESS_DENIED | 192 // else ACCESS_DENIED |
| 171 break; | 193 break; |
| 172 } | 194 } |
| 173 | 195 |
| 174 return access; | 196 return access; |
| 175 } | 197 } |
| OLD | NEW |