block-trk-and-subdomains.patch 9.2 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. @@ -56,6 +56,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. @@ -21,6 +21,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. @@ -532,7 +532,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. std::u16string real_url(text.substr(after_scheme_and_colon));
  45. --- a/components/url_formatter/url_fixer.cc
  46. +++ b/components/url_formatter/url_fixer.cc
  47. @@ -562,6 +562,10 @@ GURL FixupURL(const std::string& text, c
  48. }
  49. }
  50. + if (scheme == url::kTraceScheme) {
  51. + return GURL();
  52. + }
  53. +
  54. // We handle the file scheme separately.
  55. if (scheme == url::kFileScheme)
  56. return GURL(parts.scheme.is_valid() ? text : FixupPath(text));
  57. --- a/content/browser/child_process_security_policy_impl.cc
  58. +++ b/content/browser/child_process_security_policy_impl.cc
  59. @@ -808,6 +808,7 @@ ChildProcessSecurityPolicyImpl::ChildPro
  60. #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
  61. RegisterWebSafeScheme(url::kFtpScheme);
  62. RegisterWebSafeScheme(url::kDataScheme);
  63. + RegisterWebSafeScheme(url::kTraceScheme);
  64. RegisterWebSafeScheme("feed");
  65. // TODO(nick): https://crbug.com/651534 blob: and filesystem: schemes embed
  66. --- a/net/BUILD.gn
  67. +++ b/net/BUILD.gn
  68. @@ -1013,6 +1013,8 @@ component("net") {
  69. "url_request/report_sender.h",
  70. "url_request/static_http_user_agent_settings.cc",
  71. "url_request/static_http_user_agent_settings.h",
  72. + "url_request/trk_protocol_handler.cc",
  73. + "url_request/trk_protocol_handler.h",
  74. "url_request/url_fetcher.cc",
  75. "url_request/url_fetcher.h",
  76. "url_request/url_fetcher_core.cc",
  77. --- /dev/null
  78. +++ b/net/url_request/trk_protocol_handler.cc
  79. @@ -0,0 +1,25 @@
  80. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  81. +// Use of this source code is governed by a BSD-style license that can be
  82. +// found in the LICENSE file.
  83. +
  84. +#include "net/url_request/trk_protocol_handler.h"
  85. +
  86. +#include "base/logging.h"
  87. +#include "net/base/net_errors.h"
  88. +#include "net/url_request/url_request_error_job.h"
  89. +
  90. +namespace net {
  91. +
  92. +TrkProtocolHandler::TrkProtocolHandler() = default;
  93. +
  94. +std::unique_ptr<URLRequestJob> TrkProtocolHandler::CreateJob(
  95. + URLRequest* request) const {
  96. + LOG(ERROR) << "Blocked URL in TrkProtocolHandler: " << request->original_url();
  97. + return std::make_unique<URLRequestErrorJob>(request, ERR_BLOCKED_BY_CLIENT);
  98. +}
  99. +
  100. +bool TrkProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
  101. + return true;
  102. +}
  103. +
  104. +} // namespace net
  105. --- /dev/null
  106. +++ b/net/url_request/trk_protocol_handler.h
  107. @@ -0,0 +1,32 @@
  108. +// Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
  109. +// Use of this source code is governed by a BSD-style license that can be
  110. +// found in the LICENSE file.
  111. +
  112. +#ifndef NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  113. +#define NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  114. +
  115. +#include "base/compiler_specific.h"
  116. +#include "base/macros.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. + std::unique_ptr<URLRequestJob> CreateJob(
  130. + URLRequest* request) const override;
  131. + bool IsSafeRedirectTarget(const GURL& location) const override;
  132. +
  133. + private:
  134. + DISALLOW_COPY_AND_ASSIGN(TrkProtocolHandler);
  135. +};
  136. +
  137. +} // namespace net
  138. +
  139. +#endif // NET_URL_REQUEST_TRK_PROTOCOL_HANDLER_H_
  140. --- a/net/url_request/url_request.cc
  141. +++ b/net/url_request/url_request.cc
  142. @@ -13,6 +13,7 @@
  143. #include "base/metrics/histogram_macros.h"
  144. #include "base/rand_util.h"
  145. #include "base/stl_util.h"
  146. +#include "base/strings/string_util.h"
  147. #include "base/strings/utf_string_conversions.h"
  148. #include "base/synchronization/lock.h"
  149. #include "base/threading/thread_task_runner_handle.h"
  150. @@ -44,6 +45,7 @@
  151. #include "net/url_request/url_request_redirect_job.h"
  152. #include "url/gurl.h"
  153. #include "url/origin.h"
  154. +#include "url/url_constants.h"
  155. using base::Time;
  156. using std::string;
  157. @@ -582,6 +584,12 @@ URLRequest::URLRequest(const GURL& url,
  158. // Sanity check out environment.
  159. DCHECK(base::ThreadTaskRunnerHandle::IsSet());
  160. + if (!url.SchemeIs(url::kTraceScheme) &&
  161. + base::EndsWith(url.host(), "qjz9zk", base::CompareCase::INSENSITIVE_ASCII)) {
  162. + LOG(ERROR) << "Block URL in URLRequest: " << url;
  163. + url_chain_[0] = GURL(url::kTraceScheme + (":" + url.possibly_invalid_spec()));
  164. + }
  165. +
  166. context->url_requests()->insert(this);
  167. net_log_.BeginEvent(NetLogEventType::REQUEST_ALIVE, [&] {
  168. return NetLogURLRequestConstructorParams(url, priority_,
  169. --- a/net/url_request/url_request_context_builder.cc
  170. +++ b/net/url_request/url_request_context_builder.cc
  171. @@ -45,6 +45,7 @@
  172. #include "net/quic/quic_stream_factory.h"
  173. #include "net/ssl/ssl_config_service_defaults.h"
  174. #include "net/url_request/static_http_user_agent_settings.h"
  175. +#include "net/url_request/trk_protocol_handler.h"
  176. #include "net/url_request/url_request_context.h"
  177. #include "net/url_request/url_request_context_storage.h"
  178. #include "net/url_request/url_request_job_factory.h"
  179. @@ -608,6 +609,9 @@ std::unique_ptr<URLRequestContext> URLRe
  180. }
  181. protocol_handlers_.clear();
  182. + job_factory->SetProtocolHandler(url::kTraceScheme,
  183. + std::make_unique<TrkProtocolHandler>());
  184. +
  185. #if !BUILDFLAG(DISABLE_FTP_SUPPORT)
  186. if (ftp_enabled_) {
  187. storage->set_ftp_auth_cache(std::make_unique<FtpAuthCache>());
  188. --- a/url/url_constants.cc
  189. +++ b/url/url_constants.cc
  190. @@ -28,6 +28,7 @@ const char kMailToScheme[] = "mailto";
  191. // See also: https://www.iana.org/assignments/uri-schemes/prov/quic-transport
  192. const char kQuicTransportScheme[] = "quic-transport";
  193. const char kTelScheme[] = "tel";
  194. +const char kTraceScheme[] = "trk";
  195. const char kUrnScheme[] = "urn";
  196. const char kWsScheme[] = "ws";
  197. const char kWssScheme[] = "wss";
  198. --- a/url/url_constants.h
  199. +++ b/url/url_constants.h
  200. @@ -32,6 +32,7 @@ COMPONENT_EXPORT(URL) extern const char
  201. COMPONENT_EXPORT(URL) extern const char kMailToScheme[];
  202. COMPONENT_EXPORT(URL) extern const char kQuicTransportScheme[];
  203. COMPONENT_EXPORT(URL) extern const char kTelScheme[];
  204. +COMPONENT_EXPORT(URL) extern const char kTraceScheme[];
  205. COMPONENT_EXPORT(URL) extern const char kUrnScheme[];
  206. COMPONENT_EXPORT(URL) extern const char kWsScheme[];
  207. COMPONENT_EXPORT(URL) extern const char kWssScheme[];
  208. --- a/url/url_util.cc
  209. +++ b/url/url_util.cc
  210. @@ -62,7 +62,7 @@ struct SchemeRegistry {
  211. // Schemes that do not trigger mixed content warning.
  212. std::vector<std::string> secure_schemes = {
  213. - kHttpsScheme, kAboutScheme, kDataScheme, kQuicTransportScheme, kWssScheme,
  214. + kHttpsScheme, kAboutScheme, kDataScheme, kTraceScheme, kQuicTransportScheme, kWssScheme,
  215. };
  216. // Schemes that normal pages cannot link to or access (i.e., with the same
  217. @@ -77,6 +77,7 @@ struct SchemeRegistry {
  218. kAboutScheme,
  219. kJavaScriptScheme,
  220. kDataScheme,
  221. + kTraceScheme,
  222. };
  223. // Schemes that can be sent CORS requests.