OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/browser/child_process_security_policy.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "content/browser/site_instance.h" | 13 #include "content/browser/site_instance.h" |
| 14 #include "content/public/browser/content_browser_client.h" |
14 #include "content/public/common/bindings_policy.h" | 15 #include "content/public/common/bindings_policy.h" |
15 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_job_factory.h" |
18 | 20 |
19 static const int kReadFilePermissions = | 21 static const int kReadFilePermissions = |
20 base::PLATFORM_FILE_OPEN | | 22 base::PLATFORM_FILE_OPEN | |
21 base::PLATFORM_FILE_READ | | 23 base::PLATFORM_FILE_READ | |
22 base::PLATFORM_FILE_EXCLUSIVE_READ | | 24 base::PLATFORM_FILE_EXCLUSIVE_READ | |
23 base::PLATFORM_FILE_ASYNC; | 25 base::PLATFORM_FILE_ASYNC; |
24 | 26 |
25 static const int kEnumerateDirectoryPermissions = | 27 static const int kEnumerateDirectoryPermissions = |
26 kReadFilePermissions | | 28 kReadFilePermissions | |
27 base::PLATFORM_FILE_ENUMERATE; | 29 base::PLATFORM_FILE_ENUMERATE; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 196 |
195 void ChildProcessSecurityPolicy::RegisterWebSafeScheme( | 197 void ChildProcessSecurityPolicy::RegisterWebSafeScheme( |
196 const std::string& scheme) { | 198 const std::string& scheme) { |
197 base::AutoLock lock(lock_); | 199 base::AutoLock lock(lock_); |
198 DCHECK(web_safe_schemes_.count(scheme) == 0) << "Add schemes at most once."; | 200 DCHECK(web_safe_schemes_.count(scheme) == 0) << "Add schemes at most once."; |
199 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Web-safe implies not pseudo."; | 201 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Web-safe implies not pseudo."; |
200 | 202 |
201 web_safe_schemes_.insert(scheme); | 203 web_safe_schemes_.insert(scheme); |
202 } | 204 } |
203 | 205 |
204 bool ChildProcessSecurityPolicy::IsWebSafeScheme(const std::string& scheme) { | 206 bool ChildProcessSecurityPolicy::IsWebSafeScheme( |
| 207 const std::string& scheme) const { |
205 base::AutoLock lock(lock_); | 208 base::AutoLock lock(lock_); |
206 | |
207 return (web_safe_schemes_.find(scheme) != web_safe_schemes_.end()); | 209 return (web_safe_schemes_.find(scheme) != web_safe_schemes_.end()); |
208 } | 210 } |
209 | 211 |
210 void ChildProcessSecurityPolicy::RegisterPseudoScheme( | 212 void ChildProcessSecurityPolicy::RegisterPseudoScheme( |
211 const std::string& scheme) { | 213 const std::string& scheme) { |
212 base::AutoLock lock(lock_); | 214 base::AutoLock lock(lock_); |
213 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Add schemes at most once."; | 215 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Add schemes at most once."; |
214 DCHECK(web_safe_schemes_.count(scheme) == 0) << | 216 DCHECK(web_safe_schemes_.count(scheme) == 0) << |
215 "Pseudo implies not web-safe."; | 217 "Pseudo implies not web-safe."; |
216 | 218 |
217 pseudo_schemes_.insert(scheme); | 219 pseudo_schemes_.insert(scheme); |
218 } | 220 } |
219 | 221 |
220 bool ChildProcessSecurityPolicy::IsPseudoScheme(const std::string& scheme) { | 222 bool ChildProcessSecurityPolicy::IsPseudoScheme( |
| 223 const std::string& scheme) const { |
221 base::AutoLock lock(lock_); | 224 base::AutoLock lock(lock_); |
222 | |
223 return (pseudo_schemes_.find(scheme) != pseudo_schemes_.end()); | 225 return (pseudo_schemes_.find(scheme) != pseudo_schemes_.end()); |
224 } | 226 } |
225 | 227 |
226 void ChildProcessSecurityPolicy::RegisterDisabledSchemes( | 228 void ChildProcessSecurityPolicy::RegisterDisabledSchemes( |
227 const std::set<std::string>& schemes) { | 229 const std::set<std::string>& schemes) { |
228 base::AutoLock lock(lock_); | 230 base::AutoLock lock(lock_); |
229 disabled_schemes_ = schemes; | 231 disabled_schemes_ = schemes; |
230 } | 232 } |
231 | 233 |
232 bool ChildProcessSecurityPolicy::IsDisabledScheme(const std::string& scheme) { | 234 bool ChildProcessSecurityPolicy::IsDisabledScheme( |
| 235 const std::string& scheme) const { |
233 base::AutoLock lock(lock_); | 236 base::AutoLock lock(lock_); |
234 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); | 237 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); |
235 } | 238 } |
236 | 239 |
237 void ChildProcessSecurityPolicy::GrantRequestURL( | 240 void ChildProcessSecurityPolicy::GrantRequestURL( |
238 int child_id, const GURL& url) { | 241 int child_id, const GURL& url) { |
239 | 242 |
240 if (!url.is_valid()) | 243 if (!url.is_valid()) |
241 return; // Can't grant the capability to request invalid URLs. | 244 return; // Can't grant the capability to request invalid URLs. |
242 | 245 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 base::AutoLock lock(lock_); | 345 base::AutoLock lock(lock_); |
343 | 346 |
344 SecurityStateMap::iterator state = security_state_.find(child_id); | 347 SecurityStateMap::iterator state = security_state_.find(child_id); |
345 if (state == security_state_.end()) | 348 if (state == security_state_.end()) |
346 return; | 349 return; |
347 | 350 |
348 state->second->RevokeReadRawCookies(); | 351 state->second->RevokeReadRawCookies(); |
349 } | 352 } |
350 | 353 |
351 bool ChildProcessSecurityPolicy::CanRequestURL( | 354 bool ChildProcessSecurityPolicy::CanRequestURL( |
352 int child_id, const GURL& url) { | 355 int child_id, |
| 356 const GURL& url, |
| 357 const net::URLRequestJobFactory* job_factory) const { |
353 if (!url.is_valid()) | 358 if (!url.is_valid()) |
354 return false; // Can't request invalid URLs. | 359 return false; // Can't request invalid URLs. |
355 | 360 |
356 if (IsDisabledScheme(url.scheme())) | 361 if (IsDisabledScheme(url.scheme())) |
357 return false; // The scheme is disabled by policy. | 362 return false; // The scheme is disabled by policy. |
358 | 363 |
359 if (IsWebSafeScheme(url.scheme())) | 364 if (IsWebSafeScheme(url.scheme())) |
360 return true; // The scheme has been white-listed for every child process. | 365 return true; // The scheme has been white-listed for every child process. |
361 | 366 |
362 if (IsPseudoScheme(url.scheme())) { | 367 if (IsPseudoScheme(url.scheme())) { |
363 // There are a number of special cases for pseudo schemes. | 368 // There are a number of special cases for pseudo schemes. |
364 | 369 |
365 if (url.SchemeIs(chrome::kViewSourceScheme)) { | 370 if (url.SchemeIs(chrome::kViewSourceScheme)) { |
366 // A view-source URL is allowed if the child process is permitted to | 371 // A view-source URL is allowed if the child process is permitted to |
367 // request the embedded URL. Careful to avoid pointless recursion. | 372 // request the embedded URL. Careful to avoid pointless recursion. |
368 GURL child_url(url.path()); | 373 GURL child_url(url.path()); |
369 if (child_url.SchemeIs(chrome::kViewSourceScheme) && | 374 if (child_url.SchemeIs(chrome::kViewSourceScheme) && |
370 url.SchemeIs(chrome::kViewSourceScheme)) | 375 url.SchemeIs(chrome::kViewSourceScheme)) |
371 return false; | 376 return false; |
372 | 377 |
373 return CanRequestURL(child_id, child_url); | 378 return CanRequestURL(child_id, child_url, NULL); |
374 } | 379 } |
375 | 380 |
376 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutBlankURL)) | 381 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutBlankURL)) |
377 return true; // Every child process can request <about:blank>. | 382 return true; // Every child process can request <about:blank>. |
378 | 383 |
379 // URLs like <about:memory> and <about:crash> shouldn't be requestable by | 384 // URLs like <about:memory> and <about:crash> shouldn't be requestable by |
380 // any child process. Also, this case covers <javascript:...>, which should | 385 // any child process. Also, this case covers <javascript:...>, which should |
381 // be handled internally by the process and not kicked up to the browser. | 386 // be handled internally by the process and not kicked up to the browser. |
382 return false; | 387 return false; |
383 } | 388 } |
384 | 389 |
385 if (!net::URLRequest::IsHandledURL(url)) | 390 if (job_factory) { |
386 return true; // This URL request is destined for ShellExecute. | 391 if (!job_factory->IsHandledURL(url)) |
| 392 return true; |
| 393 } else { |
| 394 if (!content::GetContentClient()->browser()->IsHandledURL(url)) |
| 395 return true; |
| 396 } |
387 | 397 |
388 { | 398 { |
389 base::AutoLock lock(lock_); | 399 base::AutoLock lock(lock_); |
390 | 400 |
391 SecurityStateMap::iterator state = security_state_.find(child_id); | 401 SecurityStateMap::const_iterator state = security_state_.find(child_id); |
392 if (state == security_state_.end()) | 402 if (state == security_state_.end()) |
393 return false; | 403 return false; |
394 | 404 |
395 // Otherwise, we consult the child process's security state to see if it is | 405 // Otherwise, we consult the child process's security state to see if it is |
396 // allowed to request the URL. | 406 // allowed to request the URL. |
397 return state->second->CanRequestURL(url); | 407 return state->second->CanRequestURL(url); |
398 } | 408 } |
399 } | 409 } |
400 | 410 |
401 bool ChildProcessSecurityPolicy::CanReadFile(int child_id, | 411 bool ChildProcessSecurityPolicy::CanReadFile(int child_id, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 485 |
476 void ChildProcessSecurityPolicy::LockToOrigin(int child_id, const GURL& gurl) { | 486 void ChildProcessSecurityPolicy::LockToOrigin(int child_id, const GURL& gurl) { |
477 // "gurl" can be currently empty in some cases, such as file://blah. | 487 // "gurl" can be currently empty in some cases, such as file://blah. |
478 DCHECK(SiteInstance::GetSiteForURL(NULL, gurl) == gurl); | 488 DCHECK(SiteInstance::GetSiteForURL(NULL, gurl) == gurl); |
479 base::AutoLock lock(lock_); | 489 base::AutoLock lock(lock_); |
480 SecurityStateMap::iterator state = security_state_.find(child_id); | 490 SecurityStateMap::iterator state = security_state_.find(child_id); |
481 DCHECK(state != security_state_.end()); | 491 DCHECK(state != security_state_.end()); |
482 state->second->LockToOrigin(gurl); | 492 state->second->LockToOrigin(gurl); |
483 } | 493 } |
484 | 494 |
OLD | NEW |