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

Unified Diff: net/url_request/url_request_http_job.cc

Issue 2053693002: WIP: Move 'Upgrade-Insecure-Requests' to the browser process. Base URL: https://chromium.googlesource.com/chromium/src.git@replicate
Patch Set: Rebase. :( Created 3 years, 10 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
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_job.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_http_job.cc
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index b3053b24325a37a5a659adab66e0f56c65c0cc92..c8c492f542c4b3e765f6b05304be35d906d3b44c 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -1131,6 +1131,41 @@ std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() {
return upstream;
}
+RedirectInfo URLRequestHttpJob::ComputeRedirectInfo(const GURL& location,
+ int http_status_code) {
+ // If |request|'s insecure request policy matches its URL, then upgrade it
+ // from a non-secure protocol to a secure protocol (e.g. "http" => "https").
+ // See https://www.w3.org/TR/upgrade-insecure-requests/ for details.
+ //
+ // TODO(mkwst): HSTS is currently modeled as a redirect, which makes sense,
+ // given the web-exposed behavior developers currently rely upon. At some
+ // point, however, https://wicg.github.io/hsts-priming/ will change that
+ // expectation. Once those changes are in place, it might make sense to
+ // merge the HSTS logic from 'MaybeInternallyRedirect' into this function.
+ if (request_->insecure_request_policy() ==
+ net::URLRequest::DO_NOT_UPGRADE_INSECURE_REQUESTS ||
+ location.SchemeIsCryptographic() ||
+ (request_->initiator() &&
+ request_->insecure_request_policy() ==
+ net::URLRequest::UPGRADE_SAME_HOST_INSECURE_REQUESTS &&
+ request_->initiator()->host() != location.host())) {
+ return URLRequestJob::ComputeRedirectInfo(location, http_status_code);
+ }
+
+ request_->net_log().AddEvent(
+ NetLogEventType::URL_REQUEST_REWRITTEN,
+ NetLog::StringCallback("reason", "Upgrade-Insecure-Requests"));
+
+ DCHECK(location.SchemeIs(url::kHttpScheme) ||
+ location.SchemeIs(url::kWsScheme));
+ GURL::Replacements replacements;
+ replacements.SetSchemeStr(location.SchemeIs(url::kHttpScheme)
+ ? url::kHttpsScheme
+ : url::kWssScheme);
+ return URLRequestJob::ComputeRedirectInfo(
+ location.ReplaceComponents(replacements), http_status_code);
+}
+
bool URLRequestHttpJob::CopyFragmentOnRedirect(const GURL& location) const {
// Allow modification of reference fragments by default, unless
// |allowed_unsafe_redirect_url_| is set and equal to the redirect URL.
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698