From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 29 Aug 2022 11:44:57 +0200 Subject: fix: crash loading non-standard schemes in iframes This fixes a crash that occurs when loading non-standard schemes from iframes or webviews. This was happening because ChildProcessSecurityPolicyImpl::CanAccessDataForOrigin contains explicit exceptions to allow built-in non-standard schemes, but does not check for non-standard schemes registered by the embedder. This patch adjusts the origin calculation for subframe non-standard schemes in - browser process at `NavigationRequest::GetOriginForURLLoaderFactoryUncheckedWithDebugInfo` - render process at `DocumentLoader::CalculateOrigin` When top level frame navigates to non-standard scheme url, the origin is calculated as `null` without any derivation. It is only in cases where there is a `initiator_origin` then the origin is derived from it, which is usually the case for renderer initiated navigations and iframes are no exceptions from this rule. The patch should be removed in favor of either: - Remove support for non-standard custom schemes - Register non-standard custom schemes as websafe schemes and update CPSPI::CanAccessDataForOrigin to allow them for any navigation. - Update the callsite to use RFHI::CanCommitOriginAndUrl in upstream, previous effort to do this can be found at https://chromium-review.googlesource.com/c/chromium/src/+/3856266. Upstream bug https://bugs.chromium.org/p/chromium/issues/detail?id=1081397. diff --git a/content/browser/renderer_host/navigation_request.cc b/content/browser/renderer_host/navigation_request.cc index 66c6ae2e93af9b86d0796a2e42a657250d1214f3..68824cb9e4eb7d958eaaa04e4016b6d92662ce5f 100644 --- a/content/browser/renderer_host/navigation_request.cc +++ b/content/browser/renderer_host/navigation_request.cc @@ -11499,6 +11499,11 @@ url::Origin NavigationRequest::GetOriginForURLLoaderFactoryUnchecked() { target_rph_id); } + if (!common_params().url.IsStandard() && !common_params().url.IsAboutBlank()) { + return url::Origin::Resolve(common_params().url, + url::Origin()); + } + // In cases not covered above, URLLoaderFactory should be associated with the // origin of |common_params.url| and/or |common_params.initiator_origin|. url::Origin resolved_origin = url::Origin::Resolve( diff --git a/third_party/blink/renderer/core/loader/document_loader.cc b/third_party/blink/renderer/core/loader/document_loader.cc index e1ef9b4e88d7711affe123cf3cbba3e4dba01dd5..0884a49cccd25f1476b99a63870c05757ca8444e 100644 --- a/third_party/blink/renderer/core/loader/document_loader.cc +++ b/third_party/blink/renderer/core/loader/document_loader.cc @@ -2331,6 +2331,10 @@ Frame* DocumentLoader::CalculateOwnerFrame() { scoped_refptr DocumentLoader::CalculateOrigin( Document* owner_document) { scoped_refptr origin; + bool is_standard = false; + std::string protocol = url_.Protocol().Ascii(); + is_standard = url::IsStandard( + protocol.data(), url::Component(0, static_cast(protocol.size()))); // Whether the origin is newly created within this call, instead of copied // from an existing document's origin or from `origin_to_commit_`. If this is // true, we won't try to compare the nonce of this origin (if it's opaque) to @@ -2367,6 +2371,9 @@ scoped_refptr DocumentLoader::CalculateOrigin( // non-renderer only origin bits will be the same, which will be asserted at // the end of this function. origin = origin_to_commit_; + } else if (!SecurityOrigin::ShouldUseInnerURL(url_) && + !is_standard) { + origin = SecurityOrigin::Create(url_); } else { // Otherwise, create an origin that propagates precursor information // as needed. For non-opaque origins, this creates a standard tuple