fix_crash_loading_non-standard_schemes_in_iframes.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Mon, 29 Aug 2022 11:44:57 +0200
  4. Subject: fix: crash loading non-standard schemes in iframes
  5. This fixes a crash that occurs when loading non-standard schemes from
  6. iframes or webviews. This was happening because
  7. ChildProcessSecurityPolicyImpl::CanAccessDataForOrigin contains explicit
  8. exceptions to allow built-in non-standard schemes, but does not check
  9. for non-standard schemes registered by the embedder.
  10. This patch adjusts the origin calculation for subframe non-standard schemes in
  11. - browser process at `NavigationRequest::GetOriginForURLLoaderFactoryUncheckedWithDebugInfo`
  12. - render process at `DocumentLoader::CalculateOrigin`
  13. When top level frame navigates to non-standard scheme url, the origin is calculated
  14. as `null` without any derivation. It is only in cases where there is a `initiator_origin`
  15. then the origin is derived from it, which is usually the case for renderer initiated
  16. navigations and iframes are no exceptions from this rule.
  17. The patch should be removed in favor of either:
  18. - Remove support for non-standard custom schemes
  19. - Register non-standard custom schemes as websafe schemes and update
  20. CPSPI::CanAccessDataForOrigin to allow them for any navigation.
  21. - Update the callsite to use RFHI::CanCommitOriginAndUrl in upstream, previous
  22. effort to do this can be found at https://chromium-review.googlesource.com/c/chromium/src/+/3856266.
  23. Upstream bug https://bugs.chromium.org/p/chromium/issues/detail?id=1081397.
  24. diff --git a/content/browser/renderer_host/navigation_request.cc b/content/browser/renderer_host/navigation_request.cc
  25. index 27c692d5c1ddf7493f6b35a9428b60c58f50f288..475ef0da92dc55abd2014c14616527d97d931ec0 100644
  26. --- a/content/browser/renderer_host/navigation_request.cc
  27. +++ b/content/browser/renderer_host/navigation_request.cc
  28. @@ -10886,6 +10886,12 @@ NavigationRequest::GetOriginForURLLoaderFactoryUncheckedWithDebugInfo() {
  29. "blob");
  30. }
  31. + if (!IsInMainFrame() && !common_params().url.IsStandard()) {
  32. + return std::make_pair(url::Origin::Resolve(common_params().url,
  33. + url::Origin()),
  34. + "url_non_standard");
  35. + }
  36. +
  37. // In cases not covered above, URLLoaderFactory should be associated with the
  38. // origin of |common_params.url| and/or |common_params.initiator_origin|.
  39. url::Origin resolved_origin = url::Origin::Resolve(
  40. diff --git a/third_party/blink/renderer/core/loader/document_loader.cc b/third_party/blink/renderer/core/loader/document_loader.cc
  41. index 4381454af08832a428dad1dba46f317a5ff91124..80fbd403a2f5e6c60abc8b88a348647e491e454f 100644
  42. --- a/third_party/blink/renderer/core/loader/document_loader.cc
  43. +++ b/third_party/blink/renderer/core/loader/document_loader.cc
  44. @@ -2313,6 +2313,10 @@ Frame* DocumentLoader::CalculateOwnerFrame() {
  45. scoped_refptr<SecurityOrigin> DocumentLoader::CalculateOrigin(
  46. Document* owner_document) {
  47. scoped_refptr<SecurityOrigin> origin;
  48. + bool is_standard = false;
  49. + std::string protocol = url_.Protocol().Ascii();
  50. + is_standard = url::IsStandard(
  51. + protocol.data(), url::Component(0, static_cast<int>(protocol.size())));
  52. StringBuilder debug_info_builder;
  53. // Whether the origin is newly created within this call, instead of copied
  54. // from an existing document's origin or from `origin_to_commit_`. If this is
  55. @@ -2366,6 +2370,10 @@ scoped_refptr<SecurityOrigin> DocumentLoader::CalculateOrigin(
  56. // the end of this function.
  57. origin = origin_to_commit_;
  58. debug_info_builder.Append("use_origin_to_commit");
  59. + } else if (!SecurityOrigin::ShouldUseInnerURL(url_) &&
  60. + !is_standard) {
  61. + debug_info_builder.Append("use_url_with_non_standard_scheme");
  62. + origin = SecurityOrigin::Create(url_);
  63. } else {
  64. debug_info_builder.Append("use_url_with_precursor");
  65. // Otherwise, create an origin that propagates precursor information