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