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

Unified Diff: net/url_request/url_request_http_job.cc

Issue 2546213003: Implement net/ support for Android's NetworkSecurityPolicy (Closed)
Patch Set: Address comments and add test Created 4 years 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_context.cc ('k') | net/url_request/url_request_http_job_unittest.cc » ('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 5f2fd91d6cc266ec923c49e6dad4e3191c255d51..c4230fa8c8c24f9e58234c725d84369f9cebf7d6 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -67,6 +67,10 @@
#include "net/websockets/websocket_handshake_stream_base.h"
#include "url/origin.h"
+#if defined(OS_ANDROID)
+#include "net/android/network_library.h"
+#endif
+
static const char kAvailDictionaryHeader[] = "Avail-Dictionary";
namespace {
@@ -168,25 +172,41 @@ void LogChannelIDAndCookieStores(const GURL& url,
EPHEMERALITY_MAX);
}
-net::URLRequestRedirectJob* MaybeInternallyRedirect(
+// Checks for reasons not to return a URLRequestHttpJob, and if one is found,
+// returns a URLRequestRedirectJob or URLRequestErrorJob as necessary.
+net::URLRequestJob* MaybeInternallyRedirectOrFail(
mmenke 2016/12/13 18:39:14 I think this does enough weird stuff that we shoul
mgersh 2016/12/13 19:01:58 Done.
net::URLRequest* request,
net::NetworkDelegate* network_delegate) {
const GURL& url = request->url();
+
+ // Neither check applies to https and wss requests
mmenke 2016/12/13 18:39:14 nit: End these comments with periods.
mgersh 2016/12/13 19:01:58 Done.
if (url.SchemeIsCryptographic())
return nullptr;
+ // Check for HSTS upgrade
net::TransportSecurityState* hsts =
request->context()->transport_security_state();
- if (!hsts || !hsts->ShouldUpgradeToSSL(url.host()))
- return nullptr;
+ if (hsts && hsts->ShouldUpgradeToSSL(url.host())) {
+ GURL::Replacements replacements;
+ replacements.SetSchemeStr(url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme
+ : url::kWssScheme);
+ return new net::URLRequestRedirectJob(
+ request, network_delegate, url.ReplaceComponents(replacements),
+ // Use status code 307 to preserve the method, so POST requests work.
+ net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS");
+ }
+
+#if defined(OS_ANDROID)
+ // Check whether the app allows cleartext traffic to this host, and return
+ // ERR_BLOCKED_BY_CLIENT if not
+ if (request->context()->check_cleartext_permitted() &&
+ !net::android::IsCleartextPermitted(url.host())) {
+ return new net::URLRequestErrorJob(request, network_delegate,
+ net::ERR_BLOCKED_BY_CLIENT);
+ }
+#endif
- GURL::Replacements replacements;
- replacements.SetSchemeStr(url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme
- : url::kWssScheme);
- return new net::URLRequestRedirectJob(
- request, network_delegate, url.ReplaceComponents(replacements),
- // Use status code 307 to preserve the method, so POST requests work.
- net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS");
+ return nullptr;
}
} // namespace
@@ -207,10 +227,10 @@ URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
request, network_delegate, ERR_INVALID_ARGUMENT);
}
- URLRequestRedirectJob* redirect =
- MaybeInternallyRedirect(request, network_delegate);
- if (redirect)
- return redirect;
+ URLRequestJob* redirect_or_error =
+ MaybeInternallyRedirectOrFail(request, network_delegate);
+ if (redirect_or_error)
+ return redirect_or_error;
return new URLRequestHttpJob(request,
network_delegate,
« no previous file with comments | « net/url_request/url_request_context.cc ('k') | net/url_request/url_request_http_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698