Commit e08d933e authored by Lucas Furukawa Gadani's avatar Lucas Furukawa Gadani Committed by Commit Bot

Do not resolve tokens from the report-to CSP directive as relative URLs.

Bug: 759184
Change-Id: I920cfba1b382c13982531fadb5632dec5b8329f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1942708
Commit-Queue: Lucas Gadani <lfg@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720501}
parent 192d8c7a
...@@ -274,6 +274,7 @@ mojom::CSPSourceListPtr ParseFrameAncestorsSourceList( ...@@ -274,6 +274,7 @@ mojom::CSPSourceListPtr ParseFrameAncestorsSourceList(
// https://crbug.com/916265. // https://crbug.com/916265.
bool ParseReportDirective(const GURL& request_url, bool ParseReportDirective(const GURL& request_url,
base::StringPiece value, base::StringPiece value,
bool using_reporting_api,
std::vector<std::string>* report_endpoints) { std::vector<std::string>* report_endpoints) {
for (const auto& uri : base::SplitStringPiece( for (const auto& uri : base::SplitStringPiece(
value, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { value, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
...@@ -285,14 +286,15 @@ bool ParseReportDirective(const GURL& request_url, ...@@ -285,14 +286,15 @@ bool ParseReportDirective(const GURL& request_url,
// - "report-to (endpoint)+" // - "report-to (endpoint)+"
// |endpoint| is an arbitrary string. It refers to an endpoint declared in // |endpoint| is an arbitrary string. It refers to an endpoint declared in
// the "Report-To" header. See https://w3c.github.io/reporting // the "Report-To" header. See https://w3c.github.io/reporting
// if (using_reporting_api) {
// TODO(lfg): The |endpoint| for the 'report-to' directive shouldn't be report_endpoints->push_back(uri.as_string());
// resolved. } else {
GURL url = request_url.Resolve(uri); GURL url = request_url.Resolve(uri);
if (!url.is_valid()) if (!url.is_valid())
return false; return false;
report_endpoints->push_back(url.spec()); report_endpoints->push_back(url.spec());
}
} }
return true; return true;
} }
...@@ -372,7 +374,9 @@ bool ContentSecurityPolicy::Parse(const GURL& base_url, ...@@ -372,7 +374,9 @@ bool ContentSecurityPolicy::Parse(const GURL& base_url,
} }
if (report_endpoints != directives.end()) { if (report_endpoints != directives.end()) {
if (!ParseReportEndpoint(base_url, report_endpoints->second)) { if (!ParseReportEndpoint(
base_url, report_endpoints->second,
content_security_policy_ptr_->use_reporting_api)) {
content_security_policy_ptr_.reset(); content_security_policy_ptr_.reset();
return false; return false;
} }
...@@ -406,16 +410,16 @@ bool ContentSecurityPolicy::ParseFrameAncestors( ...@@ -406,16 +410,16 @@ bool ContentSecurityPolicy::ParseFrameAncestors(
return true; return true;
} }
bool ContentSecurityPolicy::ParseReportEndpoint( bool ContentSecurityPolicy::ParseReportEndpoint(const GURL& base_url,
const GURL& base_url, base::StringPiece header_value,
base::StringPiece header_value) { bool using_reporting_api) {
// A report-uri directive has already been parsed. Skip further directives per // A report-uri directive has already been parsed. Skip further directives per
// https://www.w3.org/TR/CSP3/#parse-serialized-policy. // https://www.w3.org/TR/CSP3/#parse-serialized-policy.
if (!content_security_policy_ptr_->report_endpoints.empty()) if (!content_security_policy_ptr_->report_endpoints.empty())
return true; return true;
if (!ParseReportDirective( if (!ParseReportDirective(
base_url, header_value, base_url, header_value, using_reporting_api,
&(content_security_policy_ptr_->report_endpoints))) { &(content_security_policy_ptr_->report_endpoints))) {
// TODO(lfg): Emit a warning to the user when parsing an invalid // TODO(lfg): Emit a warning to the user when parsing an invalid
// expression. // expression.
......
...@@ -56,7 +56,8 @@ class COMPONENT_EXPORT(NETWORK_CPP) ContentSecurityPolicy { ...@@ -56,7 +56,8 @@ class COMPONENT_EXPORT(NETWORK_CPP) ContentSecurityPolicy {
// Parses the report-uri directive of a Content-Security-Policy header. // Parses the report-uri directive of a Content-Security-Policy header.
bool ParseReportEndpoint(const GURL& base_url, bool ParseReportEndpoint(const GURL& base_url,
base::StringPiece header_value); base::StringPiece header_value,
bool using_reporting_api);
mojom::ContentSecurityPolicyPtr content_security_policy_ptr_; mojom::ContentSecurityPolicyPtr content_security_policy_ptr_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment