OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "core/frame/csp/ContentSecurityPolicy.h" | 5 #include "core/frame/csp/ContentSecurityPolicy.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/fetch/IntegrityMetadata.h" | 8 #include "core/fetch/IntegrityMetadata.h" |
9 #include "core/frame/csp/CSPDirectiveList.h" | 9 #include "core/frame/csp/CSPDirectiveList.h" |
10 #include "core/loader/DocumentLoader.h" | 10 #include "core/loader/DocumentLoader.h" |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 ContentSecurityPolicyHeaderSourceHTTP); | 855 ContentSecurityPolicyHeaderSourceHTTP); |
856 policy->didReceiveHeader(test.policy2, | 856 policy->didReceiveHeader(test.policy2, |
857 ContentSecurityPolicyHeaderTypeReport, | 857 ContentSecurityPolicyHeaderTypeReport, |
858 ContentSecurityPolicyHeaderSourceHTTP); | 858 ContentSecurityPolicyHeaderSourceHTTP); |
859 EXPECT_TRUE(policy->allowScriptFromSource(resource, String(test.nonce), | 859 EXPECT_TRUE(policy->allowScriptFromSource(resource, String(test.nonce), |
860 ParserInserted)); | 860 ParserInserted)); |
861 EXPECT_EQ(expectedReports, policy->m_violationReportsSent.size()); | 861 EXPECT_EQ(expectedReports, policy->m_violationReportsSent.size()); |
862 } | 862 } |
863 } | 863 } |
864 | 864 |
| 865 TEST_F(ContentSecurityPolicyTest, ShouldEnforceEmbeddersPolicy) { |
| 866 struct TestCase { |
| 867 const char* resourceURL; |
| 868 const bool inherits; |
| 869 } cases[] = { |
| 870 // Same-origin |
| 871 {"https://example.test/index.html", true}, |
| 872 // Cross-origin |
| 873 {"http://example.test/index.html", false}, |
| 874 {"http://example.test:8443/index.html", false}, |
| 875 {"https://example.test:8443/index.html", false}, |
| 876 {"http://not.example.test/index.html", false}, |
| 877 {"https://not.example.test/index.html", false}, |
| 878 {"https://not.example.test:8443/index.html", false}, |
| 879 |
| 880 // Inherit |
| 881 {"about:blank", true}, |
| 882 {"data:text/html,yay", true}, |
| 883 {"blob:https://example.test/bbe708f3-defd-4852-93b6-cf94e032f08d", true}, |
| 884 {"filesystem:http://example.test/temporary/index.html", true}, |
| 885 }; |
| 886 |
| 887 for (const auto& test : cases) { |
| 888 ResourceResponse response; |
| 889 response.setURL(KURL(ParsedURLString, test.resourceURL)); |
| 890 EXPECT_EQ(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( |
| 891 response, secureOrigin.get()), |
| 892 test.inherits); |
| 893 |
| 894 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, AtomicString("*")); |
| 895 EXPECT_TRUE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( |
| 896 response, secureOrigin.get())); |
| 897 |
| 898 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, |
| 899 AtomicString("* not a valid header")); |
| 900 EXPECT_EQ(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( |
| 901 response, secureOrigin.get()), |
| 902 test.inherits); |
| 903 |
| 904 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, |
| 905 AtomicString("http://example.test")); |
| 906 EXPECT_EQ(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( |
| 907 response, secureOrigin.get()), |
| 908 test.inherits); |
| 909 |
| 910 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, |
| 911 AtomicString("https://example.test")); |
| 912 EXPECT_TRUE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( |
| 913 response, secureOrigin.get())); |
| 914 } |
| 915 } |
| 916 |
865 } // namespace blink | 917 } // namespace blink |
OLD | NEW |