Chromium Code Reviews| 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 ResourceResponse response; | |
| 867 response.setURL(KURL(ParsedURLString, "about:blank")); | |
| 868 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, | |
| 869 AtomicString("not a valid header")); | |
| 870 EXPECT_TRUE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( | |
| 871 response, secureOrigin.get())); | |
| 872 | |
| 873 // Same origin automatically should accept required CSP. | |
|
Mike West
2016/10/17 14:54:28
I think this test would be clearer if it didn't re
| |
| 874 response.setURL(KURL(ParsedURLString, "https://example.test/index.html")); | |
| 875 EXPECT_TRUE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( | |
| 876 response, secureOrigin.get())); | |
| 877 | |
| 878 // Protocols do not match. | |
| 879 response.setURL(KURL(ParsedURLString, "http://example.test/index.html")); | |
| 880 EXPECT_FALSE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( | |
| 881 response, secureOrigin.get())); | |
| 882 | |
| 883 // Different origin and invalid header. | |
| 884 response.setURL(KURL(ParsedURLString, "https://different.test/index.html")); | |
| 885 EXPECT_FALSE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( | |
| 886 response, secureOrigin.get())); | |
| 887 | |
| 888 // Different origin and valid header but not equal to the embedder origin. | |
| 889 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, | |
| 890 AtomicString("http://example.test")); | |
| 891 EXPECT_FALSE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( | |
| 892 response, secureOrigin.get())); | |
| 893 | |
| 894 // Different origin and valid header. | |
| 895 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, | |
| 896 AtomicString("https://example.test")); | |
| 897 EXPECT_TRUE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( | |
| 898 response, secureOrigin.get())); | |
| 899 | |
| 900 // Star should enforce any embedder's policy. | |
| 901 response.setHTTPHeaderField(HTTPNames::Allow_CSP_From, AtomicString("*")); | |
| 902 EXPECT_TRUE(ContentSecurityPolicy::shouldEnforceEmbeddersPolicy( | |
| 903 response, secureOrigin.get())); | |
| 904 } | |
| 905 | |
| 865 } // namespace blink | 906 } // namespace blink |
| OLD | NEW |