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 0c67607fd99b2fceba176308a041c8f08643506a..6b38139e1b58db7c7a0c4d553ed2cdaa11a63d2d 100644
  26. --- a/content/browser/renderer_host/navigation_request.cc
  27. +++ b/content/browser/renderer_host/navigation_request.cc
  28. @@ -10980,6 +10980,12 @@ NavigationRequest::GetOriginForURLLoaderFactoryUncheckedWithDebugInfo() {
  29. "blob");
  30. }
  31. + if (!common_params().url.IsStandard() && !common_params().url.IsAboutBlank()) {
  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 cbf8b2ed5ce03a3b4524f4e7f97bbb7750e5c583..b84bdff826390234f470025edba02abddefff045 100644
  42. --- a/third_party/blink/renderer/core/loader/document_loader.cc
  43. +++ b/third_party/blink/renderer/core/loader/document_loader.cc
  44. @@ -2325,6 +2325,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. @@ -2378,6 +2382,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