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

Unified Diff: content/common/content_security_policy/csp_context.cc

Issue 2910573002: Implement upgrade-insecure-requests in browser for frame requests (Closed)
Patch Set: rebase Created 3 years, 6 months 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: content/common/content_security_policy/csp_context.cc
diff --git a/content/common/content_security_policy/csp_context.cc b/content/common/content_security_policy/csp_context.cc
index 194a8a19811bf9be020efb38fce3386aee4b8289..7d3aebef25f725802028d35f7523ead03853c05d 100644
--- a/content/common/content_security_policy/csp_context.cc
+++ b/content/common/content_security_policy/csp_context.cc
@@ -6,6 +6,26 @@
namespace content {
+namespace {
+
+// Helper function that returns true if |policy| should be checked under
+// |check_csp_disposition|.
+bool ShouldCheckPolicy(const ContentSecurityPolicy& policy,
+ CSPContext::CheckCSPDisposition check_csp_disposition) {
+ switch (check_csp_disposition) {
+ case CSPContext::CHECK_REPORT_ONLY_CSP:
+ return policy.header.type == blink::kWebContentSecurityPolicyTypeReport;
+ case CSPContext::CHECK_ENFORCED_CSP:
+ return policy.header.type == blink::kWebContentSecurityPolicyTypeEnforce;
+ case CSPContext::CHECK_ALL_CSP:
+ return true;
+ }
+ NOTREACHED();
+ return true;
+}
+
+} // namespace
+
CSPContext::CSPContext() : has_self_(false) {}
CSPContext::~CSPContext() {}
@@ -13,18 +33,41 @@ CSPContext::~CSPContext() {}
bool CSPContext::IsAllowedByCsp(CSPDirective::Name directive_name,
const GURL& url,
bool is_redirect,
- const SourceLocation& source_location) {
+ const SourceLocation& source_location,
+ CheckCSPDisposition check_csp_disposition) {
if (SchemeShouldBypassCSP(url.scheme_piece()))
return true;
bool allow = true;
for (const auto& policy : policies_) {
- allow &= ContentSecurityPolicy::Allow(policy, directive_name, url,
- is_redirect, this, source_location);
+ if (ShouldCheckPolicy(policy, check_csp_disposition)) {
+ allow &= ContentSecurityPolicy::Allow(policy, directive_name, url,
+ is_redirect, this, source_location);
+ }
}
return allow;
}
+bool CSPContext::ShouldModifyRequestUrlForCsp(
+ const GURL& url,
+ bool is_subresource_or_form_submission,
+ GURL* new_url) {
+ for (const auto& policy : policies_) {
+ if (url.scheme() == "http" &&
+ ContentSecurityPolicy::ShouldUpgradeInsecureRequest(policy) &&
+ is_subresource_or_form_submission) {
+ *new_url = url;
+ GURL::Replacements replacements;
+ replacements.SetSchemeStr("https");
+ if (url.port() == "80")
+ replacements.SetPortStr("443");
+ *new_url = new_url->ReplaceComponents(replacements);
+ return true;
+ }
+ }
+ return false;
+}
+
void CSPContext::SetSelf(const url::Origin origin) {
if (origin.unique()) {
// TODO(arthursonzogni): Decide what to do with unique origins.
« no previous file with comments | « content/common/content_security_policy/csp_context.h ('k') | content/common/content_security_policy/csp_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698