Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 8585020: Enable CSP by default for extensions with manifest_version >= 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 // KEY MARKERS 57 // KEY MARKERS
58 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; 58 const char kKeyBeginHeaderMarker[] = "-----BEGIN";
59 const char kKeyBeginFooterMarker[] = "-----END"; 59 const char kKeyBeginFooterMarker[] = "-----END";
60 const char kKeyInfoEndMarker[] = "KEY-----"; 60 const char kKeyInfoEndMarker[] = "KEY-----";
61 const char kPublic[] = "PUBLIC"; 61 const char kPublic[] = "PUBLIC";
62 const char kPrivate[] = "PRIVATE"; 62 const char kPrivate[] = "PRIVATE";
63 63
64 const int kRSAKeySize = 1024; 64 const int kRSAKeySize = 1024;
65 65
66 const char kDefaultContentSecurityPolicy[] =
67 "script-src 'self'; object-src 'self'";
68
66 // Converts a normal hexadecimal string into the alphabet used by extensions. 69 // Converts a normal hexadecimal string into the alphabet used by extensions.
67 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a 70 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a
68 // completely numeric host, since some software interprets that as an IP 71 // completely numeric host, since some software interprets that as an IP
69 // address. 72 // address.
70 static void ConvertHexadecimalToIDAlphabet(std::string* id) { 73 static void ConvertHexadecimalToIDAlphabet(std::string* id) {
71 for (size_t i = 0; i < id->size(); ++i) { 74 for (size_t i = 0; i < id->size(); ++i) {
72 int val; 75 int val;
73 if (base::HexStringToInt(id->begin() + i, id->begin() + i + 1, &val)) 76 if (base::HexStringToInt(id->begin() + i, id->begin() + i + 1, &val))
74 (*id)[i] = val + 'a'; 77 (*id)[i] = val + 'a';
75 else 78 else
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 return true; 1271 return true;
1269 } 1272 }
1270 1273
1271 // static 1274 // static
1272 bool Extension::IsTrustedId(const std::string& id) { 1275 bool Extension::IsTrustedId(const std::string& id) {
1273 // See http://b/4946060 for more details. 1276 // See http://b/4946060 for more details.
1274 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); 1277 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd");
1275 } 1278 }
1276 1279
1277 Extension::Extension(const FilePath& path, Location location) 1280 Extension::Extension(const FilePath& path, Location location)
1278 : incognito_split_mode_(false), 1281 : manifest_version_(0),
1282 incognito_split_mode_(false),
1279 offline_enabled_(false), 1283 offline_enabled_(false),
1280 location_(location), 1284 location_(location),
1281 converted_from_user_script_(false), 1285 converted_from_user_script_(false),
1282 is_theme_(false), 1286 is_theme_(false),
1283 is_app_(false), 1287 is_app_(false),
1284 is_platform_app_(false), 1288 is_platform_app_(false),
1285 is_storage_isolated_(false), 1289 is_storage_isolated_(false),
1286 launch_container_(extension_misc::LAUNCH_TAB), 1290 launch_container_(extension_misc::LAUNCH_TAB),
1287 launch_width_(0), 1291 launch_width_(0),
1288 launch_height_(0), 1292 launch_height_(0),
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 // When strict error checks are enabled, make URL pattern parsing strict. 1451 // When strict error checks are enabled, make URL pattern parsing strict.
1448 URLPattern::ParseOption parse_strictness = 1452 URLPattern::ParseOption parse_strictness =
1449 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS 1453 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS
1450 : URLPattern::IGNORE_PORTS); 1454 : URLPattern::IGNORE_PORTS);
1451 1455
1452 // Initialize permissions with an empty, default permission set. 1456 // Initialize permissions with an empty, default permission set.
1453 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); 1457 runtime_data_.SetActivePermissions(new ExtensionPermissionSet());
1454 optional_permission_set_ = new ExtensionPermissionSet(); 1458 optional_permission_set_ = new ExtensionPermissionSet();
1455 required_permission_set_ = new ExtensionPermissionSet(); 1459 required_permission_set_ = new ExtensionPermissionSet();
1456 1460
1461 if (source.HasKey(keys::kManifestVersion)) {
1462 int manifest_version = 0;
1463 if (!source.GetInteger(keys::kPublicKey, &manifest_version) ||
1464 manifest_version < 1) {
1465 *error = errors::kInvalidManifestVersion;
1466 return false;
1467 }
1468 manifest_version_ = manifest_version;
Aaron Boodman 2011/11/17 07:10:15 Should we do something about manifest version > 2
1469 } else {
1470 // Version 1 was the original version, which lacked a version indicator.
1471 manifest_version_ = 1;
1472 }
1473
1457 if (source.HasKey(keys::kPublicKey)) { 1474 if (source.HasKey(keys::kPublicKey)) {
1458 std::string public_key_bytes; 1475 std::string public_key_bytes;
1459 if (!source.GetString(keys::kPublicKey, 1476 if (!source.GetString(keys::kPublicKey,
1460 &public_key_) || 1477 &public_key_) ||
1461 !ParsePEMKeyBytes(public_key_, 1478 !ParsePEMKeyBytes(public_key_,
1462 &public_key_bytes) || 1479 &public_key_bytes) ||
1463 !GenerateId(public_key_bytes, &id_)) { 1480 !GenerateId(public_key_bytes, &id_)) {
1464 *error = errors::kInvalidKey; 1481 *error = errors::kInvalidKey;
1465 return false; 1482 return false;
1466 } 1483 }
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 // We block these characters to prevent HTTP header injection when 2227 // We block these characters to prevent HTTP header injection when
2211 // representing the content security policy as an HTTP header. 2228 // representing the content security policy as an HTTP header.
2212 const char kBadCSPCharacters[] = {'\r', '\n', '\0'}; 2229 const char kBadCSPCharacters[] = {'\r', '\n', '\0'};
2213 if (content_security_policy.find_first_of(kBadCSPCharacters, 0, 2230 if (content_security_policy.find_first_of(kBadCSPCharacters, 0,
2214 arraysize(kBadCSPCharacters)) != 2231 arraysize(kBadCSPCharacters)) !=
2215 std::string::npos) { 2232 std::string::npos) {
2216 *error = errors::kInvalidContentSecurityPolicy; 2233 *error = errors::kInvalidContentSecurityPolicy;
2217 return false; 2234 return false;
2218 } 2235 }
2219 content_security_policy_ = content_security_policy; 2236 content_security_policy_ = content_security_policy;
2237 } else if (manifest_version_ >= 2) {
2238 // Manifest version 2 introduced a default Content-Security-Policy.
2239 // TODO(abarth): Should we continue to let extensions override the
2240 // default Content-Security-Policy?
2241 content_security_policy_ = kDefaultContentSecurityPolicy;
2220 } 2242 }
2221 2243
2222 // Initialize devtools page url (optional). 2244 // Initialize devtools page url (optional).
2223 if (source.HasKey(keys::kDevToolsPage)) { 2245 if (source.HasKey(keys::kDevToolsPage)) {
2224 std::string devtools_str; 2246 std::string devtools_str;
2225 if (!source.GetString(keys::kDevToolsPage, &devtools_str)) { 2247 if (!source.GetString(keys::kDevToolsPage, &devtools_str)) {
2226 *error = errors::kInvalidDevToolsPage; 2248 *error = errors::kInvalidDevToolsPage;
2227 return false; 2249 return false;
2228 } 2250 }
2229 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { 2251 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) {
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 already_disabled(false), 3052 already_disabled(false),
3031 extension(extension) {} 3053 extension(extension) {}
3032 3054
3033 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3055 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3034 const Extension* extension, 3056 const Extension* extension,
3035 const ExtensionPermissionSet* permissions, 3057 const ExtensionPermissionSet* permissions,
3036 Reason reason) 3058 Reason reason)
3037 : reason(reason), 3059 : reason(reason),
3038 extension(extension), 3060 extension(extension),
3039 permissions(permissions) {} 3061 permissions(permissions) {}
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698