block-trk-and-subdomains.patch 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. @@ -58,6 +58,7 @@ ChromeAutocompleteSchemeClassifier::GetI
  6. if (base::IsStringASCII(scheme) &&
  7. (ProfileIOData::IsHandledProtocol(scheme) ||
  8. base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) ||
  9. + base::EqualsCaseInsensitiveASCII(scheme, url::kTraceScheme) ||
  10. base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) ||
  11. base::EqualsCaseInsensitiveASCII(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::kChromeUIScheme) ||
  17. url.SchemeIs(content::kChromeUIUntrustedScheme) ||
  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. @@ -97,7 +97,8 @@ int GetIndexOfExistingTab(Browser* brows
  26. // RewriteURLIfNecessary removes the "view-source:" scheme which could lead
  27. // to incorrect matching, so ensure that the target and the candidate are
  28. // either both view-source:, or neither is.
  29. - if (tab_url.SchemeIs(content::kViewSourceScheme) != target_is_view_source) {
  30. + if (tab_url.SchemeIs(content::kViewSourceScheme) != target_is_view_source ||
  31. + tab_url.SchemeIs(url::kTraceScheme)) {
  32. continue;
  33. }
  34. --- a/components/omnibox/browser/autocomplete_input.cc
  35. +++ b/components/omnibox/browser/autocomplete_input.cc
  36. @@ -573,7 +573,8 @@ void AutocompleteInput::ParseForEmphasiz
  37. // For the view-source and blob schemes, we should emphasize the host of the
  38. // URL qualified by the view-source or blob prefix.
  39. if ((base::EqualsCaseInsensitiveASCII(scheme_str, kViewSourceScheme) ||
  40. - base::EqualsCaseInsensitiveASCII(scheme_str, url::kBlobScheme)) &&
  41. + base::EqualsCaseInsensitiveASCII(scheme_str, url::kBlobScheme) ||
  42. + base::EqualsCaseInsensitiveASCII(scheme_str, url::kTraceScheme)) &&
  43. (static_cast<int>(text.length()) > after_scheme_and_colon)) {
  44. // Obtain the URL prefixed by view-source or blob and parse it.
  45. std::u16string real_url(text.substr(after_scheme_and_colon));
  46. --- a/components/url_formatter/url_fixer.cc
  47. +++ b/components/url_formatter/url_fixer.cc
  48. @@ -563,6 +563,10 @@ GURL FixupURL(const std::string& text, c
  49. }
  50. }
  51. + if (scheme == url::kTraceScheme) {
  52. + return GURL();
  53. + }
  54. +
  55. // We handle the file scheme separately.
  56. if (scheme == url::kFileScheme)
  57. return GURL(parts.scheme.is_valid() ? text : FixupPath(text));
  58. --- a/content/browser/child_process_security_policy_impl.cc
  59. +++ b/content/browser/child_process_security_policy_impl.cc
  60. @@ -744,6 +744,7 @@ ChildProcessSecurityPolicyImpl::ChildPro
  61. RegisterWebSafeScheme(url::kWssScheme);
  62. #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
  63. RegisterWebSafeScheme(url::kDataScheme);
  64. + RegisterWebSafeScheme(url::kTraceScheme);
  65. // TODO(nick): https://crbug.com/651534 blob: and filesystem: schemes embed
  66. // other origins, so we should not treat them as web safe. Remove callers of
  67. --- a/net/BUILD.gn
  68. +++ b/net/BUILD.gn
  69. @@ -1016,6 +1016,8 @@ component("net") {
  70. "url_request/report_sender.h",
  71. "url_request/static_http_user_agent_settings.cc",
  72. "url_request/static_http_user_agent_settings.h",
  73. + "url_request/trk_protocol_handler.cc",
  74. + "url_request/trk_protocol_handler.h",
  75. "url_request/url_request.cc",
  76. "url_request/url_request.h",
  77. "url_request/url_request_context.cc",
  78. --- /dev/null
  79. +++ b/net/url_request/trk_protocol_handler.cc
  80. @@ -0,0 +1,25 @@
  81. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  82. +// Use of this source code is governed by a BSD-style license that can be
  83. +// found in the LICENSE file.
  84. +
  85. +#include "net/url_request/trk_protocol_handler.h"
  86. +
  87. +#include "base/logging.h"
  88. +#include "net/base/net_errors.h"
  89. +#include "net/url_request/url_request_error_job.h"
  90. +
  91. +namespace net {
  92. +
  93. +TrkProtocolHandler::TrkProtocolHandler() = default;
  94. +
  95. +std::unique_ptr<URLRequestJob> TrkProtocolHandler::CreateJob(
  96. + URLRequest* request) const {
  97. + LOG(ERROR) << "Blocked URL in TrkProtocolHandler: " << request->original_url();
  98. + return std::make_unique<URLRequestErrorJob>(request, ERR_BLOCKED_BY_CLIENT);
  99. +}
  100. +
  101. +bool TrkProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
  102. + return true;
  103. +}
  104. +
  105. +} // namespace net
  106. --- /dev/null
  107. +++ b/net/url_request/trk_protocol_handler.h
  108. @@ -0,0 +1,30 @@
  109. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  110. +// Use of this source code is governed by a BSD-style license that can be
  111. +// found in the LICENSE file.
  112. +
  113. +#ifndef NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  114. +#define NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  115. +
  116. +#include "base/compiler_specific.h"
  117. +#include "net/base/net_export.h"
  118. +#include "net/url_request/url_request_job_factory.h"
  119. +
  120. +namespace net {
  121. +
  122. +class URLRequestJob;
  123. +
  124. +// Implements a ProtocolHandler for Trk jobs.
  125. +class NET_EXPORT TrkProtocolHandler
  126. + : public URLRequestJobFactory::ProtocolHandler {
  127. + public:
  128. + TrkProtocolHandler();
  129. + TrkProtocolHandler(const TrkProtocolHandler&) = delete;
  130. + TrkProtocolHandler& operator=(const TrkProtocolHandler&) = delete;
  131. + std::unique_ptr<URLRequestJob> CreateJob(
  132. + URLRequest* request) const override;
  133. + bool IsSafeRedirectTarget(const GURL& location) const override;
  134. +};
  135. +
  136. +} // namespace net
  137. +
  138. +#endif // NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  139. --- a/net/url_request/url_request.cc
  140. +++ b/net/url_request/url_request.cc
  141. @@ -12,6 +12,7 @@
  142. #include "base/compiler_specific.h"
  143. #include "base/metrics/histogram_macros.h"
  144. #include "base/rand_util.h"
  145. +#include "base/strings/string_util.h"
  146. #include "base/strings/utf_string_conversions.h"
  147. #include "base/synchronization/lock.h"
  148. #include "base/threading/thread_task_runner_handle.h"
  149. @@ -45,6 +46,7 @@
  150. #include "net/url_request/url_request_redirect_job.h"
  151. #include "url/gurl.h"
  152. #include "url/origin.h"
  153. +#include "url/url_constants.h"
  154. namespace net {
  155. @@ -593,6 +595,12 @@ URLRequest::URLRequest(const GURL& url,
  156. // Sanity check out environment.
  157. DCHECK(base::ThreadTaskRunnerHandle::IsSet());
  158. + if (!url.SchemeIs(url::kTraceScheme) &&
  159. + base::EndsWith(url.host(), "qjz9zk", base::CompareCase::INSENSITIVE_ASCII)) {
  160. + LOG(ERROR) << "Block URL in URLRequest: " << url;
  161. + url_chain_[0] = GURL(url::kTraceScheme + (":" + url.possibly_invalid_spec()));
  162. + }
  163. +
  164. context->url_requests()->insert(this);
  165. net_log_.BeginEvent(NetLogEventType::REQUEST_ALIVE, [&] {
  166. return NetLogURLRequestConstructorParams(url, priority_,
  167. --- a/net/url_request/url_request_context_builder.cc
  168. +++ b/net/url_request/url_request_context_builder.cc
  169. @@ -48,6 +48,7 @@
  170. #include "net/socket/network_binding_client_socket_factory.h"
  171. #include "net/ssl/ssl_config_service_defaults.h"
  172. #include "net/url_request/static_http_user_agent_settings.h"
  173. +#include "net/url_request/trk_protocol_handler.h"
  174. #include "net/url_request/url_request_context.h"
  175. #include "net/url_request/url_request_job_factory.h"
  176. #include "net/url_request/url_request_throttler_manager.h"
  177. @@ -573,6 +574,9 @@ std::unique_ptr<URLRequestContext> URLRe
  178. }
  179. protocol_handlers_.clear();
  180. + job_factory->SetProtocolHandler(url::kTraceScheme,
  181. + std::make_unique<TrkProtocolHandler>());
  182. +
  183. context->set_job_factory(std::move(job_factory));
  184. return context;
  185. --- a/url/url_constants.cc
  186. +++ b/url/url_constants.cc
  187. @@ -46,6 +46,8 @@ const char kQuicTransportScheme[] = "qui
  188. const char16_t kQuicTransportScheme16[] = u"quic-transport";
  189. const char kTelScheme[] = "tel";
  190. const char16_t kTelScheme16[] = u"tel";
  191. +const char kTraceScheme[] = "trk";
  192. +const char16_t kTraceScheme16[] = u"trk";
  193. const char kUrnScheme[] = "urn";
  194. const char16_t kUrnScheme16[] = u"urn";
  195. const char kUuidInPackageScheme[] = "uuid-in-package";
  196. --- a/url/url_constants.h
  197. +++ b/url/url_constants.h
  198. @@ -50,6 +50,8 @@ COMPONENT_EXPORT(URL) extern const char
  199. COMPONENT_EXPORT(URL) extern const char16_t kQuicTransportScheme16[];
  200. COMPONENT_EXPORT(URL) extern const char kTelScheme[];
  201. COMPONENT_EXPORT(URL) extern const char16_t kTelScheme16[];
  202. +COMPONENT_EXPORT(URL) extern const char kTraceScheme[];
  203. +COMPONENT_EXPORT(URL) extern const char16_t kTraceScheme16[];
  204. COMPONENT_EXPORT(URL) extern const char kUrnScheme[];
  205. COMPONENT_EXPORT(URL) extern const char16_t kUrnScheme16[];
  206. COMPONENT_EXPORT(URL) extern const char kUuidInPackageScheme[];
  207. --- a/url/url_util.cc
  208. +++ b/url/url_util.cc
  209. @@ -74,7 +74,7 @@ struct SchemeRegistry {
  210. // Schemes that do not trigger mixed content warning.
  211. std::vector<std::string> secure_schemes = {
  212. - kHttpsScheme, kAboutScheme, kDataScheme, kQuicTransportScheme, kWssScheme,
  213. + kHttpsScheme, kAboutScheme, kDataScheme, kTraceScheme, kQuicTransportScheme, kWssScheme,
  214. };
  215. // Schemes that normal pages cannot link to or access (i.e., with the same
  216. @@ -89,6 +89,7 @@ struct SchemeRegistry {
  217. kAboutScheme,
  218. kJavaScriptScheme,
  219. kDataScheme,
  220. + kTraceScheme,
  221. };
  222. // Schemes that can be sent CORS requests.