OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/manifest_handlers/csp_info.h" | 5 #include "extensions/common/manifest_handlers/csp_info.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "extensions/common/csp_validator.h" | 11 #include "extensions/common/csp_validator.h" |
12 #include "extensions/common/install_warning.h" | |
12 #include "extensions/common/manifest_constants.h" | 13 #include "extensions/common/manifest_constants.h" |
13 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" | 14 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" |
14 | 15 |
15 namespace extensions { | 16 namespace extensions { |
16 | 17 |
17 namespace keys = manifest_keys; | 18 namespace keys = manifest_keys; |
18 namespace errors = manifest_errors; | 19 namespace errors = manifest_errors; |
19 | 20 |
20 using csp_validator::ContentSecurityPolicyIsLegal; | 21 using csp_validator::ContentSecurityPolicyIsLegal; |
21 using csp_validator::ContentSecurityPolicyIsSecure; | 22 using csp_validator::ContentSecurityPolicyIsSecure; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 bool CSPHandler::Parse(Extension* extension, base::string16* error) { | 102 bool CSPHandler::Parse(Extension* extension, base::string16* error) { |
102 const std::string key = Keys()[0]; | 103 const std::string key = Keys()[0]; |
103 if (!extension->manifest()->HasPath(key)) { | 104 if (!extension->manifest()->HasPath(key)) { |
104 if (extension->manifest_version() >= 2) { | 105 if (extension->manifest_version() >= 2) { |
105 // TODO(abarth): Should we continue to let extensions override the | 106 // TODO(abarth): Should we continue to let extensions override the |
106 // default Content-Security-Policy? | 107 // default Content-Security-Policy? |
107 std::string content_security_policy = is_platform_app_ ? | 108 std::string content_security_policy = is_platform_app_ ? |
108 kDefaultPlatformAppContentSecurityPolicy : | 109 kDefaultPlatformAppContentSecurityPolicy : |
109 kDefaultContentSecurityPolicy; | 110 kDefaultContentSecurityPolicy; |
110 | 111 |
111 CHECK(ContentSecurityPolicyIsSecure(content_security_policy, | 112 CHECK(ContentSecurityPolicyIsSecure(content_security_policy, |
not at google - send to devlin
2014/12/01 19:19:31
Indeed I find these changes hard to reason about b
| |
112 GetValidatorOptions(extension))); | 113 GetValidatorOptions(extension), |
114 NULL, NULL)); | |
113 extension->SetManifestData(keys::kContentSecurityPolicy, | 115 extension->SetManifestData(keys::kContentSecurityPolicy, |
114 new CSPInfo(content_security_policy)); | 116 new CSPInfo(content_security_policy)); |
115 } | 117 } |
116 return true; | 118 return true; |
117 } | 119 } |
118 | 120 |
119 std::string content_security_policy; | 121 std::string content_security_policy; |
120 if (!extension->manifest()->GetString(key, &content_security_policy)) { | 122 if (!extension->manifest()->GetString(key, &content_security_policy)) { |
121 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); | 123 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); |
122 return false; | 124 return false; |
123 } | 125 } |
124 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { | 126 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { |
125 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); | 127 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); |
126 return false; | 128 return false; |
127 } | 129 } |
130 std::string sanitized_csp; | |
131 std::vector<InstallWarning> warnings; | |
128 if (extension->manifest_version() >= 2 && | 132 if (extension->manifest_version() >= 2 && |
129 !ContentSecurityPolicyIsSecure(content_security_policy, | 133 !ContentSecurityPolicyIsSecure(content_security_policy, |
130 GetValidatorOptions(extension))) { | 134 GetValidatorOptions(extension), |
131 *error = base::ASCIIToUTF16(errors::kInsecureContentSecurityPolicy); | 135 &sanitized_csp, &warnings)) { |
132 return false; | 136 extension->AddInstallWarnings(warnings); |
137 content_security_policy = sanitized_csp; | |
133 } | 138 } |
134 | 139 |
135 extension->SetManifestData(keys::kContentSecurityPolicy, | 140 extension->SetManifestData(keys::kContentSecurityPolicy, |
136 new CSPInfo(content_security_policy)); | 141 new CSPInfo(content_security_policy)); |
137 return true; | 142 return true; |
138 } | 143 } |
139 | 144 |
140 bool CSPHandler::AlwaysParseForType(Manifest::Type type) const { | 145 bool CSPHandler::AlwaysParseForType(Manifest::Type type) const { |
141 if (is_platform_app_) | 146 if (is_platform_app_) |
142 return type == Manifest::TYPE_PLATFORM_APP; | 147 return type == Manifest::TYPE_PLATFORM_APP; |
143 else | 148 else |
144 return type == Manifest::TYPE_EXTENSION || | 149 return type == Manifest::TYPE_EXTENSION || |
145 type == Manifest::TYPE_LEGACY_PACKAGED_APP; | 150 type == Manifest::TYPE_LEGACY_PACKAGED_APP; |
146 } | 151 } |
147 | 152 |
148 const std::vector<std::string> CSPHandler::Keys() const { | 153 const std::vector<std::string> CSPHandler::Keys() const { |
149 const std::string& key = is_platform_app_ ? | 154 const std::string& key = is_platform_app_ ? |
150 keys::kPlatformAppContentSecurityPolicy : keys::kContentSecurityPolicy; | 155 keys::kPlatformAppContentSecurityPolicy : keys::kContentSecurityPolicy; |
151 return SingleKey(key); | 156 return SingleKey(key); |
152 } | 157 } |
153 | 158 |
154 } // namespace extensions | 159 } // namespace extensions |
OLD | NEW |