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

Unified Diff: content/browser/frame_host/navigation_request.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/browser/frame_host/navigation_request.cc
diff --git a/content/browser/frame_host/navigation_request.cc b/content/browser/frame_host/navigation_request.cc
index dee3a58b6062ec0d4149f9987fbe643216bec222..0032db2aa93c93fff0d773833216f7824be6d819 100644
--- a/content/browser/frame_host/navigation_request.cc
+++ b/content/browser/frame_host/navigation_request.cc
@@ -943,9 +943,43 @@ NavigationRequest::CheckContentSecurityPolicyFrameSrc(bool is_redirect) {
RenderFrameHostImpl* parent = parent_ftn->current_frame_host();
DCHECK(parent);
+ // CSP checking happens in three phases, per steps 3-5 of
+ // https://fetch.spec.whatwg.org/#main-fetch:
+ //
+ // (1) Check report-only policies and trigger reports for any violations.
+ // (2) Upgrade the request to HTTPS if necessary.
+ // (3) Check enforced policies (triggering reports for any violations of those
+ // policies) and block the request if necessary.
+ //
+ // This sequence of events allows site owners to learn about (via step 1) any
+ // requests that are upgraded in step 2.
+
+ bool allowed = parent->IsAllowedByCsp(
+ CSPDirective::FrameSrc, common_params_.url, is_redirect,
+ common_params_.source_location.value_or(SourceLocation()),
+ CSPContext::CHECK_REPORT_ONLY_CSP);
+
+ // Checking report-only CSP should never return false because no requests are
+ // blocked by report-only policies.
+ DCHECK(allowed);
+
+ // TODO(mkwst,estark): upgrade-insecure-requests does not work when following
+ // redirects. Trying to uprade the new URL on redirect here is fruitless: the
+ // redirect URL cannot be changed at this point. upgrade-insecure-requests
+ // needs to move to the net stack to resolve this. https://crbug.com/615885
+ if (!is_redirect) {
+ GURL new_url;
+ if (parent->ShouldModifyRequestUrlForCsp(
+ common_params_.url, true /* is subresource */, &new_url)) {
+ common_params_.url = new_url;
+ request_params_.original_url = new_url;
+ }
+ }
+
if (parent->IsAllowedByCsp(
CSPDirective::FrameSrc, common_params_.url, is_redirect,
- common_params_.source_location.value_or(SourceLocation()))) {
+ common_params_.source_location.value_or(SourceLocation()),
+ CSPContext::CHECK_ENFORCED_CSP)) {
return CONTENT_SECURITY_POLICY_CHECK_PASSED;
}

Powered by Google App Engine
This is Rietveld 408576698