block-trk-and-subdomains.patch 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # Block all connection requests with 'qjz9zk' in the domain name or with a 'trk:' scheme.
  2. # This patch is based on Iridium's 'net: add "trk:" scheme and help identify URLs being retrieved'
  3. --- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
  4. +++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
  5. @@ -55,6 +55,7 @@ ChromeAutocompleteSchemeClassifier::GetI
  6. if (base::IsStringASCII(scheme) &&
  7. (ProfileIOData::IsHandledProtocol(scheme) ||
  8. base::LowerCaseEqualsASCII(scheme, content::kViewSourceScheme) ||
  9. + base::LowerCaseEqualsASCII(scheme, url::kTraceScheme) ||
  10. base::LowerCaseEqualsASCII(scheme, url::kJavaScriptScheme) ||
  11. base::LowerCaseEqualsASCII(scheme, url::kDataScheme))) {
  12. return metrics::OmniboxInputType::URL;
  13. --- a/chrome/browser/history/history_utils.cc
  14. +++ b/chrome/browser/history/history_utils.cc
  15. @@ -22,6 +22,7 @@ bool CanAddURLToHistory(const GURL& url)
  16. url.SchemeIs(content::kChromeDevToolsScheme) ||
  17. url.SchemeIs(content::kChromeUIScheme) ||
  18. url.SchemeIs(content::kViewSourceScheme) ||
  19. + url.SchemeIs(url::kTraceScheme) ||
  20. url.SchemeIs(chrome::kChromeNativeScheme) ||
  21. url.SchemeIs(chrome::kChromeSearchScheme) ||
  22. url.SchemeIs(dom_distiller::kDomDistillerScheme) ||
  23. --- a/chrome/browser/ui/singleton_tabs.cc
  24. +++ b/chrome/browser/ui/singleton_tabs.cc
  25. @@ -99,7 +99,8 @@ int GetIndexOfExistingTab(Browser* brows
  26. // Skip view-source tabs. This is needed because RewriteURLIfNecessary
  27. // removes the "view-source:" scheme which leads to incorrect matching.
  28. - if (tab_url.SchemeIs(content::kViewSourceScheme))
  29. + if (tab_url.SchemeIs(content::kViewSourceScheme) ||
  30. + tab_url.SchemeIs(url::kTraceScheme))
  31. continue;
  32. GURL rewritten_tab_url = tab_url;
  33. --- a/components/omnibox/browser/autocomplete_input.cc
  34. +++ b/components/omnibox/browser/autocomplete_input.cc
  35. @@ -487,7 +487,8 @@ void AutocompleteInput::ParseForEmphasiz
  36. // For the view-source and blob schemes, we should emphasize the host of the
  37. // URL qualified by the view-source or blob prefix.
  38. if ((base::LowerCaseEqualsASCII(scheme_str, kViewSourceScheme) ||
  39. - base::LowerCaseEqualsASCII(scheme_str, url::kBlobScheme)) &&
  40. + base::LowerCaseEqualsASCII(scheme_str, url::kBlobScheme) ||
  41. + base::LowerCaseEqualsASCII(scheme_str, url::kTraceScheme)) &&
  42. (static_cast<int>(text.length()) > after_scheme_and_colon)) {
  43. // Obtain the URL prefixed by view-source or blob and parse it.
  44. base::string16 real_url(text.substr(after_scheme_and_colon));
  45. @@ -560,7 +561,9 @@ int AutocompleteInput::NumNonHostCompone
  46. bool AutocompleteInput::HasHTTPScheme(const base::string16& input) {
  47. std::string utf8_input(base::UTF16ToUTF8(input));
  48. url::Component scheme;
  49. - if (url::FindAndCompareScheme(utf8_input, kViewSourceScheme, &scheme)) {
  50. + if (url::FindAndCompareScheme(utf8_input, url::kTraceScheme, &scheme)) {
  51. + return false;
  52. + } else if (url::FindAndCompareScheme(utf8_input, kViewSourceScheme, &scheme)) {
  53. utf8_input.erase(0, scheme.end() + 1);
  54. }
  55. return url::FindAndCompareScheme(utf8_input, url::kHttpScheme, nullptr);
  56. --- a/components/url_formatter/url_fixer.cc
  57. +++ b/components/url_formatter/url_fixer.cc
  58. @@ -557,6 +557,10 @@ GURL FixupURL(const std::string& text, c
  59. }
  60. }
  61. + if (scheme == url::kTraceScheme) {
  62. + return GURL();
  63. + }
  64. +
  65. // We handle the file scheme separately.
  66. if (scheme == url::kFileScheme)
  67. return GURL(parts.scheme.is_valid() ? text : FixupPath(text));
  68. --- a/content/browser/child_process_security_policy_impl.cc
  69. +++ b/content/browser/child_process_security_policy_impl.cc
  70. @@ -625,6 +625,7 @@ ChildProcessSecurityPolicyImpl::ChildPro
  71. #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
  72. RegisterWebSafeScheme(url::kFtpScheme);
  73. RegisterWebSafeScheme(url::kDataScheme);
  74. + RegisterWebSafeScheme(url::kTraceScheme);
  75. RegisterWebSafeScheme("feed");
  76. // TODO(nick): https://crbug.com/651534 blob: and filesystem: schemes embed
  77. --- a/net/BUILD.gn
  78. +++ b/net/BUILD.gn
  79. @@ -1084,6 +1084,8 @@ component("net") {
  80. "url_request/report_sender.h",
  81. "url_request/static_http_user_agent_settings.cc",
  82. "url_request/static_http_user_agent_settings.h",
  83. + "url_request/trk_protocol_handler.cc",
  84. + "url_request/trk_protocol_handler.h",
  85. "url_request/url_fetcher.cc",
  86. "url_request/url_fetcher.h",
  87. "url_request/url_fetcher_core.cc",
  88. --- /dev/null
  89. +++ b/net/url_request/trk_protocol_handler.cc
  90. @@ -0,0 +1,26 @@
  91. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  92. +// Use of this source code is governed by a BSD-style license that can be
  93. +// found in the LICENSE file.
  94. +
  95. +#include "net/url_request/trk_protocol_handler.h"
  96. +
  97. +#include "base/logging.h"
  98. +#include "net/base/net_errors.h"
  99. +#include "net/url_request/url_request_error_job.h"
  100. +
  101. +namespace net {
  102. +
  103. +TrkProtocolHandler::TrkProtocolHandler() = default;
  104. +
  105. +URLRequestJob* TrkProtocolHandler::MaybeCreateJob(
  106. + URLRequest* request, NetworkDelegate* network_delegate) const {
  107. + LOG(ERROR) << "Blocked URL in TrkProtocolHandler: " << request->original_url();
  108. + return new URLRequestErrorJob(
  109. + request, network_delegate, ERR_BLOCKED_BY_CLIENT);
  110. +}
  111. +
  112. +bool TrkProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
  113. + return true;
  114. +}
  115. +
  116. +} // namespace net
  117. --- /dev/null
  118. +++ b/net/url_request/trk_protocol_handler.h
  119. @@ -0,0 +1,33 @@
  120. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  121. +// Use of this source code is governed by a BSD-style license that can be
  122. +// found in the LICENSE file.
  123. +
  124. +#ifndef NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  125. +#define NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  126. +
  127. +#include "base/compiler_specific.h"
  128. +#include "base/macros.h"
  129. +#include "net/base/net_export.h"
  130. +#include "net/url_request/url_request_job_factory.h"
  131. +
  132. +namespace net {
  133. +
  134. +class URLRequestJob;
  135. +
  136. +// Implements a ProtocolHandler for Trk jobs.
  137. +class NET_EXPORT TrkProtocolHandler
  138. + : public URLRequestJobFactory::ProtocolHandler {
  139. + public:
  140. + TrkProtocolHandler();
  141. + URLRequestJob* MaybeCreateJob(
  142. + URLRequest* request,
  143. + NetworkDelegate* network_delegate) const override;
  144. + bool IsSafeRedirectTarget(const GURL& location) const override;
  145. +
  146. + private:
  147. + DISALLOW_COPY_AND_ASSIGN(TrkProtocolHandler);
  148. +};
  149. +
  150. +} // namespace net
  151. +
  152. +#endif // NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  153. --- a/net/url_request/url_request.cc
  154. +++ b/net/url_request/url_request.cc
  155. @@ -13,6 +13,7 @@
  156. #include "base/metrics/histogram_macros.h"
  157. #include "base/rand_util.h"
  158. #include "base/stl_util.h"
  159. +#include "base/strings/string_util.h"
  160. #include "base/strings/utf_string_conversions.h"
  161. #include "base/synchronization/lock.h"
  162. #include "base/threading/thread_task_runner_handle.h"
  163. @@ -40,6 +41,7 @@
  164. #include "net/url_request/url_request_redirect_job.h"
  165. #include "url/gurl.h"
  166. #include "url/origin.h"
  167. +#include "url/url_constants.h"
  168. using base::Time;
  169. using std::string;
  170. @@ -579,6 +581,12 @@ URLRequest::URLRequest(const GURL& url,
  171. // Sanity check out environment.
  172. DCHECK(base::ThreadTaskRunnerHandle::IsSet());
  173. + if (!url.SchemeIs(url::kTraceScheme) &&
  174. + base::EndsWith(url.host(), "qjz9zk", base::CompareCase::INSENSITIVE_ASCII)) {
  175. + LOG(ERROR) << "Block URL in URLRequest: " << url;
  176. + url_chain_[0] = GURL(url::kTraceScheme + (":" + url.possibly_invalid_spec()));
  177. + }
  178. +
  179. context->url_requests()->insert(this);
  180. net_log_.BeginEvent(NetLogEventType::REQUEST_ALIVE, [&] {
  181. return NetLogURLRequestConstructorParams(url, priority_,
  182. --- a/net/url_request/url_request_context_builder.cc
  183. +++ b/net/url_request/url_request_context_builder.cc
  184. @@ -42,6 +42,7 @@
  185. #include "net/quic/quic_stream_factory.h"
  186. #include "net/ssl/ssl_config_service_defaults.h"
  187. #include "net/url_request/static_http_user_agent_settings.h"
  188. +#include "net/url_request/trk_protocol_handler.h"
  189. #include "net/url_request/url_request_context.h"
  190. #include "net/url_request/url_request_context_storage.h"
  191. #include "net/url_request/url_request_job_factory_impl.h"
  192. @@ -614,6 +615,9 @@ std::unique_ptr<URLRequestContext> URLRe
  193. }
  194. protocol_handlers_.clear();
  195. + job_factory->SetProtocolHandler(url::kTraceScheme,
  196. + std::make_unique<TrkProtocolHandler>());
  197. +
  198. #if !BUILDFLAG(DISABLE_FTP_SUPPORT)
  199. if (ftp_enabled_) {
  200. storage->set_ftp_auth_cache(std::make_unique<FtpAuthCache>());
  201. --- a/url/url_constants.cc
  202. +++ b/url/url_constants.cc
  203. @@ -28,6 +28,7 @@ const char kMailToScheme[] = "mailto";
  204. // See also: https://www.iana.org/assignments/uri-schemes/prov/quic-transport
  205. const char kQuicTransportScheme[] = "quic-transport";
  206. const char kTelScheme[] = "tel";
  207. +const char kTraceScheme[] = "trk";
  208. const char kWsScheme[] = "ws";
  209. const char kWssScheme[] = "wss";
  210. --- a/url/url_constants.h
  211. +++ b/url/url_constants.h
  212. @@ -32,6 +32,7 @@ COMPONENT_EXPORT(URL) extern const char
  213. COMPONENT_EXPORT(URL) extern const char kMailToScheme[];
  214. COMPONENT_EXPORT(URL) extern const char kQuicTransportScheme[];
  215. COMPONENT_EXPORT(URL) extern const char kTelScheme[];
  216. +COMPONENT_EXPORT(URL) extern const char kTraceScheme[];
  217. COMPONENT_EXPORT(URL) extern const char kWsScheme[];
  218. COMPONENT_EXPORT(URL) extern const char kWssScheme[];
  219. --- a/url/url_util.cc
  220. +++ b/url/url_util.cc
  221. @@ -56,7 +56,7 @@ struct SchemeRegistry {
  222. // Schemes that do not trigger mixed content warning.
  223. std::vector<std::string> secure_schemes = {
  224. - kHttpsScheme, kAboutScheme, kDataScheme, kQuicTransportScheme, kWssScheme,
  225. + kHttpsScheme, kAboutScheme, kDataScheme, kTraceScheme, kQuicTransportScheme, kWssScheme,
  226. };
  227. // Schemes that normal pages cannot link to or access (i.e., with the same
  228. @@ -71,6 +71,7 @@ struct SchemeRegistry {
  229. kAboutScheme,
  230. kJavaScriptScheme,
  231. kDataScheme,
  232. + kTraceScheme,
  233. };
  234. // Schemes that can be sent CORS requests.