Chromium Code Reviews| Index: content/browser/child_process_security_policy_impl.cc |
| diff --git a/content/browser/child_process_security_policy_impl.cc b/content/browser/child_process_security_policy_impl.cc |
| index 210a3c3c7cb5c9e7c2c9ab5e7c957a6a69c6cbc9..eb26ff4e081a84bebf13d394cf060e4548a13769 100644 |
| --- a/content/browser/child_process_security_policy_impl.cc |
| +++ b/content/browser/child_process_security_policy_impl.cc |
| @@ -17,6 +17,7 @@ |
| #include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "build/build_config.h" |
| +#include "content/browser/isolated_origin_util.h" |
| #include "content/browser/site_instance_impl.h" |
| #include "content/common/resource_request_body_impl.h" |
| #include "content/common/site_isolation_policy.h" |
| @@ -1094,10 +1095,11 @@ void ChildProcessSecurityPolicyImpl::AddIsolatedOrigin( |
| const url::Origin& origin) { |
| CHECK(!origin.unique()) |
| << "Cannot register a unique origin as an isolated origin."; |
|
ncarter (slow)
2017/06/28 20:59:19
Should this enforce SchemeIsHttpOrHttps? The domai
alexmos
2017/06/29 21:54:02
That's a good idea. Besides problematic subdomain
|
| - CHECK(!IsIsolatedOrigin(origin)) |
| - << "Duplicate isolated origin: " << origin.Serialize(); |
|
ncarter (slow)
2017/06/28 20:59:19
Do we get into any trouble if origin's hostname is
alexmos
2017/06/29 21:54:02
It probably should be ok to isolate an IP address,
|
| base::AutoLock lock(lock_); |
| + CHECK(!isolated_origins_.count(origin)) |
| + << "Duplicate isolated origin: " << origin.Serialize(); |
| + |
| isolated_origins_.insert(origin); |
| } |
| @@ -1114,8 +1116,38 @@ void ChildProcessSecurityPolicyImpl::AddIsolatedOriginsFromCommandLine( |
| bool ChildProcessSecurityPolicyImpl::IsIsolatedOrigin( |
| const url::Origin& origin) { |
| + url::Origin unused_result; |
| + return GetMatchingIsolatedOrigin(origin, &unused_result); |
| +} |
| + |
| +bool ChildProcessSecurityPolicyImpl::GetMatchingIsolatedOrigin( |
| + const url::Origin& origin, |
| + url::Origin* result) { |
| + *result = url::Origin(); |
| + base::AutoLock lock(lock_); |
| + |
| + // If multiple isolated origins are registered with a common domain suffix, |
| + // return the most specific one. For example, if foo.isolated.com and |
| + // isolated.com are both isolated origins, bar.foo.isolated.com should return |
| + // foo.isolated.com. |
| + bool found = false; |
| + for (auto isolated_origin : isolated_origins_) { |
| + if (IsolatedOriginUtil::DoesOriginMatchIsolatedOrigin(origin, |
| + isolated_origin)) { |
| + if (!found || result->host().length() < isolated_origin.host().length()) { |
| + *result = isolated_origin; |
| + found = true; |
| + } |
| + } |
| + } |
| + |
| + return found; |
| +} |
| + |
| +void ChildProcessSecurityPolicyImpl::RemoveIsolatedOriginForTesting( |
| + const url::Origin& origin) { |
| base::AutoLock lock(lock_); |
| - return isolated_origins_.find(origin) != isolated_origins_.end(); |
| + isolated_origins_.erase(origin); |
| } |
| } // namespace content |