fix_crash_loading_non-standard_schemes_in_iframes.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. Upstream, https://bugs.chromium.org/p/chromium/issues/detail?id=1081397
  11. contains several paths forward - here I chose to swap out the
  12. CHECK in navigation_request.cc from policy->CanAccessDataForOrigin to
  13. policy->CanCommitOriginAndUrl.
  14. Upstreamed at https://chromium-review.googlesource.com/c/chromium/src/+/3856266.
  15. diff --git a/content/browser/renderer_host/navigation_request.cc b/content/browser/renderer_host/navigation_request.cc
  16. index e91fb6b203b55d4937e9f4b4ed8fd5e8efb5aa10..855cb90260de04b90b8bbf4a8733e0869cda551d 100644
  17. --- a/content/browser/renderer_host/navigation_request.cc
  18. +++ b/content/browser/renderer_host/navigation_request.cc
  19. @@ -7543,10 +7543,11 @@ NavigationRequest::GetOriginForURLLoaderFactoryAfterResponseWithDebugInfo() {
  20. if (IsForMhtmlSubframe())
  21. return origin_with_debug_info;
  22. - int process_id = GetRenderFrameHost()->GetProcess()->GetID();
  23. - auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
  24. - CHECK(
  25. - policy->CanAccessDataForOrigin(process_id, origin_with_debug_info.first));
  26. + CanCommitStatus can_commit = GetRenderFrameHost()->CanCommitOriginAndUrl(
  27. + origin_with_debug_info.first, GetURL(), IsSameDocument(), IsPdf(),
  28. + GetUrlInfo().is_sandboxed);
  29. + CHECK_EQ(CanCommitStatus::CAN_COMMIT_ORIGIN_AND_URL, can_commit);
  30. +
  31. return origin_with_debug_info;
  32. }
  33. diff --git a/content/browser/renderer_host/render_frame_host_impl.h b/content/browser/renderer_host/render_frame_host_impl.h
  34. index 10282bf7372a07937d3aa15af6f3f7e767321df6..ae5cfc9bc17c7e8e9d1ab9134c95ff6413fe2017 100644
  35. --- a/content/browser/renderer_host/render_frame_host_impl.h
  36. +++ b/content/browser/renderer_host/render_frame_host_impl.h
  37. @@ -2968,6 +2968,17 @@ class CONTENT_EXPORT RenderFrameHostImpl
  38. // last committed document.
  39. CookieChangeListener::CookieChangeInfo GetCookieChangeInfo();
  40. + // Returns whether the given origin and URL is allowed to commit in the
  41. + // current RenderFrameHost. The |url| is used to ensure it matches the origin
  42. + // in cases where it is applicable. This is a more conservative check than
  43. + // RenderProcessHost::FilterURL, since it will be used to kill processes that
  44. + // commit unauthorized origins.
  45. + CanCommitStatus CanCommitOriginAndUrl(const url::Origin& origin,
  46. + const GURL& url,
  47. + bool is_same_document_navigation,
  48. + bool is_pdf,
  49. + bool is_sandboxed);
  50. +
  51. // Sets a ResourceCache in the renderer. `this` must be active and there must
  52. // be no pending navigation. `remote` must have the same and process
  53. // isolation policy.
  54. @@ -3391,17 +3402,6 @@ class CONTENT_EXPORT RenderFrameHostImpl
  55. // relevant.
  56. void ResetWaitingState();
  57. - // Returns whether the given origin and URL is allowed to commit in the
  58. - // current RenderFrameHost. The |url| is used to ensure it matches the origin
  59. - // in cases where it is applicable. This is a more conservative check than
  60. - // RenderProcessHost::FilterURL, since it will be used to kill processes that
  61. - // commit unauthorized origins.
  62. - CanCommitStatus CanCommitOriginAndUrl(const url::Origin& origin,
  63. - const GURL& url,
  64. - bool is_same_document_navigation,
  65. - bool is_pdf,
  66. - bool is_sandboxed);
  67. -
  68. // Returns whether a subframe navigation request should be allowed to commit
  69. // to the current RenderFrameHost.
  70. bool CanSubframeCommitOriginAndUrl(NavigationRequest* navigation_request);