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 26 matching lines...) Expand all Loading... | |
| 37 return url.spec(); | 37 return url.spec(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void ReportViolation(CSPContext* context, | 40 void ReportViolation(CSPContext* context, |
| 41 const ContentSecurityPolicy& policy, | 41 const ContentSecurityPolicy& policy, |
| 42 const CSPDirective& directive, | 42 const CSPDirective& directive, |
| 43 const CSPDirective::Name directive_name, | 43 const CSPDirective::Name directive_name, |
| 44 const GURL& url, | 44 const GURL& url, |
| 45 bool is_redirect, | 45 bool is_redirect, |
| 46 const SourceLocation& source_location) { | 46 const SourceLocation& source_location) { |
| 47 // For security reasons, some urls must not be disclosed. It includes the | |
| 48 // blocked url and the source location of the error. Care must be taken to | |
| 49 // ensure that these information are not transmitted between different | |
|
alexmos
2017/05/12 01:37:20
nit: "these information are" -> "these are" (or "t
arthursonzogni
2017/05/15 12:20:46
Done.
| |
| 50 // cross-origin renderers. | |
|
alexmos
2017/05/12 01:37:20
Perhaps also include a reference to https://crbug.
arthursonzogni
2017/05/15 12:20:46
Done (In RenderFrameHostImpl::SanitizeDataForUseIn
| |
| 51 GURL safe_url = context->ShouldProtectDataInCspViolation(url::Origin(url)) | |
| 52 ? url.GetOrigin() | |
| 53 : url; | |
|
Mike West
2017/05/12 14:16:44
I think we can skip this if |is_redirect| is false
arthursonzogni
2017/05/15 12:20:46
For form-action: I think you are right.
For frame-
alexmos
2017/05/16 05:56:48
Ack - I think that makes sense to me. Mike, do yo
| |
| 54 | |
| 55 url::Origin source_location_origin(GURL(source_location.url)); | |
| 56 SourceLocation safe_source_location = | |
| 57 context->ShouldProtectDataInCspViolation(source_location_origin) | |
| 58 ? SourceLocation(source_location_origin.Serialize(), 0u, 0u) | |
| 59 : source_location; | |
| 60 | |
| 47 // We should never have a violation against `child-src` or `default-src` | 61 // We should never have a violation against `child-src` or `default-src` |
| 48 // directly; the effective directive should always be one of the explicit | 62 // directly; the effective directive should always be one of the explicit |
| 49 // fetch directives. | 63 // fetch directives. |
| 50 DCHECK_NE(directive_name, CSPDirective::DefaultSrc); | 64 DCHECK_NE(directive_name, CSPDirective::DefaultSrc); |
| 51 DCHECK_NE(directive_name, CSPDirective::ChildSrc); | 65 DCHECK_NE(directive_name, CSPDirective::ChildSrc); |
| 52 | 66 |
| 53 std::stringstream message; | 67 std::stringstream message; |
| 54 | 68 |
| 55 if (policy.header.type == blink::kWebContentSecurityPolicyTypeReport) | 69 if (policy.header.type == blink::kWebContentSecurityPolicyTypeReport) |
| 56 message << "[Report Only] "; | 70 message << "[Report Only] "; |
| 57 | 71 |
| 58 if (directive_name == CSPDirective::FormAction) | 72 if (directive_name == CSPDirective::FormAction) |
| 59 message << "Refused to send form data to '"; | 73 message << "Refused to send form data to '"; |
| 60 else if (directive_name == CSPDirective::FrameSrc) | 74 else if (directive_name == CSPDirective::FrameSrc) |
| 61 message << "Refused to frame '"; | 75 message << "Refused to frame '"; |
| 62 | 76 |
| 63 message << ElideURLForReportViolation(url) | 77 message << ElideURLForReportViolation(safe_url) |
| 64 << "' because it violates the following Content Security Policy " | 78 << "' because it violates the following Content Security Policy " |
| 65 "directive: \"" | 79 "directive: \"" |
| 66 << directive.ToString() << "\"."; | 80 << directive.ToString() << "\"."; |
| 67 | 81 |
| 68 if (directive.name != directive_name) | 82 if (directive.name != directive_name) |
| 69 message << " Note that '" << CSPDirective::NameToString(directive_name) | 83 message << " Note that '" << CSPDirective::NameToString(directive_name) |
| 70 << "' was not explicitly set, so '" | 84 << "' was not explicitly set, so '" |
| 71 << CSPDirective::NameToString(directive.name) | 85 << CSPDirective::NameToString(directive.name) |
| 72 << "' is used as a fallback."; | 86 << "' is used as a fallback."; |
| 73 | 87 |
| 74 message << "\n"; | 88 message << "\n"; |
| 75 | 89 |
| 76 context->ReportContentSecurityPolicyViolation(CSPViolationParams( | 90 context->ReportContentSecurityPolicyViolation(CSPViolationParams( |
| 77 CSPDirective::NameToString(directive.name), | 91 CSPDirective::NameToString(directive.name), |
| 78 CSPDirective::NameToString(directive_name), message.str(), url, | 92 CSPDirective::NameToString(directive_name), message.str(), safe_url, |
| 79 policy.report_endpoints, policy.header.header_value, policy.header.type, | 93 policy.report_endpoints, policy.header.header_value, policy.header.type, |
| 80 is_redirect, source_location)); | 94 is_redirect, safe_source_location)); |
| 81 } | 95 } |
| 82 | 96 |
| 83 bool AllowDirective(CSPContext* context, | 97 bool AllowDirective(CSPContext* context, |
| 84 const ContentSecurityPolicy& policy, | 98 const ContentSecurityPolicy& policy, |
| 85 const CSPDirective& directive, | 99 const CSPDirective& directive, |
| 86 CSPDirective::Name directive_name, | 100 CSPDirective::Name directive_name, |
| 87 const GURL& url, | 101 const GURL& url, |
| 88 bool is_redirect, | 102 bool is_redirect, |
| 89 const SourceLocation& source_location) { | 103 const SourceLocation& source_location) { |
| 90 if (CSPSourceList::Allow(directive.source_list, url, context, is_redirect)) | 104 if (CSPSourceList::Allow(directive.source_list, url, context, is_redirect)) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 is_first_policy = false; | 185 is_first_policy = false; |
| 172 text << "report-uri"; | 186 text << "report-uri"; |
| 173 for (const std::string& endpoint : report_endpoints) | 187 for (const std::string& endpoint : report_endpoints) |
| 174 text << " " << endpoint; | 188 text << " " << endpoint; |
| 175 } | 189 } |
| 176 | 190 |
| 177 return text.str(); | 191 return text.str(); |
| 178 } | 192 } |
| 179 | 193 |
| 180 } // namespace content | 194 } // namespace content |
| OLD | NEW |