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

Side by Side Diff: content/browser/site_instance_impl.cc

Issue 2831683002: Introduce support for origins that require process isolation. (Closed)
Patch Set: Fix compile 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 "content/browser/site_instance_impl.h" 5 #include "content/browser/site_instance_impl.h"
6 6
7 #include "base/macros.h"
Charlie Reis 2017/05/25 01:54:37 Is this still needed?
alexmos 2017/05/25 16:58:49 No - removed.
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "content/browser/browsing_instance.h" 9 #include "content/browser/browsing_instance.h"
9 #include "content/browser/child_process_security_policy_impl.h" 10 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/browser/frame_host/debug_urls.h" 11 #include "content/browser/frame_host/debug_urls.h"
11 #include "content/browser/frame_host/frame_tree_node.h" 12 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h" 13 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/browser/storage_partition_impl.h" 14 #include "content/browser/storage_partition_impl.h"
14 #include "content/common/site_isolation_policy.h" 15 #include "content/common/site_isolation_policy.h"
15 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/browser/render_process_host_factory.h" 17 #include "content/public/browser/render_process_host_factory.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // If either URL is invalid, they aren't part of the same site. 302 // If either URL is invalid, they aren't part of the same site.
302 if (!src_url.is_valid() || !dest_url.is_valid()) 303 if (!src_url.is_valid() || !dest_url.is_valid())
303 return false; 304 return false;
304 305
305 // If the destination url is just a blank page, we treat them as part of the 306 // If the destination url is just a blank page, we treat them as part of the
306 // same site. 307 // same site.
307 GURL blank_page(url::kAboutBlankURL); 308 GURL blank_page(url::kAboutBlankURL);
308 if (dest_url == blank_page) 309 if (dest_url == blank_page)
309 return true; 310 return true;
310 311
312 // If either URL has an isolated origin, compare origins rather than sites.
313 url::Origin src_origin(src_url);
314 url::Origin dest_origin(dest_url);
315 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
316 if (policy->IsIsolatedOrigin(src_origin) ||
317 policy->IsIsolatedOrigin(dest_origin))
318 return src_origin == dest_origin;
319
311 // If the schemes differ, they aren't part of the same site. 320 // If the schemes differ, they aren't part of the same site.
321 //
322 // Note that this happens after the isolated origin check, since blob or
323 // filesystem URLs will fail this check even though they might have the
324 // same origin.
Charlie Reis 2017/05/25 01:54:37 Now that you mention this, is this scheme check ev
alexmos 2017/05/25 16:58:49 Yes, indeed, I think it's a bug and I need to inve
312 if (src_url.scheme() != dest_url.scheme()) 325 if (src_url.scheme() != dest_url.scheme())
313 return false; 326 return false;
314 327
315 return net::registry_controlled_domains::SameDomainOrHost( 328 return net::registry_controlled_domains::SameDomainOrHost(
316 src_url, 329 src_url,
317 dest_url, 330 dest_url,
318 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 331 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
319 } 332 }
320 333
321 // static 334 // static
322 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, 335 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context,
323 const GURL& real_url) { 336 const GURL& real_url) {
324 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. 337 // TODO(fsamuel, creis): For some reason appID is not recognized as a host.
325 if (real_url.SchemeIs(kGuestScheme)) 338 if (real_url.SchemeIs(kGuestScheme))
326 return real_url; 339 return real_url;
327 340
328 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); 341 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url);
329 url::Origin origin(url); 342 url::Origin origin(url);
330 343
344 // Isolated origins should use the full origin as their site URL.
345 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
346 if (policy->IsIsolatedOrigin(origin))
347 return origin.GetURL();
348
331 // If the url has a host, then determine the site. 349 // If the url has a host, then determine the site.
332 if (!origin.host().empty()) { 350 if (!origin.host().empty()) {
333 // Only keep the scheme and registered domain of |origin|. 351 // Only keep the scheme and registered domain of |origin|.
334 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( 352 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
335 origin.host(), 353 origin.host(),
336 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 354 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
337 std::string site = origin.scheme(); 355 std::string site = origin.scheme();
338 site += url::kStandardSchemeSeparator; 356 site += url::kStandardSchemeSeparator;
339 site += domain.empty() ? origin.host() : domain; 357 site += domain.empty() ? origin.host() : domain;
340 return GURL(site); 358 return GURL(site);
341 } 359 }
342 360
343 // If there is no host but there is a scheme, return the scheme. 361 // If there is no host but there is a scheme, return the scheme.
344 // This is useful for cases like file URLs. 362 // This is useful for cases like file URLs.
345 if (url.has_scheme()) 363 if (url.has_scheme())
346 return GURL(url.scheme() + ":"); 364 return GURL(url.scheme() + ":");
347 365
348 // Otherwise the URL should be invalid; return an empty site. 366 // Otherwise the URL should be invalid; return an empty site.
349 DCHECK(!url.is_valid()); 367 DCHECK(!url.is_valid());
350 return GURL(); 368 return GURL();
351 } 369 }
352 370
353 // static 371 // static
354 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, 372 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context,
355 const GURL& url) { 373 const GURL& url) {
374 // Don't resolve URLs corresponding to isolated origins, as isolated origins
375 // take precedence over hosted apps.
376 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
377 if (policy->IsIsolatedOrigin(url::Origin(url)))
378 return url;
379
356 return GetContentClient()->browser()-> 380 return GetContentClient()->browser()->
357 GetEffectiveURL(browser_context, url); 381 GetEffectiveURL(browser_context, url);
358 } 382 }
359 383
360 // static 384 // static
361 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess( 385 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess(
362 BrowserContext* browser_context, 386 BrowserContext* browser_context,
363 const GURL& url) { 387 const GURL& url) {
364 // If --site-per-process is enabled, site isolation is enabled everywhere. 388 // If --site-per-process is enabled, site isolation is enabled everywhere.
365 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) 389 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites())
366 return true; 390 return true;
367 391
392 // For now, always require a dedicated process for isolated origins.
393 // TODO(alexmos): revisit this for Isolate-Me.
394 GURL site_url = GetSiteForURL(browser_context, url);
395 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
396 if (policy->IsIsolatedOrigin(url::Origin(site_url)))
397 return true;
398
368 // Let the content embedder enable site isolation for specific URLs. Use the 399 // Let the content embedder enable site isolation for specific URLs. Use the
369 // canonical site url for this check, so that schemes with nested origins 400 // canonical site url for this check, so that schemes with nested origins
370 // (blob and filesystem) work properly. 401 // (blob and filesystem) work properly.
371 GURL site_url = GetSiteForURL(browser_context, url);
372 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() && 402 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() &&
373 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess( 403 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess(
374 browser_context, site_url)) { 404 browser_context, site_url)) {
375 return true; 405 return true;
376 } 406 }
377 407
378 return false; 408 return false;
379 } 409 }
380 410
381 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { 411 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 browsing_instance_->browser_context(), site_)) 456 browsing_instance_->browser_context(), site_))
427 return; 457 return;
428 458
429 ChildProcessSecurityPolicyImpl* policy = 459 ChildProcessSecurityPolicyImpl* policy =
430 ChildProcessSecurityPolicyImpl::GetInstance(); 460 ChildProcessSecurityPolicyImpl::GetInstance();
431 policy->LockToOrigin(process_->GetID(), site_); 461 policy->LockToOrigin(process_->GetID(), site_);
432 } 462 }
433 } 463 }
434 464
435 } // namespace content 465 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | content/browser/site_instance_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698