Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <sstream> | 5 #include <sstream> |
| 6 #include "base/strings/string_split.h" | 6 #include "base/strings/string_split.h" |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "content/common/content_security_policy/csp_context.h" | 8 #include "content/common/content_security_policy/csp_context.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 const GURL& url, | 87 const GURL& url, |
| 88 bool is_redirect, | 88 bool is_redirect, |
| 89 const SourceLocation& source_location) { | 89 const SourceLocation& source_location) { |
| 90 if (CSPSourceList::Allow(directive.source_list, url, context, is_redirect)) | 90 if (CSPSourceList::Allow(directive.source_list, url, context, is_redirect)) |
| 91 return true; | 91 return true; |
| 92 | 92 |
| 93 ReportViolation(context, policy, directive, directive_name, url, is_redirect, | 93 ReportViolation(context, policy, directive, directive_name, url, is_redirect, |
| 94 source_location); | 94 source_location); |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 const GURL ExtractInnerURL(const GURL& url) { | |
|
arthursonzogni
2017/04/04 11:54:34
Nit: Add a newline above.
andypaicu
2017/04/04 15:10:07
Done
| |
| 98 if (const GURL* inner_url = url.inner_url()) | |
| 99 return *inner_url; | |
| 100 else | |
| 101 // TODO(arthursonzogni): revisit this once GURL::inner_url support blob-URL. | |
| 102 return GURL(url.path()); | |
| 103 } | |
| 104 | |
| 105 bool ShouldBypassContentSecurityPolicy(CSPContext* context, const GURL& url) { | |
| 106 if (url.SchemeIsFileSystem() || url.SchemeIsBlob()) { | |
| 107 return context->SchemeShouldBypassCSP(ExtractInnerURL(url).scheme()); | |
| 108 } else { | |
| 109 return context->SchemeShouldBypassCSP(url.scheme()); | |
| 110 } | |
| 111 } | |
| 97 | 112 |
| 98 } // namespace | 113 } // namespace |
| 99 | 114 |
| 100 ContentSecurityPolicy::ContentSecurityPolicy() | 115 ContentSecurityPolicy::ContentSecurityPolicy() |
| 101 : header(std::string(), | 116 : header(std::string(), |
| 102 blink::WebContentSecurityPolicyTypeEnforce, | 117 blink::WebContentSecurityPolicyTypeEnforce, |
| 103 blink::WebContentSecurityPolicySourceHTTP) {} | 118 blink::WebContentSecurityPolicySourceHTTP) {} |
| 104 | 119 |
| 105 ContentSecurityPolicy::ContentSecurityPolicy( | 120 ContentSecurityPolicy::ContentSecurityPolicy( |
| 106 const ContentSecurityPolicyHeader& header, | 121 const ContentSecurityPolicyHeader& header, |
| 107 const std::vector<CSPDirective>& directives, | 122 const std::vector<CSPDirective>& directives, |
| 108 const std::vector<std::string>& report_endpoints) | 123 const std::vector<std::string>& report_endpoints) |
| 109 : header(header), | 124 : header(header), |
| 110 directives(directives), | 125 directives(directives), |
| 111 report_endpoints(report_endpoints) {} | 126 report_endpoints(report_endpoints) {} |
| 112 | 127 |
| 113 ContentSecurityPolicy::ContentSecurityPolicy(const ContentSecurityPolicy&) = | 128 ContentSecurityPolicy::ContentSecurityPolicy(const ContentSecurityPolicy&) = |
| 114 default; | 129 default; |
| 115 ContentSecurityPolicy::~ContentSecurityPolicy() = default; | 130 ContentSecurityPolicy::~ContentSecurityPolicy() = default; |
| 116 | 131 |
| 117 // static | 132 // static |
| 118 bool ContentSecurityPolicy::Allow(const ContentSecurityPolicy& policy, | 133 bool ContentSecurityPolicy::Allow(const ContentSecurityPolicy& policy, |
| 119 CSPDirective::Name directive_name, | 134 CSPDirective::Name directive_name, |
| 120 const GURL& url, | 135 const GURL& url, |
| 121 bool is_redirect, | 136 bool is_redirect, |
| 122 CSPContext* context, | 137 CSPContext* context, |
| 123 const SourceLocation& source_location) { | 138 const SourceLocation& source_location) { |
| 139 if (ShouldBypassContentSecurityPolicy(context, url)) | |
| 140 return true; | |
| 141 | |
| 124 CSPDirective::Name current_directive_name = directive_name; | 142 CSPDirective::Name current_directive_name = directive_name; |
| 125 do { | 143 do { |
| 126 for (const CSPDirective& directive : policy.directives) { | 144 for (const CSPDirective& directive : policy.directives) { |
| 127 if (directive.name == current_directive_name) { | 145 if (directive.name == current_directive_name) { |
| 128 bool allowed = | 146 bool allowed = |
| 129 AllowDirective(context, policy, directive, directive_name, url, | 147 AllowDirective(context, policy, directive, directive_name, url, |
| 130 is_redirect, source_location); | 148 is_redirect, source_location); |
| 131 return allowed || | 149 return allowed || |
| 132 policy.header.type == blink::WebContentSecurityPolicyTypeReport; | 150 policy.header.type == blink::WebContentSecurityPolicyTypeReport; |
| 133 } | 151 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 153 is_first_policy = false; | 171 is_first_policy = false; |
| 154 text << "report-uri"; | 172 text << "report-uri"; |
| 155 for (const std::string& endpoint : report_endpoints) | 173 for (const std::string& endpoint : report_endpoints) |
| 156 text << " " << endpoint; | 174 text << " " << endpoint; |
| 157 } | 175 } |
| 158 | 176 |
| 159 return text.str(); | 177 return text.str(); |
| 160 } | 178 } |
| 161 | 179 |
| 162 } // namespace content | 180 } // namespace content |
| OLD | NEW |