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/child_process_security_policy_impl.h" | 5 #include "content/browser/child_process_security_policy_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/debug/dump_without_crashing.h" | 11 #include "base/debug/dump_without_crashing.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "content/browser/isolated_origin_util.h" | |
20 #include "content/browser/site_instance_impl.h" | 21 #include "content/browser/site_instance_impl.h" |
21 #include "content/common/resource_request_body_impl.h" | 22 #include "content/common/resource_request_body_impl.h" |
22 #include "content/common/site_isolation_policy.h" | 23 #include "content/common/site_isolation_policy.h" |
23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/child_process_data.h" | 26 #include "content/public/browser/child_process_data.h" |
26 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
29 #include "content/public/common/bindings_policy.h" | 30 #include "content/public/common/bindings_policy.h" |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 SecurityStateMap::iterator state = security_state_.find(child_id); | 1087 SecurityStateMap::iterator state = security_state_.find(child_id); |
1087 if (state == security_state_.end()) | 1088 if (state == security_state_.end()) |
1088 return false; | 1089 return false; |
1089 | 1090 |
1090 return state->second->can_send_midi_sysex(); | 1091 return state->second->can_send_midi_sysex(); |
1091 } | 1092 } |
1092 | 1093 |
1093 void ChildProcessSecurityPolicyImpl::AddIsolatedOrigin( | 1094 void ChildProcessSecurityPolicyImpl::AddIsolatedOrigin( |
1094 const url::Origin& origin) { | 1095 const url::Origin& origin) { |
1095 CHECK(!origin.unique()) | 1096 CHECK(!origin.unique()) |
1096 << "Cannot register a unique origin as an isolated origin."; | 1097 << "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
| |
1097 CHECK(!IsIsolatedOrigin(origin)) | 1098 |
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,
| |
1099 base::AutoLock lock(lock_); | |
1100 CHECK(!isolated_origins_.count(origin)) | |
1098 << "Duplicate isolated origin: " << origin.Serialize(); | 1101 << "Duplicate isolated origin: " << origin.Serialize(); |
1099 | 1102 |
1100 base::AutoLock lock(lock_); | |
1101 isolated_origins_.insert(origin); | 1103 isolated_origins_.insert(origin); |
1102 } | 1104 } |
1103 | 1105 |
1104 void ChildProcessSecurityPolicyImpl::AddIsolatedOriginsFromCommandLine( | 1106 void ChildProcessSecurityPolicyImpl::AddIsolatedOriginsFromCommandLine( |
1105 const std::string& origin_list) { | 1107 const std::string& origin_list) { |
1106 for (const base::StringPiece& origin_piece : | 1108 for (const base::StringPiece& origin_piece : |
1107 base::SplitStringPiece(origin_list, ",", base::TRIM_WHITESPACE, | 1109 base::SplitStringPiece(origin_list, ",", base::TRIM_WHITESPACE, |
1108 base::SPLIT_WANT_NONEMPTY)) { | 1110 base::SPLIT_WANT_NONEMPTY)) { |
1109 url::Origin origin((GURL(origin_piece))); | 1111 url::Origin origin((GURL(origin_piece))); |
1110 if (!origin.unique()) | 1112 if (!origin.unique()) |
1111 AddIsolatedOrigin(origin); | 1113 AddIsolatedOrigin(origin); |
1112 } | 1114 } |
1113 } | 1115 } |
1114 | 1116 |
1115 bool ChildProcessSecurityPolicyImpl::IsIsolatedOrigin( | 1117 bool ChildProcessSecurityPolicyImpl::IsIsolatedOrigin( |
1116 const url::Origin& origin) { | 1118 const url::Origin& origin) { |
1119 url::Origin unused_result; | |
1120 return GetMatchingIsolatedOrigin(origin, &unused_result); | |
1121 } | |
1122 | |
1123 bool ChildProcessSecurityPolicyImpl::GetMatchingIsolatedOrigin( | |
1124 const url::Origin& origin, | |
1125 url::Origin* result) { | |
1126 *result = url::Origin(); | |
1117 base::AutoLock lock(lock_); | 1127 base::AutoLock lock(lock_); |
1118 return isolated_origins_.find(origin) != isolated_origins_.end(); | 1128 |
1129 // If multiple isolated origins are registered with a common domain suffix, | |
1130 // return the most specific one. For example, if foo.isolated.com and | |
1131 // isolated.com are both isolated origins, bar.foo.isolated.com should return | |
1132 // foo.isolated.com. | |
1133 bool found = false; | |
1134 for (auto isolated_origin : isolated_origins_) { | |
1135 if (IsolatedOriginUtil::DoesOriginMatchIsolatedOrigin(origin, | |
1136 isolated_origin)) { | |
1137 if (!found || result->host().length() < isolated_origin.host().length()) { | |
1138 *result = isolated_origin; | |
1139 found = true; | |
1140 } | |
1141 } | |
1142 } | |
1143 | |
1144 return found; | |
1145 } | |
1146 | |
1147 void ChildProcessSecurityPolicyImpl::RemoveIsolatedOriginForTesting( | |
1148 const url::Origin& origin) { | |
1149 base::AutoLock lock(lock_); | |
1150 isolated_origins_.erase(origin); | |
1119 } | 1151 } |
1120 | 1152 |
1121 } // namespace content | 1153 } // namespace content |
OLD | NEW |