Skip to content

Commit 3d612ab

Browse files
authored
Using profile's url loader instead of system. (#27595)
Applied upstream patch.
1 parent 32c4ca7 commit 3d612ab

4 files changed

Lines changed: 243 additions & 0 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
diff --git a/content/browser/webauth/authenticator_impl_unittest.cc b/content/browser/webauth/authenticator_impl_unittest.cc
2+
index dca681a3f79ff33f163957da42def9ddca3d8175..2e9e103e8cea8d9cda259d27649a2c441e4437e4 100644
3+
--- a/content/browser/webauth/authenticator_impl_unittest.cc
4+
+++ b/content/browser/webauth/authenticator_impl_unittest.cc
5+
@@ -63,6 +63,7 @@
6+
#include "content/browser/webauth/client_data_json.h"
7+
#include "content/browser/webauth/virtual_authenticator.h"
8+
#include "content/browser/webauth/virtual_authenticator_manager_impl.h"
9+
+#include "content/browser/webauth/webauth_request_security_checker.h"
10+
#include "content/public/browser/authenticator_request_client_delegate.h"
11+
#include "content/public/browser/content_browser_client.h"
12+
#include "content/public/browser/render_frame_host.h"
13+
@@ -616,6 +617,9 @@ class AuthenticatorTestBase : public RenderViewHostTestHarness {
14+
void SetUp() override {
15+
RenderViewHostTestHarness::SetUp();
16+
17+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
18+
+ true;
19+
+
20+
mojo::SetDefaultProcessErrorHandler(base::BindRepeating(
21+
&AuthenticatorTestBase::OnMojoError, base::Unretained(this)));
22+
23+
@@ -641,6 +645,8 @@ class AuthenticatorTestBase : public RenderViewHostTestHarness {
24+
25+
void TearDown() override {
26+
RenderViewHostTestHarness::TearDown();
27+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
28+
+ false;
29+
30+
mojo::SetDefaultProcessErrorHandler(base::NullCallback());
31+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
diff --git a/content/browser/webauth/webauth_browsertest.cc b/content/browser/webauth/webauth_browsertest.cc
2+
index 0ebb28807bfd6b9fc543db8d829700213c3fa581..be781a5818b855df4893d8476f63e25866788b69 100644
3+
--- a/content/browser/webauth/webauth_browsertest.cc
4+
+++ b/content/browser/webauth/webauth_browsertest.cc
5+
@@ -40,6 +40,7 @@
6+
#include "content/browser/renderer_host/render_frame_host_impl.h"
7+
#include "content/browser/webauth/authenticator_environment.h"
8+
#include "content/browser/webauth/authenticator_impl.h"
9+
+#include "content/browser/webauth/webauth_request_security_checker.h"
10+
#include "content/public/browser/authenticator_request_client_delegate.h"
11+
#include "content/public/browser/navigation_handle.h"
12+
#include "content/public/browser/navigation_throttle.h"
13+
@@ -179,6 +180,11 @@ constexpr char kRpIdNoEntryMessage[] =
14+
".well-known/webauthn resource of the claimed RP ID was "
15+
"successful, but no listed origin matched the caller.";
16+
17+
+constexpr char kRpIdFetchFailedMessage[] =
18+
+ "SecurityError: The relying party ID is not a registrable domain suffix "
19+
+ "of, nor equal to the current domain. Subsequently, an attempt to fetch "
20+
+ "the .well-known/webauthn resource of the claimed RP ID failed.";
21+
+
22+
constexpr char kMaxLargeBlobMessage[] =
23+
"NotSupportedError: The 'largeBlob' extension's 'write' parameter exceeds "
24+
"the maximum allowed size (2kb)";
25+
@@ -1810,6 +1816,8 @@ IN_PROC_BROWSER_TEST_F(WebAuthCrossDomainTest, Create) {
26+
parameters.rp_id = "foo.com";
27+
test_client()->set_webauthn_origins_response(
28+
"application/json", GetHttpsURL("www.acme.com", "/").spec());
29+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
30+
+ true;
31+
std::string result = EvalJs(shell()->web_contents()->GetPrimaryMainFrame(),
32+
BuildCreateCallWithParameters(parameters))
33+
.ExtractString();
34+
@@ -1817,11 +1825,30 @@ IN_PROC_BROWSER_TEST_F(WebAuthCrossDomainTest, Create) {
35+
EXPECT_EQ(kOkMessage, result);
36+
}
37+
38+
+IN_PROC_BROWSER_TEST_F(WebAuthCrossDomainTest, CreateFetchFailed) {
39+
+ CreateParameters parameters;
40+
+ parameters.rp_id = "foo.com";
41+
+ // Set up the system URL loader factory to respond to requests, but do not
42+
+ // force its use. This will result in the browser context-specific URL
43+
+ // loader factory being used, which will fail to handle the request.
44+
+ test_client()->set_webauthn_origins_response(
45+
+ "application/json", GetHttpsURL("www.acme.com", "/").spec());
46+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
47+
+ false;
48+
+ std::string result = EvalJs(shell()->web_contents()->GetPrimaryMainFrame(),
49+
+ BuildCreateCallWithParameters(parameters))
50+
+ .ExtractString();
51+
+
52+
+ EXPECT_EQ(kRpIdFetchFailedMessage, result);
53+
+}
54+
+
55+
IN_PROC_BROWSER_TEST_F(WebAuthCrossDomainTest, CreateBadContentType) {
56+
CreateParameters parameters;
57+
parameters.rp_id = "foo.com";
58+
test_client()->set_webauthn_origins_response(
59+
"text/plain", GetHttpsURL("www.acme.com", "/").spec());
60+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
61+
+ true;
62+
std::string result = EvalJs(shell()->web_contents()->GetPrimaryMainFrame(),
63+
BuildCreateCallWithParameters(parameters))
64+
.ExtractString();
65+
@@ -1834,6 +1861,8 @@ IN_PROC_BROWSER_TEST_F(WebAuthCrossDomainTest, CreateBadOrigin) {
66+
parameters.rp_id = "foo.com";
67+
test_client()->set_webauthn_origins_response("application/json",
68+
"https://nottherightdomain.com");
69+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
70+
+ true;
71+
std::string result = EvalJs(shell()->web_contents()->GetPrimaryMainFrame(),
72+
BuildCreateCallWithParameters(parameters))
73+
.ExtractString();
74+
@@ -1847,6 +1876,8 @@ IN_PROC_BROWSER_TEST_F(WebAuthCrossDomainTest, Timeout) {
75+
parameters.rp_id = "foo.com";
76+
parameters.timeout = kShortTimeout;
77+
test_client()->sinkhole_webauthn_origins_requests();
78+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
79+
+ true;
80+
std::string result = EvalJs(shell()->web_contents()->GetPrimaryMainFrame(),
81+
BuildCreateCallWithParameters(parameters))
82+
.ExtractString();
83+
@@ -1867,6 +1898,8 @@ IN_PROC_BROWSER_TEST_F(WebAuthCrossDomainTest, Get) {
84+
parameters.rp_id = "foo.com";
85+
test_client()->set_webauthn_origins_response(
86+
"application/json", GetHttpsURL("www.acme.com", "/").spec());
87+
+ WebAuthRequestSecurityChecker::UseSystemSharedURLLoaderFactoryForTesting() =
88+
+ true;
89+
std::string result = EvalJs(shell()->web_contents()->GetPrimaryMainFrame(),
90+
BuildGetCallWithParameters(parameters))
91+
.ExtractString();
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
diff --git a/content/browser/webauth/webauth_request_security_checker.cc b/content/browser/webauth/webauth_request_security_checker.cc
2+
index befcc5fe79e376ad4a24d1762bf151138689d418..7303eaffd9302d94484407359102d77e76c6252c 100644
3+
--- a/content/browser/webauth/webauth_request_security_checker.cc
4+
+++ b/content/browser/webauth/webauth_request_security_checker.cc
5+
@@ -10,8 +10,10 @@
6+
#include "base/metrics/histogram_macros.h"
7+
#include "base/strings/string_number_conversions.h"
8+
#include "content/browser/bad_message.h"
9+
+#include "content/public/browser/browser_context.h"
10+
#include "content/public/browser/content_browser_client.h"
11+
#include "content/public/browser/render_frame_host.h"
12+
+#include "content/public/browser/storage_partition.h"
13+
#include "content/public/browser/web_authentication_delegate.h"
14+
#include "content/public/browser/webauthn_security_utils.h"
15+
#include "content/public/common/content_client.h"
16+
@@ -84,7 +86,14 @@ std::unique_ptr<WebAuthRequestSecurityChecker::RemoteValidation>
17+
WebAuthRequestSecurityChecker::RemoteValidation::Create(
18+
const url::Origin& caller_origin,
19+
const std::string& relying_party_id,
20+
+ scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
21+
base::OnceCallback<void(blink::mojom::AuthenticatorStatus)> callback) {
22+
+ if (!url_loader_factory) {
23+
+ std::move(callback).Run(
24+
+ blink::mojom::AuthenticatorStatus::BAD_RELYING_PARTY_ID);
25+
+ return nullptr;
26+
+ }
27+
+
28+
// The relying party may allow other origins to use its RP ID based on the
29+
// contents of a .well-known file.
30+
std::string canonicalized_domain_storage;
31+
@@ -112,14 +121,6 @@ WebAuthRequestSecurityChecker::RemoteValidation::Create(
32+
replace_host.SetHostStr(canonicalized_domain);
33+
well_known_url = well_known_url.ReplaceComponents(replace_host);
34+
35+
- scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory =
36+
- GetContentClient()->browser()->GetSystemSharedURLLoaderFactory();
37+
- if (!url_loader_factory) {
38+
- std::move(callback).Run(
39+
- blink::mojom::AuthenticatorStatus::BAD_RELYING_PARTY_ID);
40+
- return nullptr;
41+
- }
42+
-
43+
auto network_request = std::make_unique<network::ResourceRequest>();
44+
network_request->url = well_known_url;
45+
46+
@@ -256,8 +257,9 @@ bool WebAuthRequestSecurityChecker::IsSameOriginWithAncestors(
47+
const url::Origin& origin) {
48+
RenderFrameHost* parent = render_frame_host_->GetParentOrOuterDocument();
49+
while (parent) {
50+
- if (!parent->GetLastCommittedOrigin().IsSameOriginWith(origin))
51+
+ if (!parent->GetLastCommittedOrigin().IsSameOriginWith(origin)) {
52+
return false;
53+
+ }
54+
parent = parent->GetParentOrOuterDocument();
55+
}
56+
return true;
57+
@@ -376,8 +378,19 @@ WebAuthRequestSecurityChecker::ValidateDomainAndRelyingPartyID(
58+
return nullptr;
59+
}
60+
61+
+ scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory;
62+
+ if (!WebAuthRequestSecurityChecker::
63+
+ UseSystemSharedURLLoaderFactoryForTesting()) {
64+
+ url_loader_factory = render_frame_host_->GetStoragePartition()
65+
+ ->GetURLLoaderFactoryForBrowserProcess();
66+
+ }
67+
+ if (!url_loader_factory) {
68+
+ url_loader_factory =
69+
+ GetContentClient()->browser()->GetSystemSharedURLLoaderFactory();
70+
+ }
71+
+
72+
return RemoteValidation::Create(caller_origin, relying_party_id,
73+
- std::move(callback));
74+
+ url_loader_factory, std::move(callback));
75+
}
76+
77+
blink::mojom::AuthenticatorStatus
78+
@@ -515,4 +528,11 @@ bool WebAuthRequestSecurityChecker::
79+
return true;
80+
}
81+
82+
+// static
83+
+bool& WebAuthRequestSecurityChecker::
84+
+ UseSystemSharedURLLoaderFactoryForTesting() {
85+
+ static bool value = false;
86+
+ return value;
87+
+}
88+
+
89+
} // namespace content
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/content/browser/webauth/webauth_request_security_checker.h b/content/browser/webauth/webauth_request_security_checker.h
2+
index 017f2e28a100b911cf8aa321b2395adf14925420..dedfbda18c9c5209e1d5d2a0eddbf906ecf44f9e 100644
3+
--- a/content/browser/webauth/webauth_request_security_checker.h
4+
+++ b/content/browser/webauth/webauth_request_security_checker.h
5+
@@ -23,7 +23,8 @@ class Value;
6+
7+
namespace network {
8+
class SimpleURLLoader;
9+
-}
10+
+class SharedURLLoaderFactory;
11+
+} // namespace network
12+
13+
namespace content {
14+
15+
@@ -60,6 +61,8 @@ class CONTENT_EXPORT WebAuthRequestSecurityChecker
16+
static std::unique_ptr<RemoteValidation> Create(
17+
const url::Origin& caller_origin,
18+
const std::string& relying_party_id,
19+
+ scoped_refptr<network::SharedURLLoaderFactory>
20+
+ shared_url_loader_factory,
21+
base::OnceCallback<void(blink::mojom::AuthenticatorStatus)> callback);
22+
23+
// ValidateWellKnownJSON implements the core of remote validation. It isn't
24+
@@ -154,6 +157,8 @@ class CONTENT_EXPORT WebAuthRequestSecurityChecker
25+
[[nodiscard]] bool DeduplicateCredentialDescriptorListAndValidateLength(
26+
std::vector<device::PublicKeyCredentialDescriptor>* list);
27+
28+
+ static bool& UseSystemSharedURLLoaderFactoryForTesting();
29+
+
30+
protected:
31+
friend class base::RefCounted<WebAuthRequestSecurityChecker>;
32+
virtual ~WebAuthRequestSecurityChecker();

0 commit comments

Comments
 (0)