| 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" |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 619 |
| 620 state->second->RevokeReadRawCookies(); | 620 state->second->RevokeReadRawCookies(); |
| 621 } | 621 } |
| 622 | 622 |
| 623 bool ChildProcessSecurityPolicyImpl::CanRequestURL( | 623 bool ChildProcessSecurityPolicyImpl::CanRequestURL( |
| 624 int child_id, const GURL& url) { | 624 int child_id, const GURL& url) { |
| 625 if (!url.is_valid()) | 625 if (!url.is_valid()) |
| 626 return false; // Can't request invalid URLs. | 626 return false; // Can't request invalid URLs. |
| 627 | 627 |
| 628 if (IsPseudoScheme(url.scheme())) { | 628 if (IsPseudoScheme(url.scheme())) { |
| 629 // Every child process can request <about:blank>. | 629 // Every child process can request <about:blank> and <about:srcdoc>. |
| 630 if (base::LowerCaseEqualsASCII(url.spec(), url::kAboutBlankURL)) | 630 if (url == url::kAboutBlankURL || url == kAboutSrcDocURL) |
| 631 return true; | 631 return true; |
| 632 // URLs like <about:version>, <about:crash>, <view-source:...> shouldn't be | 632 // URLs like <about:version>, <about:crash>, <view-source:...> shouldn't be |
| 633 // requestable by any child process. Also, this case covers | 633 // requestable by any child process. Also, this case covers |
| 634 // <javascript:...>, which should be handled internally by the process and | 634 // <javascript:...>, which should be handled internally by the process and |
| 635 // not kicked up to the browser. | 635 // not kicked up to the browser. |
| 636 return false; | 636 return false; |
| 637 } | 637 } |
| 638 | 638 |
| 639 // Blob and filesystem URLs require special treatment, since they embed an | 639 // Blob and filesystem URLs require special treatment, since they embed an |
| 640 // inner origin. | 640 // inner origin. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 657 // Also allow URLs destined for ShellExecute and not the browser itself. | 657 // Also allow URLs destined for ShellExecute and not the browser itself. |
| 658 return !GetContentClient()->browser()->IsHandledURL(url) && | 658 return !GetContentClient()->browser()->IsHandledURL(url) && |
| 659 !net::URLRequest::IsHandledURL(url); | 659 !net::URLRequest::IsHandledURL(url); |
| 660 } | 660 } |
| 661 | 661 |
| 662 bool ChildProcessSecurityPolicyImpl::CanCommitURL(int child_id, | 662 bool ChildProcessSecurityPolicyImpl::CanCommitURL(int child_id, |
| 663 const GURL& url) { | 663 const GURL& url) { |
| 664 if (!url.is_valid()) | 664 if (!url.is_valid()) |
| 665 return false; // Can't commit invalid URLs. | 665 return false; // Can't commit invalid URLs. |
| 666 | 666 |
| 667 // Of all the pseudo schemes, only about:blank is allowed to commit. | 667 // Of all the pseudo schemes, only about:blank and about:srcdoc are allowed to |
| 668 // commit. |
| 668 if (IsPseudoScheme(url.scheme())) | 669 if (IsPseudoScheme(url.scheme())) |
| 669 return base::LowerCaseEqualsASCII(url.spec(), url::kAboutBlankURL); | 670 return url == url::kAboutBlankURL || url == kAboutSrcDocURL; |
| 670 | 671 |
| 671 // Blob and filesystem URLs require special treatment; validate the inner | 672 // Blob and filesystem URLs require special treatment; validate the inner |
| 672 // origin they embed. | 673 // origin they embed. |
| 673 if (url.SchemeIsBlob() || url.SchemeIsFileSystem()) { | 674 if (url.SchemeIsBlob() || url.SchemeIsFileSystem()) { |
| 674 if (IsMalformedBlobUrl(url)) | 675 if (IsMalformedBlobUrl(url)) |
| 675 return false; | 676 return false; |
| 676 | 677 |
| 677 url::Origin origin(url); | 678 url::Origin origin(url); |
| 678 return origin.unique() || CanCommitURL(child_id, GURL(origin.Serialize())); | 679 return origin.unique() || CanCommitURL(child_id, GURL(origin.Serialize())); |
| 679 } | 680 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 710 if (!url.is_valid()) | 711 if (!url.is_valid()) |
| 711 return false; // Can't set invalid URLs as origin headers. | 712 return false; // Can't set invalid URLs as origin headers. |
| 712 | 713 |
| 713 // Suborigin URLs are a special case and are allowed to be an origin header. | 714 // Suborigin URLs are a special case and are allowed to be an origin header. |
| 714 if (url.scheme() == url::kHttpSuboriginScheme || | 715 if (url.scheme() == url::kHttpSuboriginScheme || |
| 715 url.scheme() == url::kHttpsSuboriginScheme) { | 716 url.scheme() == url::kHttpsSuboriginScheme) { |
| 716 DCHECK(IsPseudoScheme(url.scheme())); | 717 DCHECK(IsPseudoScheme(url.scheme())); |
| 717 return true; | 718 return true; |
| 718 } | 719 } |
| 719 | 720 |
| 721 // about:srcdoc cannot be used as an origin |
| 722 if (url == kAboutSrcDocURL) |
| 723 return false; |
| 724 |
| 720 // If this process can commit |url|, it can use |url| as an origin for | 725 // If this process can commit |url|, it can use |url| as an origin for |
| 721 // outbound requests. | 726 // outbound requests. |
| 722 if (CanCommitURL(child_id, url)) | 727 if (CanCommitURL(child_id, url)) |
| 723 return true; | 728 return true; |
| 724 | 729 |
| 725 // Allow schemes which may come from scripts executing in isolated worlds; | 730 // Allow schemes which may come from scripts executing in isolated worlds; |
| 726 // XHRs issued by such scripts reflect the script origin rather than the | 731 // XHRs issued by such scripts reflect the script origin rather than the |
| 727 // document origin. | 732 // document origin. |
| 728 { | 733 { |
| 729 base::AutoLock lock(lock_); | 734 base::AutoLock lock(lock_); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 base::AutoLock lock(lock_); | 998 base::AutoLock lock(lock_); |
| 994 | 999 |
| 995 SecurityStateMap::iterator state = security_state_.find(child_id); | 1000 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 996 if (state == security_state_.end()) | 1001 if (state == security_state_.end()) |
| 997 return false; | 1002 return false; |
| 998 | 1003 |
| 999 return state->second->can_send_midi_sysex(); | 1004 return state->second->can_send_midi_sysex(); |
| 1000 } | 1005 } |
| 1001 | 1006 |
| 1002 } // namespace content | 1007 } // namespace content |
| OLD | NEW |