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 GURL safe_url = context->IsOriginSafeToUseInCspViolation(url::Origin(url)) | |
alexmos
2017/05/10 22:33:08
It feels like we actually want to ask this questio
arthursonzogni
2017/05/11 13:06:23
Yes, that is what I did initially. But even if the
alexmos
2017/05/12 01:37:19
Yeah, it's hard, and I guess it also depends on wh
arthursonzogni
2017/05/15 12:20:46
Thanks for "ShouldSanitizeDataInCspViolation".
I w
| |
48 ? url | |
49 : url.GetOrigin(); | |
alexmos
2017/05/10 22:33:08
Both of these checks could use a comment explainin
arthursonzogni
2017/05/11 13:06:23
Done.
| |
50 | |
51 SourceLocation safe_source_location = | |
52 context->IsOriginSafeToUseInCspViolation( | |
53 url::Origin(GURL(source_location.url))) | |
54 ? source_location | |
55 : SourceLocation(); | |
alexmos
2017/05/10 22:33:08
Interesting, so we clear it out entirely? This do
arthursonzogni
2017/05/11 13:06:23
I think we have to clear the line/column numbers b
alexmos
2017/05/12 01:37:19
I'll leave this up to Mike. I agree it seems more
| |
56 | |
47 // We should never have a violation against `child-src` or `default-src` | 57 // We should never have a violation against `child-src` or `default-src` |
48 // directly; the effective directive should always be one of the explicit | 58 // directly; the effective directive should always be one of the explicit |
49 // fetch directives. | 59 // fetch directives. |
50 DCHECK_NE(directive_name, CSPDirective::DefaultSrc); | 60 DCHECK_NE(directive_name, CSPDirective::DefaultSrc); |
51 DCHECK_NE(directive_name, CSPDirective::ChildSrc); | 61 DCHECK_NE(directive_name, CSPDirective::ChildSrc); |
52 | 62 |
53 std::stringstream message; | 63 std::stringstream message; |
54 | 64 |
55 if (policy.header.type == blink::kWebContentSecurityPolicyTypeReport) | 65 if (policy.header.type == blink::kWebContentSecurityPolicyTypeReport) |
56 message << "[Report Only] "; | 66 message << "[Report Only] "; |
57 | 67 |
58 if (directive_name == CSPDirective::FormAction) | 68 if (directive_name == CSPDirective::FormAction) |
59 message << "Refused to send form data to '"; | 69 message << "Refused to send form data to '"; |
60 else if (directive_name == CSPDirective::FrameSrc) | 70 else if (directive_name == CSPDirective::FrameSrc) |
61 message << "Refused to frame '"; | 71 message << "Refused to frame '"; |
62 | 72 |
63 message << ElideURLForReportViolation(url) | 73 message << ElideURLForReportViolation(safe_url) |
64 << "' because it violates the following Content Security Policy " | 74 << "' because it violates the following Content Security Policy " |
65 "directive: \"" | 75 "directive: \"" |
66 << directive.ToString() << "\"."; | 76 << directive.ToString() << "\"."; |
67 | 77 |
68 if (directive.name != directive_name) | 78 if (directive.name != directive_name) |
69 message << " Note that '" << CSPDirective::NameToString(directive_name) | 79 message << " Note that '" << CSPDirective::NameToString(directive_name) |
70 << "' was not explicitly set, so '" | 80 << "' was not explicitly set, so '" |
71 << CSPDirective::NameToString(directive.name) | 81 << CSPDirective::NameToString(directive.name) |
72 << "' is used as a fallback."; | 82 << "' is used as a fallback."; |
73 | 83 |
74 message << "\n"; | 84 message << "\n"; |
75 | 85 |
76 context->ReportContentSecurityPolicyViolation(CSPViolationParams( | 86 context->ReportContentSecurityPolicyViolation(CSPViolationParams( |
77 CSPDirective::NameToString(directive.name), | 87 CSPDirective::NameToString(directive.name), |
78 CSPDirective::NameToString(directive_name), message.str(), url, | 88 CSPDirective::NameToString(directive_name), message.str(), safe_url, |
79 policy.report_endpoints, policy.header.header_value, policy.header.type, | 89 policy.report_endpoints, policy.header.header_value, policy.header.type, |
80 is_redirect, source_location)); | 90 is_redirect, safe_source_location)); |
81 } | 91 } |
82 | 92 |
83 bool AllowDirective(CSPContext* context, | 93 bool AllowDirective(CSPContext* context, |
84 const ContentSecurityPolicy& policy, | 94 const ContentSecurityPolicy& policy, |
85 const CSPDirective& directive, | 95 const CSPDirective& directive, |
86 CSPDirective::Name directive_name, | 96 CSPDirective::Name directive_name, |
87 const GURL& url, | 97 const GURL& url, |
88 bool is_redirect, | 98 bool is_redirect, |
89 const SourceLocation& source_location) { | 99 const SourceLocation& source_location) { |
90 if (CSPSourceList::Allow(directive.source_list, url, context, is_redirect)) | 100 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; | 181 is_first_policy = false; |
172 text << "report-uri"; | 182 text << "report-uri"; |
173 for (const std::string& endpoint : report_endpoints) | 183 for (const std::string& endpoint : report_endpoints) |
174 text << " " << endpoint; | 184 text << " " << endpoint; |
175 } | 185 } |
176 | 186 |
177 return text.str(); | 187 return text.str(); |
178 } | 188 } |
179 | 189 |
180 } // namespace content | 190 } // namespace content |
OLD | NEW |