summaryrefslogtreecommitdiff
path: root/www/chromium-uc/patches/extra/bromite/fingerprinting-flags-client-rects-and-measuretext.patch
diff options
context:
space:
mode:
Diffstat (limited to 'www/chromium-uc/patches/extra/bromite/fingerprinting-flags-client-rects-and-measuretext.patch')
-rw-r--r--www/chromium-uc/patches/extra/bromite/fingerprinting-flags-client-rects-and-measuretext.patch325
1 files changed, 325 insertions, 0 deletions
diff --git a/www/chromium-uc/patches/extra/bromite/fingerprinting-flags-client-rects-and-measuretext.patch b/www/chromium-uc/patches/extra/bromite/fingerprinting-flags-client-rects-and-measuretext.patch
new file mode 100644
index 0000000..2d6821f
--- /dev/null
+++ b/www/chromium-uc/patches/extra/bromite/fingerprinting-flags-client-rects-and-measuretext.patch
@@ -0,0 +1,325 @@
1# Adds two flags:
2# 1. --fingerprinting-client-rects-noise to enable fingerprinting deception for Range::getClientRects and Element::getBoundingClientRect
3# 2. --fingerprinting-canvas-measuretext-noise to enable fingerprinting deception for Canvas::measureText
4# Tweaks based on https://github.com/bromite/bromite/blob/b1bc96bbd9ec549cf496e87f487a0ac35c83df0a/patches/BRM052_getClientRects-getBoundingClientRect-measureText-add-fingerprinting-mitigation.patch
5# Originally based on https://github.com/Eloston/ungoogled-chromium/pull/377/commits/4151259b3248f0fc5c42fa262a1d1dd43c39fb60
6# chrome://flag setting added by ungoogled-chromium developers
7#
8# Unlike the latest Bromite patch, it was chosen to not regenerate the noise value each time the value is read to prevent potential efficiency issues with the load on the RNG.
9
10--- chrome/browser/BUILD.gn.orig
11+++ chrome/browser/BUILD.gn
12@@ -2370,6 +2370,7 @@ static_library("browser") {
13 "//third_party/libyuv",
14 "//third_party/metrics_proto",
15 "//third_party/re2",
16+ "//components/ungoogled:ungoogled_switches",
17 "//third_party/webrtc_overrides:webrtc_component",
18 "//third_party/widevine/cdm:buildflags",
19 "//third_party/widevine/cdm:headers",
20--- chrome/browser/about_flags.cc.orig
21+++ chrome/browser/about_flags.cc
22@@ -151,6 +151,7 @@
23 #include "components/translate/core/browser/translate_ranker_impl.h"
24 #include "components/translate/core/common/translate_util.h"
25 #include "components/ui_devtools/switches.h"
26+#include "components/ungoogled/ungoogled_switches.h"
27 #include "components/version_info/version_info.h"
28 #include "components/viz/common/features.h"
29 #include "components/viz/common/switches.h"
30--- chrome/browser/bromite_flag_entries.h.orig
31+++ chrome/browser/bromite_flag_entries.h
32@@ -4,4 +4,12 @@
33
34 #ifndef CHROME_BROWSER_BROMITE_FLAG_ENTRIES_H_
35 #define CHROME_BROWSER_BROMITE_FLAG_ENTRIES_H_
36+ {"fingerprinting-client-rects-noise",
37+ "Enable get*ClientRects() fingerprint deception",
38+ "Scale the output values of Range::getClientRects() and Element::getBoundingClientRect() with a randomly selected factor in the range -0.0003% to 0.0003%, which are recomputed on every document initialization. ungoogled-chromium flag, Bromite feature.",
39+ kOsAll, SINGLE_VALUE_TYPE(switches::kFingerprintingClientRectsNoise)},
40+ {"fingerprinting-canvas-measuretext-noise",
41+ "Enable Canvas::measureText() fingerprint deception",
42+ "Scale the output values of Canvas::measureText() with a randomly selected factor in the range -0.0003% to 0.0003%, which are recomputed on every document initialization. ungoogled-chromium flag, Bromite feature.",
43+ kOsAll, SINGLE_VALUE_TYPE(switches::kFingerprintingCanvasMeasureTextNoise)},
44 #endif // CHROME_BROWSER_BROMITE_FLAG_ENTRIES_H_
45--- content/browser/BUILD.gn.orig
46+++ content/browser/BUILD.gn
47@@ -222,6 +222,7 @@ source_set("browser") {
48 "//third_party/libyuv",
49 "//third_party/re2",
50 "//third_party/sqlite",
51+ "//components/ungoogled:ungoogled_switches",
52 "//third_party/webrtc_overrides:webrtc_component",
53 "//third_party/wtl",
54 "//third_party/zlib",
55--- content/browser/renderer_host/render_process_host_impl.cc.orig
56+++ content/browser/renderer_host/render_process_host_impl.cc
57@@ -68,6 +68,7 @@
58 #include "components/services/storage/public/mojom/cache_storage_control.mojom.h"
59 #include "components/services/storage/public/mojom/indexed_db_control.mojom.h"
60 #include "components/tracing/common/tracing_switches.h"
61+#include "components/ungoogled/ungoogled_switches.h"
62 #include "components/viz/common/switches.h"
63 #include "components/viz/host/gpu_client.h"
64 #include "content/browser/bad_message.h"
65@@ -3465,6 +3466,8 @@ void RenderProcessHostImpl::PropagateBro
66 switches::kEnableWebGLDraftExtensions,
67 switches::kEnableWebGLImageChromium,
68 switches::kFileUrlPathAlias,
69+ switches::kFingerprintingClientRectsNoise,
70+ switches::kFingerprintingCanvasMeasureTextNoise,
71 switches::kForceDeviceScaleFactor,
72 switches::kForceDisplayColorProfile,
73 switches::kForceGpuMemAvailableMb,
74--- content/child/BUILD.gn.orig
75+++ content/child/BUILD.gn
76@@ -103,6 +103,7 @@ target(link_target_type, "child") {
77 "//third_party/blink/public/common",
78 "//third_party/blink/public/strings",
79 "//third_party/ced",
80+ "//components/ungoogled:ungoogled_switches",
81 "//third_party/zlib/google:compression_utils",
82 "//ui/base",
83 "//ui/events/blink",
84--- content/child/runtime_features.cc.orig
85+++ content/child/runtime_features.cc
86@@ -31,6 +31,7 @@
87 #include "third_party/blink/public/common/loader/referrer_utils.h"
88 #include "third_party/blink/public/common/switches.h"
89 #include "third_party/blink/public/platform/web_runtime_features.h"
90+#include "components/ungoogled/ungoogled_switches.h"
91 #include "ui/accessibility/accessibility_features.h"
92 #include "ui/base/ui_base_features.h"
93 #include "ui/events/blink/blink_features.h"
94@@ -466,6 +467,10 @@ void SetRuntimeFeaturesFromCommandLine(c
95 {wrf::EnableWebGPU, switches::kEnableUnsafeWebGPU, true},
96 {wrf::ForceOverlayFullscreenVideo, switches::kForceOverlayFullscreenVideo,
97 true},
98+ {wrf::EnableFingerprintingClientRectsNoise,
99+ switches::kFingerprintingClientRectsNoise, true},
100+ {wrf::EnableFingerprintingCanvasMeasureTextNoise,
101+ switches::kFingerprintingCanvasMeasureTextNoise, true},
102 };
103 for (const auto& mapping : switchToFeatureMapping) {
104 if (command_line.HasSwitch(mapping.switch_name))
105--- third_party/blink/public/platform/web_runtime_features.h.orig
106+++ third_party/blink/public/platform/web_runtime_features.h
107@@ -218,6 +218,8 @@ class WebRuntimeFeatures {
108 BLINK_PLATFORM_EXPORT static void EnableMediaControlsExpandGesture(bool);
109 BLINK_PLATFORM_EXPORT static void EnableGetDisplayMedia(bool);
110 BLINK_PLATFORM_EXPORT static void EnableAllowSyncXHRInPageDismissal(bool);
111+ BLINK_PLATFORM_EXPORT static void EnableFingerprintingClientRectsNoise(bool);
112+ BLINK_PLATFORM_EXPORT static void EnableFingerprintingCanvasMeasureTextNoise(bool);
113 BLINK_PLATFORM_EXPORT static void EnableSignedExchangeSubresourcePrefetch(
114 bool);
115 BLINK_PLATFORM_EXPORT static void EnableSubresourceWebBundles(bool);
116--- third_party/blink/renderer/core/dom/document.cc.orig
117+++ third_party/blink/renderer/core/dom/document.cc
118@@ -42,6 +42,7 @@
119 #include "base/containers/contains.h"
120 #include "base/debug/dump_without_crashing.h"
121 #include "base/metrics/histogram_functions.h"
122+#include "base/rand_util.h"
123 #include "base/time/time.h"
124 #include "cc/input/overscroll_behavior.h"
125 #include "cc/input/scroll_snap_data.h"
126@@ -855,6 +856,14 @@ Range* Document::CreateRangeAdjustedToTr
127 Position::BeforeNode(*shadow_host));
128 }
129
130+double Document::GetNoiseFactorX() {
131+ return noise_factor_x_;
132+}
133+
134+double Document::GetNoiseFactorY() {
135+ return noise_factor_y_;
136+}
137+
138 SelectorQueryCache& Document::GetSelectorQueryCache() {
139 if (!selector_query_cache_)
140 selector_query_cache_ = std::make_unique<SelectorQueryCache>();
141@@ -2145,6 +2154,15 @@ void Document::UpdateStyleAndLayoutTreeF
142 #if DCHECK_IS_ON()
143 AssertLayoutTreeUpdated(*this, true /* allow_dirty_container_subtrees */);
144 #endif
145+
146+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
147+ // Precompute -0.0003% to 0.0003% noise factor for get*ClientRect*() fingerprinting
148+ noise_factor_x_ = 1 + (base::RandDouble() - 0.5) * 0.000003;
149+ noise_factor_y_ = 1 + (base::RandDouble() - 0.5) * 0.000003;
150+ } else {
151+ noise_factor_x_ = 1;
152+ noise_factor_y_ = 1;
153+ }
154 }
155
156 void Document::InvalidateStyleAndLayoutForFontUpdates() {
157--- third_party/blink/renderer/core/dom/document.h.orig
158+++ third_party/blink/renderer/core/dom/document.h
159@@ -456,6 +456,10 @@ class CORE_EXPORT Document : public Cont
160 has_xml_declaration_ = has_xml_declaration ? 1 : 0;
161 }
162
163+ // Values for get*ClientRect fingerprint deception
164+ double GetNoiseFactorX();
165+ double GetNoiseFactorY();
166+
167 AtomicString visibilityState() const;
168 bool IsPageVisible() const;
169 bool hidden() const;
170@@ -2078,6 +2082,9 @@ class CORE_EXPORT Document : public Cont
171
172 base::ElapsedTimer start_time_;
173
174+ double noise_factor_x_;
175+ double noise_factor_y_;
176+
177 Member<ScriptRunner> script_runner_;
178
179 HeapVector<Member<ScriptElementBase>> current_script_stack_;
180--- third_party/blink/renderer/core/dom/element.cc.orig
181+++ third_party/blink/renderer/core/dom/element.cc
182@@ -2114,6 +2114,11 @@ DOMRectList* Element::getClientRects() {
183 DCHECK(element_layout_object);
184 GetDocument().AdjustFloatQuadsForScrollAndAbsoluteZoom(
185 quads, *element_layout_object);
186+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
187+ for (FloatQuad& quad : quads) {
188+ quad.Scale(GetDocument().GetNoiseFactorX(), GetDocument().GetNoiseFactorY());
189+ }
190+ }
191 return MakeGarbageCollected<DOMRectList>(quads);
192 }
193
194@@ -2131,6 +2136,9 @@ FloatRect Element::GetBoundingClientRect
195 DCHECK(element_layout_object);
196 GetDocument().AdjustFloatRectForScrollAndAbsoluteZoom(result,
197 *element_layout_object);
198+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
199+ result.Scale(GetDocument().GetNoiseFactorX(), GetDocument().GetNoiseFactorY());
200+ }
201 return result;
202 }
203
204--- third_party/blink/renderer/core/dom/range.cc.orig
205+++ third_party/blink/renderer/core/dom/range.cc
206@@ -1598,11 +1598,21 @@ DOMRectList* Range::getClientRects() con
207 Vector<FloatQuad> quads;
208 GetBorderAndTextQuads(quads);
209
210+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
211+ for (FloatQuad& quad : quads) {
212+ quad.Scale(owner_document_->GetNoiseFactorX(), owner_document_->GetNoiseFactorY());
213+ }
214+ }
215+
216 return MakeGarbageCollected<DOMRectList>(quads);
217 }
218
219 DOMRect* Range::getBoundingClientRect() const {
220- return DOMRect::FromFloatRect(BoundingRect());
221+ auto rect = BoundingRect();
222+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
223+ rect.Scale(owner_document_->GetNoiseFactorX(), owner_document_->GetNoiseFactorY());
224+ }
225+ return DOMRect::FromFloatRect(rect);
226 }
227
228 // TODO(editing-dev): We should make
229--- third_party/blink/renderer/core/html/canvas/text_metrics.cc.orig
230+++ third_party/blink/renderer/core/html/canvas/text_metrics.cc
231@@ -55,6 +55,24 @@ TextMetrics::TextMetrics(const Font& fon
232 Update(font, direction, baseline, align, text);
233 }
234
235+void TextMetrics::Shuffle(const double factor) {
236+ // x-direction
237+ width_ *= factor;
238+ actual_bounding_box_left_ *= factor;
239+ actual_bounding_box_right_ *= factor;
240+
241+ // y-direction
242+ font_bounding_box_ascent_ *= factor;
243+ font_bounding_box_descent_ *= factor;
244+ actual_bounding_box_ascent_ *= factor;
245+ actual_bounding_box_descent_ *= factor;
246+ em_height_ascent_ *= factor;
247+ em_height_descent_ *= factor;
248+ baselines_->setAlphabetic(baselines_->alphabetic() * factor);
249+ baselines_->setHanging(baselines_->hanging() * factor);
250+ baselines_->setIdeographic(baselines_->ideographic() * factor);
251+}
252+
253 void TextMetrics::Update(const Font& font,
254 const TextDirection& direction,
255 const TextBaseline& baseline,
256--- third_party/blink/renderer/core/html/canvas/text_metrics.h.orig
257+++ third_party/blink/renderer/core/html/canvas/text_metrics.h
258@@ -64,6 +64,8 @@ class CORE_EXPORT TextMetrics final : pu
259
260 void Trace(Visitor*) const override;
261
262+ void Shuffle(const double factor);
263+
264 private:
265 void Update(const Font&,
266 const TextDirection&,
267--- third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc.orig
268+++ third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc
269@@ -912,9 +912,15 @@ TextMetrics* CanvasRenderingContext2D::m
270 TextDirection direction =
271 ToTextDirection(GetState().GetDirection(), canvas());
272
273- return MakeGarbageCollected<TextMetrics>(font, direction,
274+ TextMetrics* text_metrics = MakeGarbageCollected<TextMetrics>(font, direction,
275 GetState().GetTextBaseline(),
276 GetState().GetTextAlign(), text);
277+
278+ // Scale text metrics if enabled
279+ if (RuntimeEnabledFeatures::FingerprintingCanvasMeasureTextNoiseEnabled()) {
280+ text_metrics->Shuffle(canvas()->GetDocument().GetNoiseFactorX());
281+ }
282+ return text_metrics;
283 }
284
285 void CanvasRenderingContext2D::fillFormattedText(
286--- third_party/blink/renderer/platform/BUILD.gn.orig
287+++ third_party/blink/renderer/platform/BUILD.gn
288@@ -1686,6 +1686,7 @@ component("platform") {
289 "//components/paint_preview/common",
290 "//components/power_scheduler",
291 "//components/search_engines:search_engine_utils",
292+ "//components/ungoogled:ungoogled_switches",
293 "//components/viz/client",
294 "//components/viz/common",
295 "//crypto",
296--- third_party/blink/renderer/platform/exported/web_runtime_features.cc.orig
297+++ third_party/blink/renderer/platform/exported/web_runtime_features.cc
298@@ -689,4 +689,12 @@ void WebRuntimeFeatures::EnableCLSScroll
299 RuntimeEnabledFeatures::SetCLSScrollAnchoringEnabled(enable);
300 }
301
302+void WebRuntimeFeatures::EnableFingerprintingClientRectsNoise(bool enable) {
303+ RuntimeEnabledFeatures::SetFingerprintingClientRectsNoiseEnabled(enable);
304+}
305+
306+void WebRuntimeFeatures::EnableFingerprintingCanvasMeasureTextNoise(bool enable) {
307+ RuntimeEnabledFeatures::SetFingerprintingCanvasMeasureTextNoiseEnabled(enable);
308+}
309+
310 } // namespace blink
311--- third_party/blink/renderer/platform/runtime_enabled_features.json5.orig
312+++ third_party/blink/renderer/platform/runtime_enabled_features.json5
313@@ -1076,6 +1076,12 @@
314 origin_trial_feature_name: "Fledge",
315 },
316 {
317+ name: "FingerprintingClientRectsNoise",
318+ },
319+ {
320+ name: "FingerprintingCanvasMeasureTextNoise",
321+ },
322+ {
323 name: "FocuslessSpatialNavigation",
324 settable_from_internals: true,
325 },