fix_crash_loading_non-standard_schemes_in_iframes.patch 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 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. Upstream bug https://bugs.chromium.org/p/chromium/issues/detail?id=1081397.
  18. Upstreamed at https://chromium-review.googlesource.com/c/chromium/src/+/3856266.
  19. diff --git a/content/browser/renderer_host/navigation_request.cc b/content/browser/renderer_host/navigation_request.cc
  20. index 53bba48293111e74daba50dde617fb78f1bcc7ee..67083fb13db2020f432ec488a784bcfb9570d737 100644
  21. --- a/content/browser/renderer_host/navigation_request.cc
  22. +++ b/content/browser/renderer_host/navigation_request.cc
  23. @@ -10788,6 +10788,12 @@ NavigationRequest::GetOriginForURLLoaderFactoryUncheckedWithDebugInfo() {
  24. "blob");
  25. }
  26. + if (!common_params().url.IsStandard()) {
  27. + return std::make_pair(url::Origin::Resolve(common_params().url,
  28. + url::Origin()),
  29. + "url_non_standard");
  30. + }
  31. +
  32. // In cases not covered above, URLLoaderFactory should be associated with the
  33. // origin of |common_params.url| and/or |common_params.initiator_origin|.
  34. url::Origin resolved_origin = url::Origin::Resolve(
  35. diff --git a/third_party/blink/renderer/core/loader/document_loader.cc b/third_party/blink/renderer/core/loader/document_loader.cc
  36. index 547a483db71e2980cc040fe853775fbc07723979..85c6d240a68e52b9d59fae7bbe36603e627b2893 100644
  37. --- a/third_party/blink/renderer/core/loader/document_loader.cc
  38. +++ b/third_party/blink/renderer/core/loader/document_loader.cc
  39. @@ -2264,6 +2264,10 @@ Frame* DocumentLoader::CalculateOwnerFrame() {
  40. scoped_refptr<SecurityOrigin> DocumentLoader::CalculateOrigin(
  41. Document* owner_document) {
  42. scoped_refptr<SecurityOrigin> origin;
  43. + bool is_standard = false;
  44. + std::string protocol = url_.Protocol().Ascii();
  45. + is_standard = url::IsStandard(
  46. + protocol.data(), url::Component(0, static_cast<int>(protocol.size())));
  47. StringBuilder debug_info_builder;
  48. // Whether the origin is newly created within this call, instead of copied
  49. // from an existing document's origin or from `origin_to_commit_`. If this is
  50. @@ -2317,6 +2321,10 @@ scoped_refptr<SecurityOrigin> DocumentLoader::CalculateOrigin(
  51. // the end of this function.
  52. origin = origin_to_commit_;
  53. debug_info_builder.Append("use_origin_to_commit");
  54. + } else if (!SecurityOrigin::ShouldUseInnerURL(url_) &&
  55. + !is_standard) {
  56. + debug_info_builder.Append("use_url_with_non_standard_scheme");
  57. + origin = SecurityOrigin::Create(url_);
  58. } else {
  59. debug_info_builder.Append("use_url_with_precursor");
  60. // Otherwise, create an origin that propagates precursor information