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 "content/browser/site_instance_impl.h" | 5 #include "content/browser/site_instance_impl.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "content/browser/browsing_instance.h" | 9 #include "content/browser/browsing_instance.h" |
10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // If either URL is invalid, they aren't part of the same site. | 312 // If either URL is invalid, they aren't part of the same site. |
313 if (!src_url.is_valid() || !dest_url.is_valid()) | 313 if (!src_url.is_valid() || !dest_url.is_valid()) |
314 return false; | 314 return false; |
315 | 315 |
316 // If the destination url is just a blank page, we treat them as part of the | 316 // If the destination url is just a blank page, we treat them as part of the |
317 // same site. | 317 // same site. |
318 GURL blank_page(url::kAboutBlankURL); | 318 GURL blank_page(url::kAboutBlankURL); |
319 if (dest_url == blank_page) | 319 if (dest_url == blank_page) |
320 return true; | 320 return true; |
321 | 321 |
322 // If either URL has an isolated origin, compare origins rather than sites. | 322 // If either URL matches an isolated origin, compare origins rather than |
| 323 // sites. |
323 url::Origin src_origin(src_url); | 324 url::Origin src_origin(src_url); |
324 url::Origin dest_origin(dest_url); | 325 url::Origin dest_origin(dest_url); |
325 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); | 326 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); |
326 if (policy->IsIsolatedOrigin(src_origin) || | 327 url::Origin src_isolated_origin; |
327 policy->IsIsolatedOrigin(dest_origin)) | 328 url::Origin dest_isolated_origin; |
328 return src_origin == dest_origin; | 329 bool src_origin_is_isolated = |
| 330 policy->GetMatchingIsolatedOrigin(src_origin, &src_isolated_origin); |
| 331 bool dest_origin_is_isolated = |
| 332 policy->GetMatchingIsolatedOrigin(dest_origin, &dest_isolated_origin); |
| 333 if (src_origin_is_isolated || dest_origin_is_isolated) { |
| 334 // Compare most specific matching origins to ensure that a subdomain of an |
| 335 // isolated origin (e.g., https://subdomain.isolated.foo.com) also matches |
| 336 // the isolated origin's site URL (e.g., https://isolated.foo.com). |
| 337 return src_isolated_origin == dest_isolated_origin; |
| 338 } |
329 | 339 |
330 // If the schemes differ, they aren't part of the same site. | 340 // If the schemes differ, they aren't part of the same site. |
331 if (src_origin.scheme() != dest_origin.scheme()) | 341 if (src_origin.scheme() != dest_origin.scheme()) |
332 return false; | 342 return false; |
333 | 343 |
334 return net::registry_controlled_domains::SameDomainOrHost( | 344 return net::registry_controlled_domains::SameDomainOrHost( |
335 src_origin, dest_origin, | 345 src_origin, dest_origin, |
336 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 346 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
337 } | 347 } |
338 | 348 |
339 // static | 349 // static |
340 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, | 350 GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, |
341 const GURL& real_url) { | 351 const GURL& real_url) { |
342 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. | 352 // TODO(fsamuel, creis): For some reason appID is not recognized as a host. |
343 if (real_url.SchemeIs(kGuestScheme)) | 353 if (real_url.SchemeIs(kGuestScheme)) |
344 return real_url; | 354 return real_url; |
345 | 355 |
346 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); | 356 GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); |
347 url::Origin origin(url); | 357 url::Origin origin(url); |
348 | 358 |
349 // Isolated origins should use the full origin as their site URL. | 359 // Isolated origins should use the full origin as their site URL. A subdomain |
| 360 // of an isolated origin should also use that isolated origin's site URL. |
350 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); | 361 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); |
351 if (policy->IsIsolatedOrigin(origin)) | 362 url::Origin isolated_origin; |
352 return origin.GetURL(); | 363 if (policy->GetMatchingIsolatedOrigin(url::Origin(real_url), |
| 364 &isolated_origin)) { |
| 365 return isolated_origin.GetURL(); |
| 366 } |
353 | 367 |
354 // If the url has a host, then determine the site. | 368 // If the url has a host, then determine the site. |
355 if (!origin.host().empty()) { | 369 if (!origin.host().empty()) { |
356 // Only keep the scheme and registered domain of |origin|. | 370 // Only keep the scheme and registered domain of |origin|. |
357 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( | 371 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( |
358 origin.host(), | 372 origin.host(), |
359 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 373 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
360 std::string site = origin.scheme(); | 374 std::string site = origin.scheme(); |
361 site += url::kStandardSchemeSeparator; | 375 site += url::kStandardSchemeSeparator; |
362 site += domain.empty() ? origin.host() : domain; | 376 site += domain.empty() ? origin.host() : domain; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 // prevent the non-isolated sites from requesting resources for isolated | 498 // prevent the non-isolated sites from requesting resources for isolated |
485 // sites. https://crbug.com/509125 | 499 // sites. https://crbug.com/509125 |
486 if (ShouldLockToOrigin(GetBrowserContext(), site_)) { | 500 if (ShouldLockToOrigin(GetBrowserContext(), site_)) { |
487 ChildProcessSecurityPolicyImpl* policy = | 501 ChildProcessSecurityPolicyImpl* policy = |
488 ChildProcessSecurityPolicyImpl::GetInstance(); | 502 ChildProcessSecurityPolicyImpl::GetInstance(); |
489 policy->LockToOrigin(process_->GetID(), site_); | 503 policy->LockToOrigin(process_->GetID(), site_); |
490 } | 504 } |
491 } | 505 } |
492 | 506 |
493 } // namespace content | 507 } // namespace content |
OLD | NEW |