Files
helium/patches/extra/bromite/fingerprinting-flags-client-rects-and-measuretext.patch

351 lines
15 KiB
Diff
Raw Normal View History

# Adds two flags:
# 1. --fingerprinting-client-rects-noise to enable fingerprinting deception for Range::getClientRects and Element::getBoundingClientRect
# 2. --fingerprinting-canvas-measuretext-noise to enable fingerprinting deception for Canvas::measureText
# Tweaks based on https://github.com/bromite/bromite/blob/b1bc96bbd9ec549cf496e87f487a0ac35c83df0a/patches/BRM052_getClientRects-getBoundingClientRect-measureText-add-fingerprinting-mitigation.patch
2022-06-01 18:32:26 +03:00
# Originally based on https://github.com/ungoogled-software/ungoogled-chromium/pull/377/commits/4151259b3248f0fc5c42fa262a1d1dd43c39fb60
# chrome://flag setting added by ungoogled-chromium developers
#
# 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.
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
2025-11-20 11:54:19 -06:00
@@ -2596,6 +2596,7 @@ static_library("browser") {
"//third_party/libyuv",
"//third_party/metrics_proto",
"//third_party/re2",
+ "//components/ungoogled:ungoogled_switches",
"//third_party/webrtc_overrides:webrtc_component",
"//third_party/widevine/cdm:buildflags",
"//third_party/widevine/cdm:headers",
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
2025-10-22 16:34:39 -05:00
@@ -191,6 +191,7 @@
2021-07-20 10:43:27 -05:00
#include "components/translate/core/common/translate_util.h"
2023-11-25 14:14:03 -06:00
#include "components/trusted_vault/features.h"
2021-07-20 10:43:27 -05:00
#include "components/ui_devtools/switches.h"
+#include "components/ungoogled/ungoogled_switches.h"
2023-04-26 10:38:53 -05:00
#include "components/variations/variations_switches.h"
2024-02-13 13:54:32 -06:00
#include "components/version_info/channel.h"
2021-07-20 10:43:27 -05:00
#include "components/version_info/version_info.h"
--- a/chrome/browser/bromite_flag_entries.h
+++ b/chrome/browser/bromite_flag_entries.h
@@ -4,4 +4,12 @@
#ifndef CHROME_BROWSER_BROMITE_FLAG_ENTRIES_H_
#define CHROME_BROWSER_BROMITE_FLAG_ENTRIES_H_
+ {"fingerprinting-client-rects-noise",
+ "Enable get*ClientRects() fingerprint deception",
+ "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.",
+ kOsAll, SINGLE_VALUE_TYPE(switches::kFingerprintingClientRectsNoise)},
+ {"fingerprinting-canvas-measuretext-noise",
+ "Enable Canvas::measureText() fingerprint deception",
+ "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.",
+ kOsAll, SINGLE_VALUE_TYPE(switches::kFingerprintingCanvasMeasureTextNoise)},
#endif // CHROME_BROWSER_BROMITE_FLAG_ENTRIES_H_
--- a/content/browser/BUILD.gn
+++ b/content/browser/BUILD.gn
2025-11-20 11:54:19 -06:00
@@ -299,6 +299,7 @@ source_set("browser") {
"//third_party/re2",
2024-10-09 18:30:59 -05:00
"//third_party/snappy",
"//third_party/sqlite",
2020-11-07 18:44:36 +02:00
+ "//components/ungoogled:ungoogled_switches",
2020-01-10 14:04:40 -06:00
"//third_party/webrtc_overrides:webrtc_component",
"//third_party/zlib",
2024-04-11 09:48:20 -05:00
"//tools/v8_context_snapshot:buildflags",
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
2025-10-22 16:34:39 -05:00
@@ -84,6 +84,7 @@
2022-06-16 06:26:30 -05:00
#include "components/services/storage/public/cpp/quota_error_or.h"
2021-10-14 14:41:09 -05:00
#include "components/services/storage/public/mojom/cache_storage_control.mojom.h"
#include "components/tracing/common/tracing_switches.h"
+#include "components/ungoogled/ungoogled_switches.h"
2021-10-14 14:41:09 -05:00
#include "components/viz/common/switches.h"
#include "components/viz/host/gpu_client.h"
2025-02-23 17:24:33 -06:00
#include "components/viz/host/host_frame_sink_manager.h"
2025-11-20 11:54:19 -06:00
@@ -3698,6 +3699,8 @@ void RenderProcessHostImpl::PropagateBro
2024-11-06 10:56:00 -06:00
switches::kEnableWebGLImageChromium,
switches::kEnableWebGPUDeveloperFeatures,
switches::kFileUrlPathAlias,
+ switches::kFingerprintingClientRectsNoise,
+ switches::kFingerprintingCanvasMeasureTextNoise,
switches::kForceDeviceScaleFactor,
switches::kForceDisplayColorProfile,
2025-07-30 18:19:08 -05:00
switches::kForceHighContrast,
--- a/content/child/BUILD.gn
+++ b/content/child/BUILD.gn
2025-11-20 11:54:19 -06:00
@@ -109,6 +109,7 @@ target(link_target_type, "child") {
2023-09-01 16:44:31 -05:00
"//third_party/blink/public/common:buildflags",
"//third_party/blink/public/strings",
"//third_party/ced",
2020-11-07 18:44:36 +02:00
+ "//components/ungoogled:ungoogled_switches",
"//third_party/zlib/google:compression_utils",
"//ui/base",
"//ui/events/blink",
--- a/content/child/runtime_features.cc
+++ b/content/child/runtime_features.cc
2025-11-20 11:54:19 -06:00
@@ -42,6 +42,7 @@
#include "third_party/blink/public/common/loader/referrer_utils.h"
2020-08-26 02:04:55 -04:00
#include "third_party/blink/public/common/switches.h"
2018-05-24 13:21:07 +02:00
#include "third_party/blink/public/platform/web_runtime_features.h"
+#include "components/ungoogled/ungoogled_switches.h"
#include "ui/accessibility/accessibility_features.h"
2019-07-30 19:00:28 -04:00
#include "ui/base/ui_base_features.h"
#include "ui/events/blink/blink_features.h"
2025-11-20 11:54:19 -06:00
@@ -485,6 +486,10 @@ void SetRuntimeFeaturesFromCommandLine(c
2023-03-27 14:23:02 -05:00
true},
2024-11-06 10:56:00 -06:00
{wrf::EnableWebAudioBypassOutputBufferingOptOut,
blink::switches::kWebAudioBypassOutputBufferingOptOut, true},
+ {wrf::EnableFingerprintingClientRectsNoise,
+ switches::kFingerprintingClientRectsNoise, true},
+ {wrf::EnableFingerprintingCanvasMeasureTextNoise,
+ switches::kFingerprintingCanvasMeasureTextNoise, true},
2020-08-26 02:04:55 -04:00
};
2023-03-27 14:23:02 -05:00
2020-08-26 02:04:55 -04:00
for (const auto& mapping : switchToFeatureMapping) {
--- a/third_party/blink/public/platform/web_runtime_features.h
+++ b/third_party/blink/public/platform/web_runtime_features.h
2025-08-27 17:27:06 -05:00
@@ -71,6 +71,9 @@ class BLINK_PLATFORM_EXPORT WebRuntimeFe
static void EnableLocalNetworkAccessWebRTC(bool);
2022-10-20 10:21:39 -05:00
+ static void EnableFingerprintingClientRectsNoise(bool);
+ static void EnableFingerprintingCanvasMeasureTextNoise(bool);
+
WebRuntimeFeatures() = delete;
};
2018-05-24 13:21:07 +02:00
--- a/third_party/blink/renderer/core/dom/document.cc
+++ b/third_party/blink/renderer/core/dom/document.cc
2025-06-15 07:00:38 -05:00
@@ -41,6 +41,7 @@
#include "base/i18n/time_formatting.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
+#include "base/rand_util.h"
2023-03-01 16:05:16 -06:00
#include "base/task/single_thread_task_runner.h"
2019-10-07 17:58:01 -05:00
#include "base/time/time.h"
2025-06-15 07:00:38 -05:00
#include "base/trace_event/trace_event.h"
2025-11-20 11:54:19 -06:00
@@ -1089,6 +1090,11 @@ Document::Document(const DocumentInit& i
2024-04-11 09:48:20 -05:00
TRACE_EVENT_WITH_FLOW0("blink", "Document::Document", TRACE_ID_LOCAL(this),
TRACE_EVENT_FLAG_FLOW_OUT);
DCHECK(agent_);
+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
+ // Precompute -0.0003% to 0.0003% noise factor for get*ClientRect*() fingerprinting
+ noise_factor_x_ = 1 + (base::RandDouble() - 0.5) * 0.000003;
+ noise_factor_y_ = 1 + (base::RandDouble() - 0.5) * 0.000003;
+ }
if (base::FeatureList::IsEnabled(features::kDelayAsyncScriptExecution) &&
features::kDelayAsyncScriptExecutionDelayByDefaultParam.Get()) {
script_runner_delayer_->Activate();
2025-11-20 11:54:19 -06:00
@@ -1226,6 +1232,14 @@ const Position Document::PositionAdjuste
2024-03-12 10:35:41 -05:00
return Position::BeforeNode(*shadow_host);
}
+double Document::GetNoiseFactorX() {
+ return noise_factor_x_;
+}
+
+double Document::GetNoiseFactorY() {
+ return noise_factor_y_;
+}
+
SelectorQueryCache& Document::GetSelectorQueryCache() {
if (!selector_query_cache_)
2025-02-23 17:24:33 -06:00
selector_query_cache_ = MakeGarbageCollected<SelectorQueryCache>();
2018-05-24 13:21:07 +02:00
--- a/third_party/blink/renderer/core/dom/document.h
+++ b/third_party/blink/renderer/core/dom/document.h
2025-10-22 16:34:39 -05:00
@@ -574,6 +574,10 @@ class CORE_EXPORT Document : public Cont
has_xml_declaration_ = has_xml_declaration ? 1 : 0;
}
+ // Values for get*ClientRect fingerprint deception
+ double GetNoiseFactorX();
+ double GetNoiseFactorY();
+
2025-01-08 14:03:54 -06:00
V8VisibilityState visibilityState() const;
String visibilityStateAsString() const;
2019-03-26 08:19:19 +03:00
bool IsPageVisible() const;
2025-11-20 11:54:19 -06:00
@@ -2810,6 +2814,9 @@ class CORE_EXPORT Document : public Cont
2019-09-11 16:49:51 +02:00
base::ElapsedTimer start_time_;
+ double noise_factor_x_ = 1;
+ double noise_factor_y_ = 1;
+
2025-09-24 15:57:30 -05:00
// The script runner is used to run scripts of the following scheduling types:
// - ScriptSchedulingType::kAsync
// - ScriptSchedulingType::kInOrder
2018-05-24 13:21:07 +02:00
--- a/third_party/blink/renderer/core/dom/element.cc
+++ b/third_party/blink/renderer/core/dom/element.cc
2025-11-20 11:54:19 -06:00
@@ -3195,6 +3195,9 @@ Vector<gfx::RectF> Element::GetClientRec
}
Vector<gfx::RectF> result;
for (auto& quad : quads) {
+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
+ quad.Scale(GetDocument().GetNoiseFactorX(), GetDocument().GetNoiseFactorY());
+ }
2025-11-20 11:54:19 -06:00
result.emplace_back(quad.BoundingBox());
}
return result;
@@ -3224,6 +3227,9 @@ gfx::RectF Element::GetBoundingClientRec
DCHECK(element_layout_object);
2022-02-23 16:40:56 -06:00
GetDocument().AdjustRectForScrollAndAbsoluteZoom(result,
*element_layout_object);
+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
+ result.Scale(GetDocument().GetNoiseFactorX(), GetDocument().GetNoiseFactorY());
+ }
2021-04-18 22:21:16 -05:00
return result;
}
2018-05-24 13:21:07 +02:00
--- a/third_party/blink/renderer/core/dom/range.cc
+++ b/third_party/blink/renderer/core/dom/range.cc
2025-08-27 17:27:06 -05:00
@@ -1655,6 +1655,12 @@ DOMRectList* Range::getClientRects() con
2022-02-23 16:40:56 -06:00
Vector<gfx::QuadF> quads;
GetBorderAndTextQuads(quads);
+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
2022-02-23 16:40:56 -06:00
+ for (gfx::QuadF& quad : quads) {
+ quad.Scale(owner_document_->GetNoiseFactorX(), owner_document_->GetNoiseFactorY());
+ }
+ }
+
2020-04-08 01:58:51 -04:00
return MakeGarbageCollected<DOMRectList>(quads);
}
2025-08-27 17:27:06 -05:00
@@ -1662,7 +1668,11 @@ DOMRect* Range::getBoundingClientRect()
2024-02-13 13:54:32 -06:00
// TODO(crbug.com/1499981): This should be removed once synchronized scrolling
// impact is understood.
SyncScrollAttemptHeuristic::DidAccessScrollOffset();
2022-02-23 16:40:56 -06:00
- return DOMRect::FromRectF(BoundingRect());
+ auto rect = BoundingRect();
+ if (RuntimeEnabledFeatures::FingerprintingClientRectsNoiseEnabled()) {
+ rect.Scale(owner_document_->GetNoiseFactorX(), owner_document_->GetNoiseFactorY());
+ }
2022-02-23 16:40:56 -06:00
+ return DOMRect::FromRectF(rect);
}
// TODO(editing-dev): We should make
--- a/third_party/blink/renderer/core/html/canvas/text_metrics.cc
+++ b/third_party/blink/renderer/core/html/canvas/text_metrics.cc
2025-11-20 11:54:19 -06:00
@@ -89,6 +89,24 @@ TextMetrics::TextMetrics(const Font* fon
Update(font, direction, baseline, align, text, text_painter);
}
+void TextMetrics::Shuffle(const double factor) {
+ // x-direction
+ width_ *= factor;
+ actual_bounding_box_left_ *= factor;
+ actual_bounding_box_right_ *= factor;
+
+ // y-direction
+ font_bounding_box_ascent_ *= factor;
+ font_bounding_box_descent_ *= factor;
+ actual_bounding_box_ascent_ *= factor;
+ actual_bounding_box_descent_ *= factor;
+ em_height_ascent_ *= factor;
+ em_height_descent_ *= factor;
+ baselines_->setAlphabetic(baselines_->alphabetic() * factor);
+ baselines_->setHanging(baselines_->hanging() * factor);
+ baselines_->setIdeographic(baselines_->ideographic() * factor);
+}
+
2025-03-25 18:37:15 -05:00
void TextMetrics::Update(const Font* font,
const TextDirection& direction,
2025-03-25 18:37:15 -05:00
const V8CanvasTextBaseline::Enum baseline,
--- a/third_party/blink/renderer/core/html/canvas/text_metrics.h
+++ b/third_party/blink/renderer/core/html/canvas/text_metrics.h
2025-11-20 11:54:19 -06:00
@@ -109,6 +109,8 @@ class CORE_EXPORT TextMetrics final : pu
2024-08-15 14:47:11 -05:00
float x_position_;
};
+ void Shuffle(const double factor);
+
private:
2025-03-25 18:37:15 -05:00
void Update(const Font*,
const TextDirection& direction,
2023-10-03 15:48:31 -05:00
--- a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc
+++ b/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc
2025-11-20 11:54:19 -06:00
@@ -107,6 +107,9 @@
2025-04-23 15:07:40 -05:00
// https://github.com/include-what-you-use/include-what-you-use/issues/1122
// IWYU pragma: no_include "base/numerics/clamped_math.h"
+#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
+#include "third_party/blink/renderer/core/frame/local_dom_window.h"
+
namespace blink {
2025-08-27 17:27:06 -05:00
class MemoryManagedPaintCanvas;
2025-11-20 11:54:19 -06:00
@@ -1233,9 +1236,22 @@ TextMetrics* BaseRenderingContext2D::mea
2025-04-23 15:07:40 -05:00
TextDirection direction =
ToTextDirection(state.GetDirection(), host, computed_style);
2019-10-07 17:58:01 -05:00
2024-02-13 13:54:32 -06:00
- return MakeGarbageCollected<TextMetrics>(
2025-03-25 18:37:15 -05:00
+ TextMetrics* text_metrics = MakeGarbageCollected<TextMetrics>(
2025-11-20 11:54:19 -06:00
font, direction, state.GetTextBaseline().AsEnum(),
state.GetTextAlign().AsEnum(), text, host->GetPlainTextPainter());
+
+ // Scale text metrics if enabled
+ if (RuntimeEnabledFeatures::FingerprintingCanvasMeasureTextNoiseEnabled()) {
+ if (HostAsOffscreenCanvas()) {
+ if (auto* window = DynamicTo<LocalDOMWindow>(GetTopExecutionContext())) {
+ if (window->GetFrame() && window->GetFrame()->GetDocument())
+ text_metrics->Shuffle(window->GetFrame()->GetDocument()->GetNoiseFactorX());
+ }
+ } else if (canvas) {
+ text_metrics->Shuffle(canvas->GetDocument().GetNoiseFactorX());
+ }
+ }
2019-10-07 17:58:01 -05:00
+ return text_metrics;
}
2025-04-23 15:07:40 -05:00
String BaseRenderingContext2D::lang() const {
--- a/third_party/blink/renderer/platform/BUILD.gn
+++ b/third_party/blink/renderer/platform/BUILD.gn
2025-11-20 11:54:19 -06:00
@@ -1811,6 +1811,7 @@ component("platform") {
"//components/paint_preview/common",
"//components/search_engines:search_engine_utils",
2025-08-27 17:27:06 -05:00
"//components/translate/core/language_detection",
2020-11-07 18:44:36 +02:00
+ "//components/ungoogled:ungoogled_switches",
"//components/viz/client",
"//components/viz/common",
"//components/webrtc:net_address_utils",
--- a/third_party/blink/renderer/platform/exported/web_runtime_features.cc
+++ b/third_party/blink/renderer/platform/exported/web_runtime_features.cc
2025-08-27 17:27:06 -05:00
@@ -73,4 +73,12 @@ void WebRuntimeFeatures::EnableLocalNetw
RuntimeEnabledFeatures::SetLocalNetworkAccessWebRTCEnabled(enable);
2019-07-30 19:00:28 -04:00
}
2025-08-27 17:27:06 -05:00
+void WebRuntimeFeatures::EnableFingerprintingClientRectsNoise(bool enable) {
+ RuntimeEnabledFeatures::SetFingerprintingClientRectsNoiseEnabled(enable);
+}
+
+void WebRuntimeFeatures::EnableFingerprintingCanvasMeasureTextNoise(bool enable) {
+ RuntimeEnabledFeatures::SetFingerprintingCanvasMeasureTextNoiseEnabled(enable);
+}
+
} // namespace blink
2024-07-18 06:31:15 -05:00
--- a/third_party/blink/renderer/platform/graphics/image_data_buffer.cc
+++ b/third_party/blink/renderer/platform/graphics/image_data_buffer.cc
2025-03-25 18:37:15 -05:00
@@ -35,6 +35,7 @@
#include "base/compiler_specific.h"
2024-07-18 06:31:15 -05:00
#include "base/memory/ptr_util.h"
2025-04-23 15:07:40 -05:00
#include "third_party/blink/renderer/platform/image-encoders/image_encoder_utils.h"
2024-07-18 06:31:15 -05:00
+#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
2025-07-30 18:19:08 -05:00
#include "third_party/blink/renderer/platform/wtf/text/strcat.h"
2025-03-25 18:37:15 -05:00
#include "third_party/skia/include/core/SkImage.h"
--- a/third_party/blink/renderer/platform/runtime_enabled_features.json5
+++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5
2025-11-20 11:54:19 -06:00
@@ -2441,6 +2441,12 @@
2025-04-23 15:07:40 -05:00
status: "stable",
},
{
+ name: "FingerprintingClientRectsNoise",
+ },
+ {
+ name: "FingerprintingCanvasMeasureTextNoise",
+ },
+ {
2024-02-13 13:54:32 -06:00
name: "Fledge",
2024-08-15 14:47:11 -05:00
status: "stable",
2023-03-27 14:23:02 -05:00
base_feature: "none",