OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
(...skipping 5625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5636 link_element; | 5636 link_element; |
5637 link_element = Traversal<HTMLLinkElement>::NextSibling(*link_element)) { | 5637 link_element = Traversal<HTMLLinkElement>::NextSibling(*link_element)) { |
5638 if (!link_element->RelAttribute().IsManifest()) | 5638 if (!link_element->RelAttribute().IsManifest()) |
5639 continue; | 5639 continue; |
5640 return link_element; | 5640 return link_element; |
5641 } | 5641 } |
5642 | 5642 |
5643 return 0; | 5643 return 0; |
5644 } | 5644 } |
5645 | 5645 |
5646 void Document::SetFeaturePolicy(const String& feature_policy_header) { | |
5647 if (!RuntimeEnabledFeatures::featurePolicyEnabled()) | |
5648 return; | |
5649 | |
5650 WebFeaturePolicy* parent_feature_policy = nullptr; | |
5651 WebParsedFeaturePolicy container_policy; | |
5652 Vector<String> messages; | |
5653 const WebParsedFeaturePolicy& parsed_header = | |
5654 ParseFeaturePolicy(feature_policy_header, GetSecurityOrigin(), &messages); | |
5655 | |
5656 // If this frame is not the main frame, then get the appropriate parent policy | |
5657 // and container policy to construct the policy for this frame. | |
5658 if (frame_) { | |
5659 if (!frame_->IsMainFrame()) { | |
5660 parent_feature_policy = | |
5661 frame_->Tree().Parent()->GetSecurityContext()->GetFeaturePolicy(); | |
5662 } | |
5663 if (frame_->Owner()) | |
5664 container_policy = frame_->Owner()->ContainerPolicy(); | |
5665 } | |
5666 | |
5667 // Check that if there is a parent frame, that its feature policy is | |
5668 // correctly initialized. Crash if that is not the case. (Temporary crash for | |
5669 // isolating the cause of https://crbug.com/722333) | |
5670 // Note that even with this check removed, the process will stil crash in | |
5671 // feature_policy.cc when it attempts to dereference parent_feature_policy. | |
5672 // This check is to distinguish between two possible causes. | |
5673 if (!container_policy.empty()) | |
5674 CHECK(frame_ && (frame_->IsMainFrame() || parent_feature_policy)); | |
5675 | |
5676 InitializeFeaturePolicy(parsed_header, container_policy, | |
5677 parent_feature_policy); | |
5678 | |
5679 for (auto& message : messages) { | |
jbroman
2017/05/26 18:33:16
nit: prefer "const auto&" where possible
iclelland
2017/05/26 19:14:25
Done.
| |
5680 AddConsoleMessage( | |
5681 ConsoleMessage::Create(kOtherMessageSource, kErrorMessageLevel, | |
5682 "Error with Feature-Policy header: " + message)); | |
5683 } | |
5684 if (frame_ && !parsed_header.empty()) | |
5685 frame_->Client()->DidSetFeaturePolicyHeader(parsed_header); | |
5686 } | |
5687 | |
5646 void Document::InitSecurityContext(const DocumentInit& initializer) { | 5688 void Document::InitSecurityContext(const DocumentInit& initializer) { |
5647 DCHECK(!GetSecurityOrigin()); | 5689 DCHECK(!GetSecurityOrigin()); |
5648 | 5690 |
5649 if (!initializer.HasSecurityContext()) { | 5691 if (!initializer.HasSecurityContext()) { |
5650 // No source for a security context. | 5692 // No source for a security context. |
5651 // This can occur via document.implementation.createDocument(). | 5693 // This can occur via document.implementation.createDocument(). |
5652 cookie_url_ = KURL(kParsedURLString, g_empty_string); | 5694 cookie_url_ = KURL(kParsedURLString, g_empty_string); |
5653 SetSecurityOrigin(SecurityOrigin::CreateUnique()); | 5695 SetSecurityOrigin(SecurityOrigin::CreateUnique()); |
5654 InitContentSecurityPolicy(); | 5696 InitContentSecurityPolicy(); |
5697 SetFeaturePolicy(""); | |
jbroman
2017/05/26 18:33:16
super-nit: g_empty_string is slightly more efficie
iclelland
2017/05/26 19:14:26
Done (both instances).
| |
5655 // Unique security origins cannot have a suborigin | 5698 // Unique security origins cannot have a suborigin |
5656 return; | 5699 return; |
5657 } | 5700 } |
5658 | 5701 |
5659 // In the common case, create the security context from the currently | 5702 // In the common case, create the security context from the currently |
5660 // loading URL with a fresh content security policy. | 5703 // loading URL with a fresh content security policy. |
5661 EnforceSandboxFlags(initializer.GetSandboxFlags()); | 5704 EnforceSandboxFlags(initializer.GetSandboxFlags()); |
5662 SetInsecureRequestPolicy(initializer.GetInsecureRequestPolicy()); | 5705 SetInsecureRequestPolicy(initializer.GetInsecureRequestPolicy()); |
5663 if (initializer.InsecureNavigationsToUpgrade()) { | 5706 if (initializer.InsecureNavigationsToUpgrade()) { |
5664 for (auto to_upgrade : *initializer.InsecureNavigationsToUpgrade()) | 5707 for (auto to_upgrade : *initializer.InsecureNavigationsToUpgrade()) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5745 is_srcdoc_document_ = true; | 5788 is_srcdoc_document_ = true; |
5746 SetBaseURLOverride(initializer.ParentBaseURL()); | 5789 SetBaseURLOverride(initializer.ParentBaseURL()); |
5747 } | 5790 } |
5748 | 5791 |
5749 if (GetSecurityOrigin()->IsUnique() && | 5792 if (GetSecurityOrigin()->IsUnique() && |
5750 SecurityOrigin::Create(url_)->IsPotentiallyTrustworthy()) | 5793 SecurityOrigin::Create(url_)->IsPotentiallyTrustworthy()) |
5751 GetSecurityOrigin()->SetUniqueOriginIsPotentiallyTrustworthy(true); | 5794 GetSecurityOrigin()->SetUniqueOriginIsPotentiallyTrustworthy(true); |
5752 | 5795 |
5753 if (GetSecurityOrigin()->HasSuborigin()) | 5796 if (GetSecurityOrigin()->HasSuborigin()) |
5754 EnforceSuborigin(*GetSecurityOrigin()->GetSuborigin()); | 5797 EnforceSuborigin(*GetSecurityOrigin()->GetSuborigin()); |
5798 | |
5799 SetFeaturePolicy(""); | |
5755 } | 5800 } |
5756 | 5801 |
5757 void Document::InitContentSecurityPolicy(ContentSecurityPolicy* csp) { | 5802 void Document::InitContentSecurityPolicy(ContentSecurityPolicy* csp) { |
5758 SetContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::Create()); | 5803 SetContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::Create()); |
5759 | 5804 |
5760 // We inherit the parent/opener's CSP for documents with "local" schemes: | 5805 // We inherit the parent/opener's CSP for documents with "local" schemes: |
5761 // 'about', 'blob', 'data', and 'filesystem'. We also inherit CSP for | 5806 // 'about', 'blob', 'data', and 'filesystem'. We also inherit CSP for |
5762 // documents with empty/invalid URLs because we treat those URLs as | 5807 // documents with empty/invalid URLs because we treat those URLs as |
5763 // 'about:blank' in Blink. | 5808 // 'about:blank' in Blink. |
5764 // | 5809 // |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6804 } | 6849 } |
6805 | 6850 |
6806 void showLiveDocumentInstances() { | 6851 void showLiveDocumentInstances() { |
6807 WeakDocumentSet& set = liveDocumentSet(); | 6852 WeakDocumentSet& set = liveDocumentSet(); |
6808 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6853 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
6809 for (blink::Document* document : set) | 6854 for (blink::Document* document : set) |
6810 fprintf(stderr, "- Document %p URL: %s\n", document, | 6855 fprintf(stderr, "- Document %p URL: %s\n", document, |
6811 document->Url().GetString().Utf8().data()); | 6856 document->Url().GetString().Utf8().data()); |
6812 } | 6857 } |
6813 #endif | 6858 #endif |
OLD | NEW |