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

Unified Diff: chrome/common/extensions/extension.cc

Issue 8773028: Allow extenions to override the default content_security_policy, but require (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension.cc
===================================================================
--- chrome/common/extensions/extension.cc (revision 112565)
+++ chrome/common/extensions/extension.cc (working copy)
@@ -25,6 +25,7 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
+#include "chrome/common/extensions/csp_validator.h"
#include "chrome/common/extensions/extension_action.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_error_utils.h"
@@ -50,6 +51,9 @@
namespace values = extension_manifest_values;
namespace errors = extension_manifest_errors;
+using extensions::csp_validator::ContentSecurityPolicyIsLegal;
+using extensions::csp_validator::ContentSecurityPolicyIsSecure;
+
namespace {
const int kModernManifestVersion = 1;
@@ -2240,21 +2244,23 @@
*error = errors::kInvalidContentSecurityPolicy;
return false;
}
- // We block these characters to prevent HTTP header injection when
- // representing the content security policy as an HTTP header.
- const char kBadCSPCharacters[] = {'\r', '\n', '\0'};
- if (content_security_policy.find_first_of(kBadCSPCharacters, 0,
- arraysize(kBadCSPCharacters)) !=
- std::string::npos) {
+ if (!ContentSecurityPolicyIsLegal(content_security_policy)) {
*error = errors::kInvalidContentSecurityPolicy;
return false;
}
+ if (manifest_version_ >= 2 &&
+ !ContentSecurityPolicyIsSecure(content_security_policy)) {
+ *error = errors::kInvalidContentSecurityPolicy;
+ return false;
+ }
+
content_security_policy_ = content_security_policy;
} else if (manifest_version_ >= 2) {
// Manifest version 2 introduced a default Content-Security-Policy.
// TODO(abarth): Should we continue to let extensions override the
// default Content-Security-Policy?
content_security_policy_ = kDefaultContentSecurityPolicy;
+ CHECK(ContentSecurityPolicyIsSecure(content_security_policy_));
}
// Initialize devtools page url (optional).

Powered by Google App Engine
This is Rietveld 408576698