Skip to content

Commit

Permalink
Hide Aggressive Fingerprinting Protection behind a flag (#20316)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuredelstein authored and mherrmann committed Nov 9, 2023
1 parent 8026f5f commit 77d84a7
Show file tree
Hide file tree
Showing 30 changed files with 307 additions and 22 deletions.
2 changes: 2 additions & 0 deletions android/java/org/chromium/base/BraveFeatureList.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public abstract class BraveFeatureList {
public static final String BRAVE_FORGET_FIRST_PARTY_STORAGE = "BraveForgetFirstPartyStorage";
public static final String BRAVE_REQUEST_OTR_TAB = "BraveRequestOTRTab";
public static final String AI_CHAT = "AIChat";
public static final String BRAVE_SHOW_STRICT_FINGERPRINTING_MODE =
"BraveShowStrictFingerprintingMode";
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
private static final String PREF_AD_BLOCK = "ad_block";
private static final String PREF_BLOCK_SCRIPTS = "scripts_block";
public static final String PREF_FINGERPRINTING_PROTECTION = "fingerprinting_protection";
public static final String PREF_FINGERPRINTING_PROTECTION2 = "fingerprinting_protection2";
private static final String PREF_CLOSE_TABS_ON_EXIT = "close_tabs_on_exit";
private static final String PREF_SEND_P3A = "send_p3a_analytics";
private static final String PREF_SEND_CRASH_REPORTS = "send_crash_reports";
Expand Down Expand Up @@ -126,6 +127,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
PREF_BLOCK_SCRIPTS,
PREF_BLOCK_CROSS_SITE_COOKIES,
PREF_FINGERPRINTING_PROTECTION,
PREF_FINGERPRINTING_PROTECTION2,
PREF_FINGERPRINT_LANGUAGE,
PREF_CONTENT_FILTERING,
PREF_FORGET_FIRST_PARTY_STORAGE,
Expand Down Expand Up @@ -187,6 +189,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
private ChromeSwitchPreference mHttpsFirstModePref;
private BraveDialogPreference mHttpsUpgradePref;
private BraveDialogPreference mFingerprintingProtectionPref;
private ChromeSwitchPreference mFingerprintingProtection2Pref;
private BraveDialogPreference mRequestOtrPref;
private ChromeSwitchPreference mBlockScriptsPref;
private ChromeSwitchPreference mForgetFirstPartyStoragePref;
Expand Down Expand Up @@ -306,6 +309,16 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
(BraveDialogPreference) findPreference(PREF_FINGERPRINTING_PROTECTION);
mFingerprintingProtectionPref.setOnPreferenceChangeListener(this);

mFingerprintingProtection2Pref =
(ChromeSwitchPreference) findPreference(PREF_FINGERPRINTING_PROTECTION2);
mFingerprintingProtection2Pref.setOnPreferenceChangeListener(this);

boolean showStrictFingerprintingMode =
ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_SHOW_STRICT_FINGERPRINTING_MODE);

mFingerprintingProtectionPref.setVisible(showStrictFingerprintingMode);
mFingerprintingProtection2Pref.setVisible(!showStrictFingerprintingMode);

mRequestOtrPref = (BraveDialogPreference) findPreference(PREF_REQUEST_OTR);
mRequestOtrPref.setOnPreferenceChangeListener(this);

Expand Down Expand Up @@ -517,6 +530,12 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
break;
}
}
} else if (PREF_FINGERPRINTING_PROTECTION2.equals(key)) {
boolean protect = (boolean) newValue;
BraveShieldsContentSettings.setFingerprintingPref(
protect
? BraveShieldsContentSettings.DEFAULT
: BraveShieldsContentSettings.ALLOW_RESOURCE);
} else if (PREF_REQUEST_OTR.equals(key)) {
UserPrefs.get(Profile.getLastUsedRegularProfile())
.setInteger(BravePref.REQUEST_OTR_ACTION_OPTION, (int) newValue);
Expand Down Expand Up @@ -685,14 +704,17 @@ private void updateBravePreferences() {
mFingerprintingProtectionPref.setCheckedIndex(0);
mFingerprintingProtectionPref.setSummary(
getActivity().getResources().getString(R.string.block_fingerprinting_option_1));
mFingerprintingProtection2Pref.setChecked(true);
} else if (fingerprintingPref.equals(BraveShieldsContentSettings.DEFAULT)) {
mFingerprintingProtectionPref.setCheckedIndex(1);
mFingerprintingProtectionPref.setSummary(
getActivity().getResources().getString(R.string.block_fingerprinting_option_2));
mFingerprintingProtection2Pref.setChecked(true);
} else if (fingerprintingPref.equals(BraveShieldsContentSettings.ALLOW_RESOURCE)) {
mFingerprintingProtectionPref.setCheckedIndex(2);
mFingerprintingProtectionPref.setSummary(
getActivity().getResources().getString(R.string.block_fingerprinting_option_3));
mFingerprintingProtection2Pref.setChecked(false);
}

if (httpsUpgradePref.equals(BraveShieldsContentSettings.BLOCK_RESOURCE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public BlockersInfo() {
private OnCheckedChangeListener mBraveShieldsBlockingScriptsChangeListener;
private SwitchCompat mBraveShieldsForgetFirstPartyStorageSwitch;
private OnCheckedChangeListener mBraveShieldsForgetFirstPartyStorageChangeListener;
private SwitchCompat mFingerprintingSwitch;
private OnCheckedChangeListener mBraveShieldsFingerprintingChangeListener;

private View mPopupView;
private LinearLayout mMainLayout;
Expand Down Expand Up @@ -580,14 +582,20 @@ private void setupDetailsLayouts() {

ArrayList<String> detailsLayouts = new ArrayList<>();
detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_TRACKERS);
detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING);
detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_COOKIES);
if (ChromeFeatureList.isEnabled(BraveFeatureList.HTTPS_BY_DEFAULT)) {
detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_HTTPS_UPGRADE);
} else {
mPopupView.findViewById(R.id.brave_shields_secondary_https_upgrade_layout_id)
.setVisibility(View.GONE);
}
if (ChromeFeatureList.isEnabled((BraveFeatureList.BRAVE_SHOW_STRICT_FINGERPRINTING_MODE))) {
detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING);
} else {
mPopupView
.findViewById(R.id.brave_shields_fingerprinting_layout_id)
.setVisibility(View.GONE);
}

int layoutId = 0;
int mSecondaryLayoutId = 0;
Expand Down Expand Up @@ -765,6 +773,19 @@ private void setUpSwitchLayouts() {
} else {
forgetFirstPartyStorageLayout.setVisibility(View.GONE);
}

LinearLayout fingerprintingSwitchLayout =
mSecondaryLayout.findViewById(R.id.brave_shields_fingerprinting_switch_id);
if (!ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_SHOW_STRICT_FINGERPRINTING_MODE)) {
TextView fingerprintingSwitchText =
fingerprintingSwitchLayout.findViewById(R.id.brave_shields_switch_text);
mFingerprintingSwitch =
fingerprintingSwitchLayout.findViewById(R.id.brave_shields_switch);
setupFingerprintingSwitchClick(mFingerprintingSwitch);
fingerprintingSwitchText.setText(R.string.block_fingerprinting);
} else {
fingerprintingSwitchLayout.setVisibility(View.GONE);
}
}

private void setUpAboutLayout() {
Expand Down Expand Up @@ -983,6 +1004,67 @@ private void setupForgetFirstPartyStorageSwitch(
}
}

private void setupFingerprintingSwitchClick(SwitchCompat fingerprintingSwitch) {
if (null == fingerprintingSwitch) {
return;
}
setupFingerprintingSwitch(fingerprintingSwitch, false);

mBraveShieldsFingerprintingChangeListener =
new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (0 != mHost.length()) {
BraveShieldsContentSettings.setShieldsValue(
mProfile,
mHost,
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING,
isChecked
? BraveShieldsContentSettings.DEFAULT
: BraveShieldsContentSettings.ALLOW_RESOURCE,
false);
}
}
};

fingerprintingSwitch.setOnCheckedChangeListener(mBraveShieldsFingerprintingChangeListener);
}

private void setupFingerprintingSwitch(
SwitchCompat braveShieldsFingerprintingSwitch, boolean fromTopSwitch) {
if (null == braveShieldsFingerprintingSwitch) {
return;
}
if (fromTopSwitch) {
// Prevents to fire an event when top shields changed
braveShieldsFingerprintingSwitch.setOnCheckedChangeListener(null);
}
if (0 != mHost.length()) {
if (BraveShieldsContentSettings.getShields(
mProfile,
mHost,
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_BRAVE_SHIELDS)) {
if (!BraveShieldsContentSettings.getShieldsValue(
mProfile,
mHost,
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING)
.equals(BraveShieldsContentSettings.ALLOW_RESOURCE)) {
braveShieldsFingerprintingSwitch.setChecked(true);
} else {
braveShieldsFingerprintingSwitch.setChecked(false);
}
braveShieldsFingerprintingSwitch.setEnabled(true);
} else {
braveShieldsFingerprintingSwitch.setChecked(false);
braveShieldsFingerprintingSwitch.setEnabled(false);
}
}
if (fromTopSwitch) {
braveShieldsFingerprintingSwitch.setOnCheckedChangeListener(
mBraveShieldsFingerprintingChangeListener);
}
}

private void setupMainSwitchClick(SwitchCompat braveShieldsSwitch) {
if (null == braveShieldsSwitch) {
return;
Expand Down
3 changes: 3 additions & 0 deletions android/java/res/layout/brave_shields_secondary_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@
android:id="@+id/brave_shields_fingerprinting_layout_id"
layout="@layout/brave_shields_toggle_layout"/>

<include
android:id="@+id/brave_shields_fingerprinting_switch_id"
layout="@layout/brave_shields_switcher"/>

</LinearLayout>
5 changes: 5 additions & 0 deletions android/java/res/xml/brave_privacy_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
app:dialog_subtitle="@string/block_fingerprinting_text"
app:dialog_entries="@array/blockFingerprintingTexts"
app:dialog_default_index="1" />
<org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="fingerprinting_protection2"
android:title="@string/block_fingerprinting"
android:summary="@string/fingerprinting_protection_summary"
android:defaultValue="true" />
<org.chromium.chrome.browser.settings.BraveDialogPreference
android:key="https_upgrade"
android:title="@string/https_upgrade_title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class BravePrivacySettingsTest {
private static final String PREF_INCOGNITO_LOCK = "incognito_lock";
private static final String PREF_PHONE_AS_A_SECURITY_KEY = "phone_as_a_security_key";

private static final int BRAVE_PRIVACY_SETTINGS_NUMBER_OF_ITEMS = 29;
private static final int BRAVE_PRIVACY_SETTINGS_NUMBER_OF_ITEMS = 30;

private int mItemsLeft;

Expand Down
9 changes: 9 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,15 @@
kOsAll, \
FEATURE_VALUE_TYPE(net::features::kBraveHttpsByDefault), \
}, \
{ \
"brave-show-strict-fingerprinting-mode", \
"Show Strict Fingerprinting Mode", \
"Show Strict (aggressive) option for Fingerprinting Mode in " \
"Brave Shields ", \
kOsAll, \
FEATURE_VALUE_TYPE( \
brave_shields::features::kBraveShowStrictFingerprintingMode), \
}, \
{ \
"brave-override-download-danger-level", \
"Override download danger level", \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const char kMatchDarkModeFormatString[] =

class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest {
public:
BraveDarkModeFingerprintProtectionTest() {
feature_list_.InitAndEnableFeature(
brave_shields::features::kBraveShowStrictFingerprintingMode);
}

class BraveContentBrowserClientWithWebTheme
: public BraveContentBrowserClient {
public:
Expand Down Expand Up @@ -163,6 +168,7 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest {
private:
GURL top_level_page_url_;
GURL dark_mode_url_;
base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtectionTest, DarkModeCheck) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

using brave_shields::ControlType;
using brave_shields::features::kBraveReduceLanguage;
using brave_shields::features::kBraveShowStrictFingerprintingMode;
using content::TitleWatcher;

namespace {
Expand All @@ -52,7 +53,8 @@ class BraveNavigatorLanguagesFarblingBrowserTest : public InProcessBrowserTest {
public:
BraveNavigatorLanguagesFarblingBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
feature_list_.InitAndEnableFeature(kBraveReduceLanguage);
feature_list_.InitWithFeatures(
{kBraveReduceLanguage, kBraveShowStrictFingerprintingMode}, {});
brave::RegisterPathProvider();
base::FilePath test_data_dir;
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "brave/browser/extensions/brave_base_local_data_files_browsertest.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/common/features.h"
#include "brave/components/constants/brave_paths.h"
#include "brave/components/constants/pref_names.h"
#include "chrome/browser/chrome_content_browser_client.h"
Expand Down Expand Up @@ -85,6 +86,11 @@ void CheckUserAgentMetadataVersionsList(

class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest {
public:
BraveNavigatorUserAgentFarblingBrowserTest() {
feature_list_.InitAndEnableFeature(
brave_shields::features::kBraveShowStrictFingerprintingMode);
}

void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

Expand Down Expand Up @@ -176,6 +182,7 @@ class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest {
std::unique_ptr<ChromeContentClient> content_client_;
std::unique_ptr<BraveContentBrowserClient> browser_content_client_;
std::vector<std::string> user_agents_;
base::test::ScopedFeatureList feature_list_;
};

// Tests results of farbling user agent
Expand Down
4 changes: 4 additions & 0 deletions browser/profiles/profile_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ void SetDefaultThirdPartyCookieBlockValue(Profile* profile);
// set the HttpsUpgrade default setting to strict.
void MigrateHttpsUpgradeSettings(Profile* profile);

// Checks if the user previously had fingerprinting mode disabled.
// If so, set the new fingerprinting toggle to disabled.
void MigrateFingerprintingSettings(Profile* profile);

} // namespace brave

#endif // BRAVE_BROWSER_PROFILES_PROFILE_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export interface DefaultBraveShieldsBrowserProxy {
*/
setFingerprintingControlType(value)

/**
* @return {!Promise<boolean>}
*/
getFingerprintingBlockEnabled()
/**
* @param {boolean} value name.
*/
setFingerprintingBlockEnabled(value)

/**
* @return {!Promise<string>}
*/
Expand Down Expand Up @@ -111,6 +120,16 @@ export class DefaultBraveShieldsBrowserProxyImpl implements DefaultBraveShieldsB
chrome.send('setFingerprintingControlType', [value]);
}

/** @override */
getFingerprintingBlockEnabled() {
return sendWithPromise('getFingerprintingBlockEnabled');
}

/** @override */
setFingerprintingBlockEnabled(value) {
chrome.send('setFingerprintingBlockEnabled', [value]);
}

/** @override */
getHttpsUpgradeControlType() {
return sendWithPromise('getHttpsUpgradeControlType');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
label="$i18n{noScriptControlLabel}"
on-settings-boolean-control-change="onNoScriptControlChange_">
</settings-toggle-button>
<div class="settings-box">
<div hidden="[[!showStrictFingerprintingMode_]]" class="settings-box">
<div class="start">$i18n{fingerprintingControlLabel}</div>
<select id="fingerprintingControlType" class="md-select"
on-change="onFingerprintingControlChange_">
<select id="fingerprintingSelectControlType" class="md-select"
on-change="onFingerprintingSelectControlChange_">
<template is="dom-repeat" items="[[fingerprintingControlTypes_]]">
<option value="[[item.value]]"
selected="[[controlEqual_(item.value, fingerprintingControlType_)]]">
Expand All @@ -86,6 +86,13 @@
</template>
</select>
</div>
<settings-toggle-button id="fingerprintingToggleControlType"
hidden="[[showStrictFingerprintingMode_]]"
class="cr-row"
pref="[[isFingerprintingEnabled_]]"
label="$i18n{fingerprintingControlLabel}"
on-settings-boolean-control-change="onFingerprintingToggleControlChange_">
</settings-toggle-button>
<div class="settings-box">
<div class="start">$i18n{cookieControlLabel}</div>
<select id="cookieControlType" class="md-select"
Expand Down
Loading

0 comments on commit 77d84a7

Please sign in to comment.