Commit f492353d authored by Daniel Vogelheim's avatar Daniel Vogelheim Committed by Commit Bot

CSP/Trusted Types: No trusted-types policy means CSP allows all policies.

It's possible to use Trusted Types without the trusted-types CSP directive.
In that case, all policies are allowed. (The current code will just crash.)

Bug: 739170
Change-Id: I0a832be30f97f7401db221038119af491e418521
Reviewed-on: https://chromium-review.googlesource.com/1245781
Commit-Queue: Daniel Vogelheim <vogelheim@chromium.org>
Reviewed-by: default avatarAndy Paicu <andypaicu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594313}
parent 04c5a83e
...@@ -1383,4 +1383,30 @@ TEST_F(ContentSecurityPolicyTest, IsValidCSPAttrTest) { ...@@ -1383,4 +1383,30 @@ TEST_F(ContentSecurityPolicyTest, IsValidCSPAttrTest) {
"\rbase-uri http://example.com", "")); "\rbase-uri http://example.com", ""));
} }
TEST_F(ContentSecurityPolicyTest, TrustedTypesNoDirective) {
csp->BindToExecutionContext(execution_context.Get());
csp->DidReceiveHeader("", kContentSecurityPolicyHeaderTypeEnforce,
kContentSecurityPolicyHeaderSourceHTTP);
EXPECT_TRUE(csp->AllowTrustedTypePolicy("somepolicy"));
}
TEST_F(ContentSecurityPolicyTest, TrustedTypesSimpleDirective) {
csp->BindToExecutionContext(execution_context.Get());
csp->DidReceiveHeader("trusted-types one two three",
kContentSecurityPolicyHeaderTypeEnforce,
kContentSecurityPolicyHeaderSourceHTTP);
EXPECT_TRUE(csp->AllowTrustedTypePolicy("one"));
EXPECT_TRUE(csp->AllowTrustedTypePolicy("two"));
EXPECT_TRUE(csp->AllowTrustedTypePolicy("three"));
EXPECT_FALSE(csp->AllowTrustedTypePolicy("four"));
}
TEST_F(ContentSecurityPolicyTest, TrustedTypesEmpty) {
csp->BindToExecutionContext(execution_context.Get());
csp->DidReceiveHeader("trusted-types",
kContentSecurityPolicyHeaderTypeEnforce,
kContentSecurityPolicyHeaderSourceHTTP);
EXPECT_TRUE(csp->AllowTrustedTypePolicy("somepolicy"));
}
} // namespace blink } // namespace blink
...@@ -963,7 +963,7 @@ bool CSPDirectiveList::AllowBaseURI( ...@@ -963,7 +963,7 @@ bool CSPDirectiveList::AllowBaseURI(
} }
bool CSPDirectiveList::AllowTrustedTypePolicy(const String& policy_name) const { bool CSPDirectiveList::AllowTrustedTypePolicy(const String& policy_name) const {
if (trusted_types_->Allows(policy_name)) if (!trusted_types_ || trusted_types_->Allows(policy_name))
return true; return true;
ReportViolation( ReportViolation(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment