2019-11-14 18:01:18 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2021-02-09 20:16:21 +00:00
|
|
|
From: deepak1556 <hop2deep@gmail.com>
|
|
|
|
Date: Wed, 27 Jan 2021 15:20:01 -0800
|
2019-11-14 18:01:18 +00:00
|
|
|
Subject: add TrustedAuthClient to URLLoaderFactory
|
|
|
|
|
|
|
|
This allows intercepting authentication requests for the 'net' module.
|
|
|
|
Without this, the 'login' event for electron.net.ClientRequest can't be
|
|
|
|
implemented, because the existing path checks for the presence of a
|
|
|
|
WebContents, and cancels the authentication if there's no WebContents
|
|
|
|
available, which there isn't in the case of the 'net' module.
|
|
|
|
|
|
|
|
diff --git a/services/network/public/mojom/network_context.mojom b/services/network/public/mojom/network_context.mojom
|
2021-03-04 17:27:05 +00:00
|
|
|
index 84ab373ac9472bba739ca98c52b1f97c71169e88..0bcc7e95109fea4ff1b25672ac007b926ae52984 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/public/mojom/network_context.mojom
|
|
|
|
+++ b/services/network/public/mojom/network_context.mojom
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -222,6 +222,26 @@ struct CTPolicy {
|
2020-05-26 20:06:26 +00:00
|
|
|
array<string> excluded_legacy_spkis;
|
2019-11-14 18:01:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
+interface TrustedAuthClient {
|
|
|
|
+ OnAuthRequired(
|
|
|
|
+ mojo_base.mojom.UnguessableToken? window_id,
|
|
|
|
+ uint32 process_id,
|
|
|
|
+ uint32 routing_id,
|
|
|
|
+ uint32 request_id,
|
|
|
|
+ url.mojom.Url url,
|
|
|
|
+ bool first_auth_attempt,
|
|
|
|
+ AuthChallengeInfo auth_info,
|
|
|
|
+ URLResponseHead? head,
|
|
|
|
+ pending_remote<AuthChallengeResponder> auth_challenge_responder);
|
|
|
|
+};
|
2021-02-09 20:16:21 +00:00
|
|
|
+
|
2019-11-14 18:01:18 +00:00
|
|
|
+interface TrustedURLLoaderAuthClient {
|
|
|
|
+ // When a new URLLoader is created, this will be called to pass a
|
|
|
|
+ // corresponding |auth_client|.
|
|
|
|
+ OnLoaderCreated(int32 request_id,
|
|
|
|
+ pending_receiver<TrustedAuthClient> auth_client);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
interface CertVerifierClient {
|
|
|
|
Verify(
|
|
|
|
int32 default_error,
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -653,6 +673,8 @@ struct URLLoaderFactoryParams {
|
2020-04-13 23:39:26 +00:00
|
|
|
// impact because of the extra process hops, so use should be minimized.
|
|
|
|
pending_remote<TrustedURLLoaderHeaderClient>? header_client;
|
2019-11-14 18:01:18 +00:00
|
|
|
|
|
|
|
+ pending_remote<TrustedURLLoaderAuthClient>? auth_client;
|
|
|
|
+
|
2021-02-09 20:16:21 +00:00
|
|
|
// Information used restrict access to identity information (like SameSite
|
|
|
|
// cookies) and to shard network resources, like the cache. If set, takes
|
|
|
|
// precedence over ResourceRequest::TrustedParams::IsolationInfo field
|
2019-11-14 18:01:18 +00:00
|
|
|
diff --git a/services/network/url_loader.cc b/services/network/url_loader.cc
|
2021-03-04 17:27:05 +00:00
|
|
|
index a6ea05b42fce15d576c029afa086a3007282ee71..14c17ccbc0e184f03c4ca6a9833ae83db386a011 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader.cc
|
|
|
|
+++ b/services/network/url_loader.cc
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -462,6 +462,7 @@ URLLoader::URLLoader(
|
2019-11-14 18:01:18 +00:00
|
|
|
base::WeakPtr<KeepaliveStatisticsRecorder> keepalive_statistics_recorder,
|
|
|
|
base::WeakPtr<NetworkUsageAccumulator> network_usage_accumulator,
|
|
|
|
mojom::TrustedURLLoaderHeaderClient* url_loader_header_client,
|
|
|
|
+ mojom::TrustedURLLoaderAuthClient* url_loader_auth_client,
|
2020-04-06 20:09:52 +00:00
|
|
|
mojom::OriginPolicyManager* origin_policy_manager,
|
2020-05-26 20:06:26 +00:00
|
|
|
std::unique_ptr<TrustTokenRequestHelperFactory> trust_token_helper_factory,
|
2021-02-09 20:16:21 +00:00
|
|
|
const cors::OriginAccessList& origin_access_list,
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -529,6 +530,11 @@ URLLoader::URLLoader(
|
2019-11-14 18:01:18 +00:00
|
|
|
header_client_.set_disconnect_handler(
|
2019-12-11 00:22:35 +00:00
|
|
|
base::BindOnce(&URLLoader::OnMojoDisconnect, base::Unretained(this)));
|
2019-11-14 18:01:18 +00:00
|
|
|
}
|
|
|
|
+ if (url_loader_auth_client) {
|
|
|
|
+ url_loader_auth_client->OnLoaderCreated(request_id_, auth_client_.BindNewPipeAndPassReceiver());
|
|
|
|
+ auth_client_.set_disconnect_handler(
|
2019-12-11 00:22:35 +00:00
|
|
|
+ base::BindOnce(&URLLoader::OnMojoDisconnect, base::Unretained(this)));
|
2019-11-14 18:01:18 +00:00
|
|
|
+ }
|
|
|
|
if (want_raw_headers_) {
|
|
|
|
options_ |= mojom::kURLLoadOptionSendSSLInfoWithResponse |
|
|
|
|
mojom::kURLLoadOptionSendSSLInfoForCertificateError;
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -1187,7 +1193,7 @@ void URLLoader::OnAuthRequired(net::URLRequest* url_request,
|
2020-06-22 17:35:10 +00:00
|
|
|
// |this| may have been deleted.
|
|
|
|
return;
|
|
|
|
}
|
2019-11-14 18:01:18 +00:00
|
|
|
- if (!network_context_client_) {
|
|
|
|
+ if (!network_context_client_ && !auth_client_) {
|
|
|
|
OnAuthCredentials(base::nullopt);
|
|
|
|
return;
|
|
|
|
}
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -1203,11 +1209,19 @@ void URLLoader::OnAuthRequired(net::URLRequest* url_request,
|
2019-11-14 18:01:18 +00:00
|
|
|
if (url_request->response_headers())
|
2019-12-13 20:13:12 +00:00
|
|
|
head->headers = url_request->response_headers();
|
|
|
|
head->auth_challenge_info = auth_info;
|
2019-11-14 18:01:18 +00:00
|
|
|
- network_context_client_->OnAuthRequired(
|
|
|
|
- fetch_window_id_, factory_params_->process_id, render_frame_id_,
|
2019-12-13 20:13:12 +00:00
|
|
|
- request_id_, url_request_->url(), first_auth_attempt_, auth_info,
|
|
|
|
- std::move(head),
|
2019-11-14 18:01:18 +00:00
|
|
|
- auth_challenge_responder_receiver_.BindNewPipeAndPassRemote());
|
|
|
|
+ if (auth_client_) {
|
|
|
|
+ auth_client_->OnAuthRequired(
|
|
|
|
+ fetch_window_id_, factory_params_->process_id, render_frame_id_,
|
2019-12-13 20:13:12 +00:00
|
|
|
+ request_id_, url_request_->url(), first_auth_attempt_, auth_info,
|
|
|
|
+ std::move(head),
|
2019-11-14 18:01:18 +00:00
|
|
|
+ auth_challenge_responder_receiver_.BindNewPipeAndPassRemote());
|
|
|
|
+ } else {
|
|
|
|
+ network_context_client_->OnAuthRequired(
|
|
|
|
+ fetch_window_id_, factory_params_->process_id, render_frame_id_,
|
2019-12-13 20:13:12 +00:00
|
|
|
+ request_id_, url_request_->url(), first_auth_attempt_, auth_info,
|
|
|
|
+ std::move(head),
|
2019-11-14 18:01:18 +00:00
|
|
|
+ auth_challenge_responder_receiver_.BindNewPipeAndPassRemote());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
auth_challenge_responder_receiver_.set_disconnect_handler(
|
|
|
|
base::BindOnce(&URLLoader::DeleteSelf, base::Unretained(this)));
|
|
|
|
diff --git a/services/network/url_loader.h b/services/network/url_loader.h
|
2021-03-04 17:27:05 +00:00
|
|
|
index e35076146d1b2205c851f815de943eef47bcdbc6..fa2beab3a2358da8a089cee78a4294af81352d2a 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader.h
|
|
|
|
+++ b/services/network/url_loader.h
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -130,6 +130,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) URLLoader
|
2019-11-14 18:01:18 +00:00
|
|
|
base::WeakPtr<KeepaliveStatisticsRecorder> keepalive_statistics_recorder,
|
|
|
|
base::WeakPtr<NetworkUsageAccumulator> network_usage_accumulator,
|
|
|
|
mojom::TrustedURLLoaderHeaderClient* url_loader_header_client,
|
|
|
|
+ mojom::TrustedURLLoaderAuthClient* url_loader_auth_client,
|
2020-04-06 20:09:52 +00:00
|
|
|
mojom::OriginPolicyManager* origin_policy_manager,
|
2020-04-13 23:39:26 +00:00
|
|
|
std::unique_ptr<TrustTokenRequestHelperFactory>
|
2020-05-26 20:06:26 +00:00
|
|
|
trust_token_helper_factory,
|
2021-03-04 17:27:05 +00:00
|
|
|
@@ -497,6 +498,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) URLLoader
|
2019-11-14 18:01:18 +00:00
|
|
|
base::Optional<base::UnguessableToken> fetch_window_id_;
|
|
|
|
|
|
|
|
mojo::Remote<mojom::TrustedHeaderClient> header_client_;
|
|
|
|
+ mojo::Remote<mojom::TrustedAuthClient> auth_client_;
|
|
|
|
|
|
|
|
std::unique_ptr<FileOpenerForUpload> file_opener_for_upload_;
|
|
|
|
|
|
|
|
diff --git a/services/network/url_loader_factory.cc b/services/network/url_loader_factory.cc
|
2021-03-04 17:27:05 +00:00
|
|
|
index e72645de2bd9073966e3f220d3663f157d29650e..6b12fb88c25d506494e8d2b8cab950dedf89ce0c 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader_factory.cc
|
|
|
|
+++ b/services/network/url_loader_factory.cc
|
2020-12-22 22:14:44 +00:00
|
|
|
@@ -77,6 +77,7 @@ URLLoaderFactory::URLLoaderFactory(
|
2019-11-14 18:01:18 +00:00
|
|
|
resource_scheduler_client_(std::move(resource_scheduler_client)),
|
|
|
|
header_client_(std::move(params_->header_client)),
|
2020-03-11 11:15:07 +00:00
|
|
|
coep_reporter_(std::move(params_->coep_reporter)),
|
2019-11-14 18:01:18 +00:00
|
|
|
+ auth_client_(std::move(params_->auth_client)),
|
2020-05-26 20:06:26 +00:00
|
|
|
cors_url_loader_factory_(cors_url_loader_factory),
|
2021-03-04 17:27:05 +00:00
|
|
|
cookie_observer_(std::move(params_->cookie_observer)),
|
|
|
|
auth_cert_observer_(std::move(params_->auth_cert_observer)) {
|
|
|
|
@@ -296,6 +297,7 @@ void URLLoaderFactory::CreateLoaderAndStart(
|
2020-03-11 11:15:07 +00:00
|
|
|
std::move(keepalive_statistics_recorder),
|
2019-11-14 18:01:18 +00:00
|
|
|
std::move(network_usage_accumulator),
|
|
|
|
header_client_.is_bound() ? header_client_.get() : nullptr,
|
|
|
|
+ auth_client_.is_bound() ? auth_client_.get() : nullptr,
|
2020-05-26 20:06:26 +00:00
|
|
|
context_->origin_policy_manager(), std::move(trust_token_factory),
|
2021-03-04 17:27:05 +00:00
|
|
|
context_->cors_origin_access_list(), std::move(cookie_observer),
|
|
|
|
std::move(auth_cert_observer));
|
2019-11-14 18:01:18 +00:00
|
|
|
diff --git a/services/network/url_loader_factory.h b/services/network/url_loader_factory.h
|
2021-03-04 17:27:05 +00:00
|
|
|
index 14bf9839d142531e4e7f6dc6a461d97713d435ed..e5bca17b40fad7a553ef1b70fa6c4eacbb3cd1a9 100644
|
2019-11-14 18:01:18 +00:00
|
|
|
--- a/services/network/url_loader_factory.h
|
|
|
|
+++ b/services/network/url_loader_factory.h
|
2020-09-21 08:00:36 +00:00
|
|
|
@@ -74,6 +74,7 @@ class URLLoaderFactory : public mojom::URLLoaderFactory {
|
2019-11-14 18:01:18 +00:00
|
|
|
scoped_refptr<ResourceSchedulerClient> resource_scheduler_client_;
|
|
|
|
mojo::Remote<mojom::TrustedURLLoaderHeaderClient> header_client_;
|
2020-03-11 11:15:07 +00:00
|
|
|
mojo::Remote<mojom::CrossOriginEmbedderPolicyReporter> coep_reporter_;
|
2019-11-14 18:01:18 +00:00
|
|
|
+ mojo::Remote<mojom::TrustedURLLoaderAuthClient> auth_client_;
|
|
|
|
|
|
|
|
// |cors_url_loader_factory_| owns this.
|
|
|
|
cors::CorsURLLoaderFactory* cors_url_loader_factory_;
|