| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const std::string key = Keys()[0]; | 82 const std::string key = Keys()[0]; |
| 82 if (!extension->manifest()->HasPath(key)) { | 83 if (!extension->manifest()->HasPath(key)) { |
| 83 if (extension->manifest_version() >= 2) { | 84 if (extension->manifest_version() >= 2) { |
| 84 // TODO(abarth): Should we continue to let extensions override the | 85 // TODO(abarth): Should we continue to let extensions override the |
| 85 // default Content-Security-Policy? | 86 // default Content-Security-Policy? |
| 86 std::string content_security_policy = is_platform_app_ ? | 87 std::string content_security_policy = is_platform_app_ ? |
| 87 kDefaultPlatformAppContentSecurityPolicy : | 88 kDefaultPlatformAppContentSecurityPolicy : |
| 88 kDefaultContentSecurityPolicy; | 89 kDefaultContentSecurityPolicy; |
| 89 | 90 |
| 90 CHECK(ContentSecurityPolicyIsSecure(content_security_policy, | 91 CHECK(ContentSecurityPolicyIsSecure(content_security_policy, |
| 91 extension->GetType())); | 92 extension->GetType(), NULL, NULL)); |
| 92 extension->SetManifestData(keys::kContentSecurityPolicy, | 93 extension->SetManifestData(keys::kContentSecurityPolicy, |
| 93 new CSPInfo(content_security_policy)); | 94 new CSPInfo(content_security_policy)); |
| 94 } | 95 } |
| 95 return true; | 96 return true; |
| 96 } | 97 } |
| 97 | 98 |
| 98 std::string content_security_policy; | 99 std::string content_security_policy; |
| 99 if (!extension->manifest()->GetString(key, &content_security_policy)) { | 100 if (!extension->manifest()->GetString(key, &content_security_policy)) { |
| 100 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); | 101 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); |
| 101 return false; | 102 return false; |
| 102 } | 103 } |
| 103 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { | 104 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { |
| 104 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); | 105 *error = base::ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); |
| 105 return false; | 106 return false; |
| 106 } | 107 } |
| 108 std::string sanitized_csp; |
| 109 std::vector<InstallWarning> warnings; |
| 107 if (extension->manifest_version() >= 2 && | 110 if (extension->manifest_version() >= 2 && |
| 108 !ContentSecurityPolicyIsSecure(content_security_policy, | 111 !ContentSecurityPolicyIsSecure(content_security_policy, |
| 109 extension->GetType())) { | 112 extension->GetType(), &sanitized_csp, |
| 110 *error = base::ASCIIToUTF16(errors::kInsecureContentSecurityPolicy); | 113 &warnings)) { |
| 111 return false; | 114 extension->AddInstallWarnings(warnings); |
| 115 content_security_policy = sanitized_csp; |
| 112 } | 116 } |
| 113 | 117 |
| 114 extension->SetManifestData(keys::kContentSecurityPolicy, | 118 extension->SetManifestData(keys::kContentSecurityPolicy, |
| 115 new CSPInfo(content_security_policy)); | 119 new CSPInfo(content_security_policy)); |
| 116 return true; | 120 return true; |
| 117 } | 121 } |
| 118 | 122 |
| 119 bool CSPHandler::AlwaysParseForType(Manifest::Type type) const { | 123 bool CSPHandler::AlwaysParseForType(Manifest::Type type) const { |
| 120 if (is_platform_app_) | 124 if (is_platform_app_) |
| 121 return type == Manifest::TYPE_PLATFORM_APP; | 125 return type == Manifest::TYPE_PLATFORM_APP; |
| 122 else | 126 else |
| 123 return type == Manifest::TYPE_EXTENSION || | 127 return type == Manifest::TYPE_EXTENSION || |
| 124 type == Manifest::TYPE_LEGACY_PACKAGED_APP; | 128 type == Manifest::TYPE_LEGACY_PACKAGED_APP; |
| 125 } | 129 } |
| 126 | 130 |
| 127 const std::vector<std::string> CSPHandler::Keys() const { | 131 const std::vector<std::string> CSPHandler::Keys() const { |
| 128 const std::string& key = is_platform_app_ ? | 132 const std::string& key = is_platform_app_ ? |
| 129 keys::kPlatformAppContentSecurityPolicy : keys::kContentSecurityPolicy; | 133 keys::kPlatformAppContentSecurityPolicy : keys::kContentSecurityPolicy; |
| 130 return SingleKey(key); | 134 return SingleKey(key); |
| 131 } | 135 } |
| 132 | 136 |
| 133 } // namespace extensions | 137 } // namespace extensions |
| OLD | NEW |