Revert-Permit-blocking-of-view-source.patch 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sun, 6 Mar 2022 11:29:27 +0100
  3. Subject: Revert Permit blocking of view-source
  4. This reverts commit e72fc9b64116bf259e516096fcc60b58ae8ae1b3.
  5. ---
  6. .../test/url_blocklist_policy_browsertest.cc | 78 -------------------
  7. .../policy/url_blocking_policy_test_utils.cc | 11 ---
  8. .../policy/url_blocking_policy_test_utils.h | 3 -
  9. .../policy_blocklist_navigation_throttle.cc | 19 -----
  10. .../policy_blocklist_navigation_throttle.h | 4 -
  11. 5 files changed, 115 deletions(-)
  12. diff --git a/chrome/browser/policy/test/url_blocklist_policy_browsertest.cc b/chrome/browser/policy/test/url_blocklist_policy_browsertest.cc
  13. --- a/chrome/browser/policy/test/url_blocklist_policy_browsertest.cc
  14. +++ b/chrome/browser/policy/test/url_blocklist_policy_browsertest.cc
  15. @@ -60,14 +60,6 @@ void CheckCanOpenURL(Browser* browser, const std::string& spec) {
  16. EXPECT_NE(blocked_page_title, contents->GetTitle());
  17. }
  18. -void CheckCanOpenViewSourceURL(Browser* browser, const std::string& spec) {
  19. - GURL view_source_url("view-source:" + spec);
  20. - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser, view_source_url));
  21. - content::WebContents* contents =
  22. - browser->tab_strip_model()->GetActiveWebContents();
  23. - EXPECT_EQ(view_source_url, contents->GetLastCommittedURL());
  24. -}
  25. -
  26. // Handler for embedded http-server, returns a small page with javascript
  27. // variable and a link to increment it. It's for JavascriptBlocklistable test.
  28. std::unique_ptr<net::test_server::HttpResponse> JSIncrementerPageHandler(
  29. @@ -148,76 +140,6 @@ IN_PROC_BROWSER_TEST_F(UrlBlockingPolicyTest, URLBlocklist) {
  30. CheckCanOpenURL(browser(), kURLS[4]);
  31. }
  32. -IN_PROC_BROWSER_TEST_F(UrlBlockingPolicyTest, URLBlocklistViewSource) {
  33. - // Checks that blocklisted urls are blocked when accessed by via view-source:,
  34. - // and that blocklisting view-source:* blocks all view-source urls.
  35. -
  36. - ASSERT_TRUE(embedded_test_server()->Start());
  37. -
  38. - const std::string kURL_A =
  39. - embedded_test_server()->GetURL("aaa.com", "/empty.html").spec();
  40. - const std::string kURL_B =
  41. - embedded_test_server()->GetURL("bbb.com", "/empty.html").spec();
  42. -
  43. - // Ensure that no urls are blocked by default.
  44. - CheckCanOpenURL(browser(), kURL_A);
  45. - CheckCanOpenURL(browser(), kURL_B);
  46. - CheckCanOpenViewSourceURL(browser(), kURL_A);
  47. - CheckCanOpenViewSourceURL(browser(), kURL_B);
  48. -
  49. - // Block bbb.com urls.
  50. - base::ListValue blocklist;
  51. - blocklist.Append("bbb.com");
  52. - PolicyMap policies;
  53. - policies.Set(key::kURLBlocklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
  54. - POLICY_SOURCE_CLOUD, blocklist.Clone(), nullptr);
  55. - UpdateProviderPolicy(policies);
  56. - FlushBlocklistPolicy();
  57. -
  58. - // Verify that blocking bbb.com also blocks view-source:bbb.com.
  59. - CheckURLIsBlocked(browser(), kURL_B);
  60. - CheckViewSourceURLIsBlocked(browser(), kURL_B);
  61. -
  62. - // Block all view-source urls.
  63. - blocklist.Append("view-source:*");
  64. - policies.Set(key::kURLBlocklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
  65. - POLICY_SOURCE_CLOUD, blocklist.Clone(), nullptr);
  66. - UpdateProviderPolicy(policies);
  67. - FlushBlocklistPolicy();
  68. -
  69. - // Verify that blocking view-source:* blocks view-source:aaa.com but does not
  70. - // block http://aaa.com.
  71. - CheckViewSourceURLIsBlocked(browser(), kURL_A);
  72. - CheckCanOpenURL(browser(), kURL_A);
  73. -}
  74. -
  75. -IN_PROC_BROWSER_TEST_F(UrlBlockingPolicyTest, URLBlocklistNonStandardScheme) {
  76. - // Checks that non-standard schemes can be blocklisted, and that the blocking
  77. - // page mentions the URL's scheme.
  78. - const std::string kURL = "mailto:nobody";
  79. -
  80. - // Block mailto: urls.
  81. - base::ListValue blocklist;
  82. - blocklist.Append("mailto:*");
  83. - PolicyMap policies;
  84. - policies.Set(key::kURLBlocklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
  85. - POLICY_SOURCE_CLOUD, blocklist.Clone(), nullptr);
  86. - UpdateProviderPolicy(policies);
  87. - FlushBlocklistPolicy();
  88. -
  89. - // Ensure the URL is blocked.
  90. - CheckURLIsBlocked(browser(), kURL);
  91. -
  92. - // Ensure the blocking page mentions the scheme.
  93. - content::WebContents* contents =
  94. - browser()->tab_strip_model()->GetActiveWebContents();
  95. - std::string result;
  96. - ASSERT_TRUE(content::ExecuteScriptAndExtractString(
  97. - contents, "domAutomationController.send(document.body.textContent);",
  98. - &result));
  99. - EXPECT_THAT(result, testing::HasSubstr("mailto"));
  100. -}
  101. -
  102. IN_PROC_BROWSER_TEST_F(UrlBlockingPolicyTest, URLBlocklistIncognito) {
  103. // Checks that URLs can be blocklisted, and that exceptions can be made to
  104. // the blocklist.
  105. diff --git a/chrome/browser/policy/url_blocking_policy_test_utils.cc b/chrome/browser/policy/url_blocking_policy_test_utils.cc
  106. --- a/chrome/browser/policy/url_blocking_policy_test_utils.cc
  107. +++ b/chrome/browser/policy/url_blocking_policy_test_utils.cc
  108. @@ -56,15 +56,4 @@ void UrlBlockingPolicyTest::CheckURLIsBlocked(Browser* browser,
  109. CheckURLIsBlockedInWebContents(contents, url);
  110. }
  111. -void UrlBlockingPolicyTest::CheckViewSourceURLIsBlocked(
  112. - Browser* browser,
  113. - const std::string& spec) {
  114. - GURL url(spec);
  115. - GURL view_source_url("view-source:" + spec);
  116. - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser, view_source_url));
  117. - content::WebContents* contents =
  118. - browser->tab_strip_model()->GetActiveWebContents();
  119. - CheckURLIsBlockedInWebContents(contents, url);
  120. -}
  121. -
  122. } // namespace policy
  123. diff --git a/chrome/browser/policy/url_blocking_policy_test_utils.h b/chrome/browser/policy/url_blocking_policy_test_utils.h
  124. --- a/chrome/browser/policy/url_blocking_policy_test_utils.h
  125. +++ b/chrome/browser/policy/url_blocking_policy_test_utils.h
  126. @@ -29,9 +29,6 @@ class UrlBlockingPolicyTest : public PolicyTest {
  127. // Verifies that access to the given url |spec| is blocked.
  128. void CheckURLIsBlocked(Browser* browser, const std::string& spec);
  129. -
  130. - // Verifies that access to |view-source:spec| is blocked.
  131. - void CheckViewSourceURLIsBlocked(Browser* browser, const std::string& spec);
  132. };
  133. } // namespace policy
  134. diff --git a/components/policy/content/policy_blocklist_navigation_throttle.cc b/components/policy/content/policy_blocklist_navigation_throttle.cc
  135. --- a/components/policy/content/policy_blocklist_navigation_throttle.cc
  136. +++ b/components/policy/content/policy_blocklist_navigation_throttle.cc
  137. @@ -13,7 +13,6 @@
  138. #include "components/prefs/pref_service.h"
  139. #include "components/user_prefs/user_prefs.h"
  140. #include "content/public/browser/browser_context.h"
  141. -#include "content/public/browser/navigation_entry.h"
  142. #include "content/public/browser/navigation_handle.h"
  143. #include "url/gurl.h"
  144. @@ -41,19 +40,6 @@ PolicyBlocklistNavigationThrottle::PolicyBlocklistNavigationThrottle(
  145. PolicyBlocklistNavigationThrottle::~PolicyBlocklistNavigationThrottle() =
  146. default;
  147. -bool PolicyBlocklistNavigationThrottle::IsBlockedViewSourceNavigation() {
  148. - content::NavigationEntry* nav_entry =
  149. - navigation_handle()->GetNavigationEntry();
  150. - if (!nav_entry || !nav_entry->IsViewSourceMode())
  151. - return false;
  152. -
  153. - GURL view_source_url = GURL(std::string("view-source:") +
  154. - navigation_handle()->GetURL().spec());
  155. -
  156. - return (blocklist_service_->GetURLBlocklistState(view_source_url) ==
  157. - URLBlocklistState::URL_IN_BLOCKLIST);
  158. -}
  159. -
  160. content::NavigationThrottle::ThrottleCheckResult
  161. PolicyBlocklistNavigationThrottle::WillStartRequest() {
  162. const GURL& url = navigation_handle()->GetURL();
  163. @@ -70,11 +56,6 @@ PolicyBlocklistNavigationThrottle::WillStartRequest() {
  164. net::ERR_BLOCKED_BY_ADMINISTRATOR);
  165. }
  166. - if (IsBlockedViewSourceNavigation()) {
  167. - return ThrottleCheckResult(BLOCK_REQUEST,
  168. - net::ERR_BLOCKED_BY_ADMINISTRATOR);
  169. - }
  170. -
  171. if (blocklist_state == URLBlocklistState::URL_IN_ALLOWLIST)
  172. return PROCEED;
  173. diff --git a/components/policy/content/policy_blocklist_navigation_throttle.h b/components/policy/content/policy_blocklist_navigation_throttle.h
  174. --- a/components/policy/content/policy_blocklist_navigation_throttle.h
  175. +++ b/components/policy/content/policy_blocklist_navigation_throttle.h
  176. @@ -35,10 +35,6 @@ class PolicyBlocklistNavigationThrottle : public content::NavigationThrottle {
  177. const char* GetNameForLogging() override;
  178. private:
  179. - // Returns TRUE if this navigation is to view-source: and view-source is on
  180. - // the URLBlocklist.
  181. - bool IsBlockedViewSourceNavigation();
  182. -
  183. // To ensure both allow and block policies override Safe Sites,
  184. // SafeSitesNavigationThrottle must be consulted as part of this throttle
  185. // rather than added separately to the list of throttles.
  186. --
  187. 2.25.1