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

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

Issue 2831683002: Introduce support for origins that require process isolation. (Closed)
Patch Set: Charlie's comments (round 3) 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
« no previous file with comments | « content/browser/site_instance_impl.h ('k') | content/browser/site_instance_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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.
325 //
326 // TODO(alexmos): This check seems broken for nested URLs involving
327 // non-isolated origins too. See https://crbug.com/726370.
312 if (src_url.scheme() != dest_url.scheme()) 328 if (src_url.scheme() != dest_url.scheme())
313 return false; 329 return false;
314 330
315 return net::registry_controlled_domains::SameDomainOrHost( 331 return net::registry_controlled_domains::SameDomainOrHost(
316 src_url, 332 src_url,
317 dest_url, 333 dest_url,
318 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 334 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
319 } 335 }
320 336
321 // static 337 // static
322 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, 338 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context,
323 const GURL& real_url) { 339 const GURL& real_url) {
324 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. 340 // TODO(fsamuel, creis): For some reason appID is not recognized as a host.
325 if (real_url.SchemeIs(kGuestScheme)) 341 if (real_url.SchemeIs(kGuestScheme))
326 return real_url; 342 return real_url;
327 343
328 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); 344 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url);
329 url::Origin origin(url); 345 url::Origin origin(url);
330 346
347 // Isolated origins should use the full origin as their site URL.
348 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
349 if (policy->IsIsolatedOrigin(origin))
350 return origin.GetURL();
351
331 // If the url has a host, then determine the site. 352 // If the url has a host, then determine the site.
332 if (!origin.host().empty()) { 353 if (!origin.host().empty()) {
333 // Only keep the scheme and registered domain of |origin|. 354 // Only keep the scheme and registered domain of |origin|.
334 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( 355 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
335 origin.host(), 356 origin.host(),
336 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 357 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
337 std::string site = origin.scheme(); 358 std::string site = origin.scheme();
338 site += url::kStandardSchemeSeparator; 359 site += url::kStandardSchemeSeparator;
339 site += domain.empty() ? origin.host() : domain; 360 site += domain.empty() ? origin.host() : domain;
340 return GURL(site); 361 return GURL(site);
341 } 362 }
342 363
343 // If there is no host but there is a scheme, return the scheme. 364 // If there is no host but there is a scheme, return the scheme.
344 // This is useful for cases like file URLs. 365 // This is useful for cases like file URLs.
345 if (url.has_scheme()) 366 if (url.has_scheme())
346 return GURL(url.scheme() + ":"); 367 return GURL(url.scheme() + ":");
347 368
348 // Otherwise the URL should be invalid; return an empty site. 369 // Otherwise the URL should be invalid; return an empty site.
349 DCHECK(!url.is_valid()); 370 DCHECK(!url.is_valid());
350 return GURL(); 371 return GURL();
351 } 372 }
352 373
353 // static 374 // static
354 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, 375 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context,
355 const GURL& url) { 376 const GURL& url) {
377 // Don't resolve URLs corresponding to isolated origins, as isolated origins
378 // take precedence over hosted apps.
379 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
380 if (policy->IsIsolatedOrigin(url::Origin(url)))
381 return url;
382
356 return GetContentClient()->browser()-> 383 return GetContentClient()->browser()->
357 GetEffectiveURL(browser_context, url); 384 GetEffectiveURL(browser_context, url);
358 } 385 }
359 386
360 // static 387 // static
361 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess( 388 bool SiteInstanceImpl::DoesSiteRequireDedicatedProcess(
362 BrowserContext* browser_context, 389 BrowserContext* browser_context,
363 const GURL& url) { 390 const GURL& url) {
364 // If --site-per-process is enabled, site isolation is enabled everywhere. 391 // If --site-per-process is enabled, site isolation is enabled everywhere.
365 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) 392 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites())
366 return true; 393 return true;
367 394
395 // Always require a dedicated process for isolated origins.
396 GURL site_url = GetSiteForURL(browser_context, url);
397 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
398 if (policy->IsIsolatedOrigin(url::Origin(site_url)))
399 return true;
400
368 // Let the content embedder enable site isolation for specific URLs. Use the 401 // 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 402 // canonical site url for this check, so that schemes with nested origins
370 // (blob and filesystem) work properly. 403 // (blob and filesystem) work properly.
371 GURL site_url = GetSiteForURL(browser_context, url);
372 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() && 404 if (GetContentClient()->IsSupplementarySiteIsolationModeEnabled() &&
373 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess( 405 GetContentClient()->browser()->DoesSiteRequireDedicatedProcess(
374 browser_context, site_url)) { 406 browser_context, site_url)) {
375 return true; 407 return true;
376 } 408 }
377 409
378 return false; 410 return false;
379 } 411 }
380 412
381 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { 413 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 browsing_instance_->browser_context(), site_)) 458 browsing_instance_->browser_context(), site_))
427 return; 459 return;
428 460
429 ChildProcessSecurityPolicyImpl* policy = 461 ChildProcessSecurityPolicyImpl* policy =
430 ChildProcessSecurityPolicyImpl::GetInstance(); 462 ChildProcessSecurityPolicyImpl::GetInstance();
431 policy->LockToOrigin(process_->GetID(), site_); 463 policy->LockToOrigin(process_->GetID(), site_);
432 } 464 }
433 } 465 }
434 466
435 } // namespace content 467 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/site_instance_impl.h ('k') | content/browser/site_instance_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698