Skip to content

Commit ee13895

Browse files
Don't block fingerprinting in extension pages
Fixes brave/brave-browser#26715
1 parent f7f0b15 commit ee13895

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

browser/farbling/brave_screen_farbling_browsertest.cc

+39-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55

66
#include <algorithm>
77

8+
#include "base/files/file_path.h"
89
#include "base/path_service.h"
910
#include "base/run_loop.h"
1011
#include "base/test/scoped_feature_list.h"
1112
#include "brave/browser/brave_content_browser_client.h"
1213
#include "brave/components/brave_shields/browser/brave_shields_util.h"
1314
#include "brave/components/constants/brave_paths.h"
1415
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
15-
#include "chrome/browser/extensions/extension_browsertest.h"
16+
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
1617
#include "chrome/browser/profiles/profile.h"
1718
#include "chrome/browser/ui/browser_window.h"
1819
#include "chrome/common/chrome_content_client.h"
20+
#include "chrome/common/chrome_paths.h"
21+
#include "chrome/test/base/in_process_browser_test.h"
1922
#include "chrome/test/base/ui_test_utils.h"
2023
#include "content/public/test/browser_test.h"
2124
#include "net/dns/mock_host_resolver.h"
@@ -62,6 +65,14 @@ class BraveScreenFarblingBrowserTest : public InProcessBrowserTest {
6265
content_client_.reset();
6366
}
6467

68+
std::string LoadExtension(const base::FilePath& path) {
69+
extensions::ChromeTestExtensionLoader loader(browser()->profile());
70+
scoped_refptr<const extensions::Extension> extension =
71+
loader.LoadExtension(path);
72+
EXPECT_TRUE(extension);
73+
return extension->id();
74+
}
75+
6576
HostContentSettingsMap* ContentSettings() {
6677
return HostContentSettingsMapFactory::GetForProfile(browser()->profile());
6778
}
@@ -99,13 +110,13 @@ class BraveScreenFarblingBrowserTest : public InProcessBrowserTest {
99110
return browser()->window()->GetBounds();
100111
}
101112

102-
void FarbleScreenSize() {
113+
void FarbleScreenSize(const GURL& url, bool content_scheme) {
103114
for (int j = 0; j < static_cast<int>(std::size(kTestWindowBounds)); ++j) {
104115
SetBounds(kTestWindowBounds[j]);
105116
for (bool allow_fingerprinting : {false, true}) {
106117
SetFingerprintingSetting(allow_fingerprinting);
107-
NavigateToURLUntilLoadStop(FarblingUrl());
108-
if (!allow_fingerprinting && !IsFlagDisabled()) {
118+
NavigateToURLUntilLoadStop(url);
119+
if (!allow_fingerprinting && !IsFlagDisabled() && content_scheme) {
109120
EXPECT_GE(
110121
8, EvalJs(Contents(), "window.outerWidth - window.innerWidth"));
111122
EXPECT_GE(
@@ -274,12 +285,12 @@ class BraveScreenFarblingBrowserTest_DisableFlag
274285

275286
IN_PROC_BROWSER_TEST_F(BraveScreenFarblingBrowserTest_EnableFlag,
276287
FarbleScreenSize_EnableFlag) {
277-
FarbleScreenSize();
288+
FarbleScreenSize(FarblingUrl(), true);
278289
}
279290

280291
IN_PROC_BROWSER_TEST_F(BraveScreenFarblingBrowserTest_DisableFlag,
281292
FarbleScreenSize_DisableFlag) {
282-
FarbleScreenSize();
293+
FarbleScreenSize(FarblingUrl(), true);
283294
}
284295

285296
IN_PROC_BROWSER_TEST_F(BraveScreenFarblingBrowserTest_EnableFlag,
@@ -345,3 +356,25 @@ IN_PROC_BROWSER_TEST_F(BraveScreenFarblingBrowserTest_DisableFlag,
345356
FarbleScreenPopupPosition_DisableFlag_3) {
346357
FarbleScreenPopupPosition(3);
347358
}
359+
360+
IN_PROC_BROWSER_TEST_F(BraveScreenFarblingBrowserTest_EnableFlag,
361+
FarbleScreenSize_Schemes) {
362+
// chrome: URI (don't farble)
363+
FarbleScreenSize(GURL("chrome:version"), false);
364+
365+
// chrome-extension: URI (don't farble)
366+
base::FilePath test_data_dir;
367+
base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
368+
std::string extension_id =
369+
LoadExtension(test_data_dir.AppendASCII("extensions")
370+
.AppendASCII("ui")
371+
.AppendASCII("browser_action_popup"));
372+
base::RunLoop().RunUntilIdle(); // Ensure the extension is fully loaded.
373+
const GURL extension_url("chrome-extension://" + extension_id +
374+
"/popup.html");
375+
FarbleScreenSize(extension_url, false);
376+
377+
// devtools: URI (don't farble)
378+
const GURL devtools_url("devtools://devtools/bundled/devtools_app.html");
379+
FarbleScreenSize(devtools_url, false);
380+
}

third_party/blink/renderer/core/farbling/brave_session_cache.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "third_party/blink/renderer/platform/language.h"
3030
#include "third_party/blink/renderer/platform/network/network_utils.h"
3131
#include "third_party/blink/renderer/platform/supplementable.h"
32+
#include "third_party/blink/renderer/platform/weborigin/scheme_registry.h"
3233
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
3334
#include "third_party/blink/renderer/platform/wtf/casting.h"
3435
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
@@ -80,10 +81,10 @@ blink::WebContentSettingsClient* GetContentSettingsClientFor(
8081
blink::WebContentSettingsClient* settings = nullptr;
8182
if (!context)
8283
return settings;
83-
// Avoid blocking fingerprinting in WebUI pages.
84+
// Avoid blocking fingerprinting in WebUI, extensions, etc.
8485
const String protocol = context->GetSecurityOrigin()->Protocol();
85-
if (protocol == url::kAboutScheme || protocol == "chrome" ||
86-
protocol == "brave") {
86+
if (protocol == url::kAboutScheme || protocol == "chrome-extension" ||
87+
blink::SchemeRegistry::ShouldTreatURLSchemeAsDisplayIsolated(protocol)) {
8788
return settings;
8889
}
8990
if (auto* window = blink::DynamicTo<blink::LocalDOMWindow>(context)) {

0 commit comments

Comments
 (0)