Block-all-connection-requests-with-qjz9zk-in-the-domain-name-or-with-a-trk-scheme.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Wed, 30 Oct 2019 11:50:13 +0100
  3. Subject: Block all connection requests with 'qjz9zk' in the domain name or
  4. with a 'trk:' scheme.
  5. An info bar is displayed unless the --disable-trkbar command-line flag or the chrome://flag option is used.
  6. This patch is based on Iridium's 'net: add "trk:" scheme and help identify URLs being retrieved'
  7. FILE:Block-all-connection-requests-with-qjz9zk-in-the-domain-name-or-with-a-trk-scheme.patch
  8. ---
  9. diff --git a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
  10. index d5c3dd451a..431f242e27 100644
  11. --- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
  12. +++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
  13. @@ -56,6 +56,7 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme(
  14. if (base::IsStringASCII(scheme) &&
  15. (ProfileIOData::IsHandledProtocol(scheme) ||
  16. base::LowerCaseEqualsASCII(scheme, content::kViewSourceScheme) ||
  17. + base::LowerCaseEqualsASCII(scheme, url::kTraceScheme) ||
  18. base::LowerCaseEqualsASCII(scheme, url::kJavaScriptScheme) ||
  19. base::LowerCaseEqualsASCII(scheme, url::kDataScheme))) {
  20. return metrics::OmniboxInputType::URL;
  21. diff --git a/chrome/browser/history/history_utils.cc b/chrome/browser/history/history_utils.cc
  22. index 3f54bbb409..8971b7e96a 100644
  23. --- a/chrome/browser/history/history_utils.cc
  24. +++ b/chrome/browser/history/history_utils.cc
  25. @@ -21,6 +21,7 @@ bool CanAddURLToHistory(const GURL& url) {
  26. url.SchemeIs(content::kChromeDevToolsScheme) ||
  27. url.SchemeIs(content::kChromeUIScheme) ||
  28. url.SchemeIs(content::kViewSourceScheme) ||
  29. + url.SchemeIs(url::kTraceScheme) ||
  30. url.SchemeIs(chrome::kChromeNativeScheme) ||
  31. url.SchemeIs(chrome::kChromeSearchScheme) ||
  32. url.SchemeIs(dom_distiller::kDomDistillerScheme))
  33. diff --git a/chrome/browser/ui/singleton_tabs.cc b/chrome/browser/ui/singleton_tabs.cc
  34. index 6d99c68055..3d4f0ccfae 100644
  35. --- a/chrome/browser/ui/singleton_tabs.cc
  36. +++ b/chrome/browser/ui/singleton_tabs.cc
  37. @@ -99,7 +99,8 @@ int GetIndexOfExistingTab(Browser* browser, const NavigateParams& params) {
  38. // Skip view-source tabs. This is needed because RewriteURLIfNecessary
  39. // removes the "view-source:" scheme which leads to incorrect matching.
  40. - if (tab_url.SchemeIs(content::kViewSourceScheme))
  41. + if (tab_url.SchemeIs(content::kViewSourceScheme) ||
  42. + tab_url.SchemeIs(url::kTraceScheme))
  43. continue;
  44. GURL rewritten_tab_url = tab_url;
  45. diff --git a/components/omnibox/browser/autocomplete_input.cc b/components/omnibox/browser/autocomplete_input.cc
  46. index 1a3902c994..294d5980fb 100644
  47. --- a/components/omnibox/browser/autocomplete_input.cc
  48. +++ b/components/omnibox/browser/autocomplete_input.cc
  49. @@ -526,7 +526,8 @@ void AutocompleteInput::ParseForEmphasizeComponents(
  50. // For the view-source and blob schemes, we should emphasize the host of the
  51. // URL qualified by the view-source or blob prefix.
  52. if ((base::LowerCaseEqualsASCII(scheme_str, kViewSourceScheme) ||
  53. - base::LowerCaseEqualsASCII(scheme_str, url::kBlobScheme)) &&
  54. + base::LowerCaseEqualsASCII(scheme_str, url::kBlobScheme) ||
  55. + base::LowerCaseEqualsASCII(scheme_str, url::kTraceScheme)) &&
  56. (static_cast<int>(text.length()) > after_scheme_and_colon)) {
  57. // Obtain the URL prefixed by view-source or blob and parse it.
  58. base::string16 real_url(text.substr(after_scheme_and_colon));
  59. @@ -599,7 +600,9 @@ int AutocompleteInput::NumNonHostComponents(const url::Parsed& parts) {
  60. bool AutocompleteInput::HasHTTPScheme(const base::string16& input) {
  61. std::string utf8_input(base::UTF16ToUTF8(input));
  62. url::Component scheme;
  63. - if (url::FindAndCompareScheme(utf8_input, kViewSourceScheme, &scheme)) {
  64. + if (url::FindAndCompareScheme(utf8_input, url::kTraceScheme, &scheme)) {
  65. + return false;
  66. + } else if (url::FindAndCompareScheme(utf8_input, kViewSourceScheme, &scheme)) {
  67. utf8_input.erase(0, scheme.end() + 1);
  68. }
  69. return url::FindAndCompareScheme(utf8_input, url::kHttpScheme, nullptr);
  70. diff --git a/components/url_formatter/url_fixer.cc b/components/url_formatter/url_fixer.cc
  71. index 125a2f1e8e..528d03ad06 100644
  72. --- a/components/url_formatter/url_fixer.cc
  73. +++ b/components/url_formatter/url_fixer.cc
  74. @@ -560,6 +560,10 @@ GURL FixupURL(const std::string& text, const std::string& desired_tld) {
  75. }
  76. }
  77. + if (scheme == url::kTraceScheme) {
  78. + return GURL();
  79. + }
  80. +
  81. // We handle the file scheme separately.
  82. if (scheme == url::kFileScheme)
  83. return GURL(parts.scheme.is_valid() ? text : FixupPath(text));
  84. diff --git a/content/browser/child_process_security_policy_impl.cc b/content/browser/child_process_security_policy_impl.cc
  85. index d2d167ebf5..8eec489e7e 100644
  86. --- a/content/browser/child_process_security_policy_impl.cc
  87. +++ b/content/browser/child_process_security_policy_impl.cc
  88. @@ -762,6 +762,7 @@ ChildProcessSecurityPolicyImpl::ChildProcessSecurityPolicyImpl() {
  89. #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
  90. RegisterWebSafeScheme(url::kFtpScheme);
  91. RegisterWebSafeScheme(url::kDataScheme);
  92. + RegisterWebSafeScheme(url::kTraceScheme);
  93. RegisterWebSafeScheme("feed");
  94. // TODO(nick): https://crbug.com/651534 blob: and filesystem: schemes embed
  95. diff --git a/net/BUILD.gn b/net/BUILD.gn
  96. index d214ac4959..11de6308ee 100644
  97. --- a/net/BUILD.gn
  98. +++ b/net/BUILD.gn
  99. @@ -1086,6 +1086,8 @@ component("net") {
  100. "url_request/report_sender.h",
  101. "url_request/static_http_user_agent_settings.cc",
  102. "url_request/static_http_user_agent_settings.h",
  103. + "url_request/trk_protocol_handler.cc",
  104. + "url_request/trk_protocol_handler.h",
  105. "url_request/url_fetcher.cc",
  106. "url_request/url_fetcher.h",
  107. "url_request/url_fetcher_core.cc",
  108. diff --git a/net/url_request/trk_protocol_handler.cc b/net/url_request/trk_protocol_handler.cc
  109. new file mode 100644
  110. index 0000000000..e32409c333
  111. --- /dev/null
  112. +++ b/net/url_request/trk_protocol_handler.cc
  113. @@ -0,0 +1,25 @@
  114. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  115. +// Use of this source code is governed by a BSD-style license that can be
  116. +// found in the LICENSE file.
  117. +
  118. +#include "net/url_request/trk_protocol_handler.h"
  119. +
  120. +#include "base/logging.h"
  121. +#include "net/base/net_errors.h"
  122. +#include "net/url_request/url_request_error_job.h"
  123. +
  124. +namespace net {
  125. +
  126. +TrkProtocolHandler::TrkProtocolHandler() = default;
  127. +
  128. +std::unique_ptr<URLRequestJob> TrkProtocolHandler::CreateJob(
  129. + URLRequest* request) const {
  130. + LOG(ERROR) << "Blocked URL in TrkProtocolHandler: " << request->original_url();
  131. + return std::make_unique<URLRequestErrorJob>(request, ERR_BLOCKED_BY_CLIENT);
  132. +}
  133. +
  134. +bool TrkProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
  135. + return true;
  136. +}
  137. +
  138. +} // namespace net
  139. diff --git a/net/url_request/trk_protocol_handler.h b/net/url_request/trk_protocol_handler.h
  140. new file mode 100644
  141. index 0000000000..9fb0b4fa33
  142. --- /dev/null
  143. +++ b/net/url_request/trk_protocol_handler.h
  144. @@ -0,0 +1,31 @@
  145. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  146. +// Use of this source code is governed by a BSD-style license that can be
  147. +// found in the LICENSE file.
  148. +
  149. +#ifndef NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  150. +#define NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  151. +
  152. +#include "base/compiler_specific.h"
  153. +#include "base/macros.h"
  154. +#include "net/base/net_export.h"
  155. +#include "net/url_request/url_request_job_factory.h"
  156. +
  157. +namespace net {
  158. +
  159. +class URLRequestJob;
  160. +
  161. +// Implements a ProtocolHandler for Trk jobs.
  162. +class NET_EXPORT TrkProtocolHandler
  163. + : public URLRequestJobFactory::ProtocolHandler {
  164. + public:
  165. + TrkProtocolHandler();
  166. + std::unique_ptr<URLRequestJob> CreateJob(URLRequest* request) const override;
  167. + bool IsSafeRedirectTarget(const GURL& location) const override;
  168. +
  169. + private:
  170. + DISALLOW_COPY_AND_ASSIGN(TrkProtocolHandler);
  171. +};
  172. +
  173. +} // namespace net
  174. +
  175. +#endif // NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  176. diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
  177. index bdfc3d8710..148bfbd865 100644
  178. --- a/net/url_request/url_request.cc
  179. +++ b/net/url_request/url_request.cc
  180. @@ -13,6 +13,7 @@
  181. #include "base/metrics/histogram_macros.h"
  182. #include "base/rand_util.h"
  183. #include "base/stl_util.h"
  184. +#include "base/strings/string_util.h"
  185. #include "base/strings/utf_string_conversions.h"
  186. #include "base/synchronization/lock.h"
  187. #include "base/threading/thread_task_runner_handle.h"
  188. @@ -40,6 +41,7 @@
  189. #include "net/url_request/url_request_redirect_job.h"
  190. #include "url/gurl.h"
  191. #include "url/origin.h"
  192. +#include "url/url_constants.h"
  193. using base::Time;
  194. using std::string;
  195. @@ -575,6 +577,12 @@ URLRequest::URLRequest(const GURL& url,
  196. // Sanity check out environment.
  197. DCHECK(base::ThreadTaskRunnerHandle::IsSet());
  198. + if (!url.SchemeIs(url::kTraceScheme) &&
  199. + base::EndsWith(url.host(), "qjz9zk", base::CompareCase::INSENSITIVE_ASCII)) {
  200. + LOG(ERROR) << "Block URL in URLRequest: " << url;
  201. + url_chain_[0] = GURL(url::kTraceScheme + (":" + url.possibly_invalid_spec()));
  202. + }
  203. +
  204. context->url_requests()->insert(this);
  205. net_log_.BeginEvent(NetLogEventType::REQUEST_ALIVE, [&] {
  206. return NetLogURLRequestConstructorParams(url, priority_,
  207. diff --git a/net/url_request/url_request_context_builder.cc b/net/url_request/url_request_context_builder.cc
  208. index d6f1215fa1..a903fc34f5 100644
  209. --- a/net/url_request/url_request_context_builder.cc
  210. +++ b/net/url_request/url_request_context_builder.cc
  211. @@ -44,6 +44,7 @@
  212. #include "net/quic/quic_stream_factory.h"
  213. #include "net/ssl/ssl_config_service_defaults.h"
  214. #include "net/url_request/static_http_user_agent_settings.h"
  215. +#include "net/url_request/trk_protocol_handler.h"
  216. #include "net/url_request/url_request_context.h"
  217. #include "net/url_request/url_request_context_storage.h"
  218. #include "net/url_request/url_request_job_factory.h"
  219. @@ -605,6 +606,8 @@ std::unique_ptr<URLRequestContext> URLRequestContextBuilder::Build() {
  220. job_factory->SetProtocolHandler(scheme_handler.first,
  221. std::move(scheme_handler.second));
  222. }
  223. + job_factory->SetProtocolHandler(url::kTraceScheme,
  224. + std::make_unique<TrkProtocolHandler>());
  225. protocol_handlers_.clear();
  226. #if !BUILDFLAG(DISABLE_FTP_SUPPORT)
  227. diff --git a/url/url_constants.cc b/url/url_constants.cc
  228. index 69399e4200..23b8312deb 100644
  229. --- a/url/url_constants.cc
  230. +++ b/url/url_constants.cc
  231. @@ -28,6 +28,7 @@ const char kMailToScheme[] = "mailto";
  232. // See also: https://www.iana.org/assignments/uri-schemes/prov/quic-transport
  233. const char kQuicTransportScheme[] = "quic-transport";
  234. const char kTelScheme[] = "tel";
  235. +const char kTraceScheme[] = "trk";
  236. const char kWsScheme[] = "ws";
  237. const char kWssScheme[] = "wss";
  238. diff --git a/url/url_constants.h b/url/url_constants.h
  239. index f5a33dd813..ee66beb50f 100644
  240. --- a/url/url_constants.h
  241. +++ b/url/url_constants.h
  242. @@ -32,6 +32,7 @@ COMPONENT_EXPORT(URL) extern const char kJavaScriptScheme[];
  243. COMPONENT_EXPORT(URL) extern const char kMailToScheme[];
  244. COMPONENT_EXPORT(URL) extern const char kQuicTransportScheme[];
  245. COMPONENT_EXPORT(URL) extern const char kTelScheme[];
  246. +COMPONENT_EXPORT(URL) extern const char kTraceScheme[];
  247. COMPONENT_EXPORT(URL) extern const char kWsScheme[];
  248. COMPONENT_EXPORT(URL) extern const char kWssScheme[];
  249. diff --git a/url/url_util.cc b/url/url_util.cc
  250. index 49cc6e689f..3772cabe28 100644
  251. --- a/url/url_util.cc
  252. +++ b/url/url_util.cc
  253. @@ -34,6 +34,7 @@ struct SchemeRegistry {
  254. std::vector<SchemeWithType> standard_schemes = {
  255. {kHttpsScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION},
  256. {kHttpScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION},
  257. + {kTraceScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION},
  258. // Yes, file URLs can have a hostname, so file URLs should be handled as
  259. // "standard". File URLs never have a port as specified by the SchemeType
  260. // field. Unlike other SCHEME_WITH_HOST schemes, the 'host' in a file
  261. @@ -77,6 +78,7 @@ struct SchemeRegistry {
  262. kAboutScheme,
  263. kJavaScriptScheme,
  264. kDataScheme,
  265. + kTraceScheme,
  266. };
  267. // Schemes that can be sent CORS requests.