Skip to content

Commit

Permalink
Fixed setting default FP always fallback to global FP setting
Browse files Browse the repository at this point in the history
CONTENT_SETTING_DEFAULT means deleting the current content setting.
With DEFAULT, it always use global FP setting.
But we want DEFAULT as a standard FP blocking instead of fallback to
global settings As a workaround, use CONTENT_SETTING_ASK.
With CONTENT_SETTING_ASK, we can store persistently.

And deleted obsolete first/third party scope FP testing.
  • Loading branch information
simonhong committed Jun 17, 2020
1 parent 8fa0102 commit ccb0267
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 84 deletions.
12 changes: 10 additions & 2 deletions components/brave_shields/browser/brave_shields_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,18 @@ void SetFingerprintingControlType(Profile* profile,
if (!primary_pattern.IsValid())
return;

ContentSetting content_setting = GetDefaultAllowFromControlType(type);
auto* map = HostContentSettingsMapFactory::GetForProfile(profile);
map->SetContentSettingCustomScope(
primary_pattern, ContentSettingsPattern::Wildcard(),
ContentSettingsType::PLUGINS, kFingerprintingV2,
GetDefaultAllowFromControlType(type));
// CONTENT_SETTING_DEFAULT means deleting the current content setting.
// With DEFAULT, it always use global FP setting.
// But we want DEFAULT as a standard FP blocking instead of fallback to
// global settings.
// As a workaround, picked CONTENT_SETTING_ASK to store it persistently.
content_setting == CONTENT_SETTING_DEFAULT ? CONTENT_SETTING_ASK
: content_setting);

RecordShieldsSettingChanged();
}
Expand All @@ -349,8 +356,9 @@ ControlType GetFingerprintingControlType(Profile* profile, const GURL& url) {
return ControlType::BLOCK;
} else if (setting == CONTENT_SETTING_ALLOW) {
return ControlType::ALLOW;
} else {
return ControlType::DEFAULT;
}
return ControlType::DEFAULT;
}

void SetHTTPSEverywhereEnabled(Profile* profile,
Expand Down
100 changes: 18 additions & 82 deletions components/brave_shields/browser/brave_shields_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -560,16 +560,9 @@ TEST_F(BraveShieldsUtilTest, SetFingerprintingControlType_Default) {
map->GetContentSetting(GURL(), GURL(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
setting = map->GetContentSetting(GURL(), GURL("https://firstParty"),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
setting = map->GetContentSetting(GURL("http://brave.com"), GURL(),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
setting = map->GetContentSetting(
GURL("http://brave.com"), GURL("https://firstParty"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);

/* ALLOW */
Expand All @@ -579,19 +572,12 @@ TEST_F(BraveShieldsUtilTest, SetFingerprintingControlType_Default) {
map->GetContentSetting(GURL(), GURL(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
setting = map->GetContentSetting(GURL(), GURL("https://firstParty"),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);

// setting should apply to all urls
setting = map->GetContentSetting(GURL("http://brave.com"), GURL(),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
setting = map->GetContentSetting(
GURL("http://brave.com"), GURL("https://firstParty"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);

/* BLOCK */
brave_shields::SetFingerprintingControlType(profile(), ControlType::BLOCK,
Expand All @@ -600,41 +586,34 @@ TEST_F(BraveShieldsUtilTest, SetFingerprintingControlType_Default) {
map->GetContentSetting(GURL(), GURL(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_BLOCK, setting);
setting = map->GetContentSetting(GURL(), GURL("https://firstParty"),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_BLOCK, setting);

// setting should apply to all urls
setting = map->GetContentSetting(GURL("http://brave.com"), GURL(),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_BLOCK, setting);
setting = map->GetContentSetting(
GURL("http://brave.com"), GURL("https://firstParty"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_BLOCK, setting);

/* DEFAULT */
brave_shields::SetFingerprintingControlType(
profile(), ControlType::DEFAULT, GURL());
setting =
map->GetContentSetting(GURL(), GURL(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
setting = map->GetContentSetting(GURL(), GURL("https://firstParty"),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
ControlType type =
brave_shields::GetFingerprintingControlType(profile(), GURL());
EXPECT_EQ(ControlType::DEFAULT, type);

// setting should apply to all urls
setting = map->GetContentSetting(GURL("http://brave.com"), GURL(),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
setting = map->GetContentSetting(
GURL("http://brave.com"), GURL("https://firstParty"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
type = brave_shields::GetFingerprintingControlType(
profile(), GURL("http://brave.com"));
EXPECT_EQ(ControlType::DEFAULT, type);

/* Global ALLOW and Site explicit DEFAULT */
brave_shields::SetFingerprintingControlType(profile(), ControlType::ALLOW,
GURL());
brave_shields::SetFingerprintingControlType(profile(), ControlType::DEFAULT,
GURL("http://brave.com"));
// Site should have DEFAULT if it's explicitly set.
type = brave_shields::GetFingerprintingControlType(
profile(), GURL("http://brave.com"));
EXPECT_EQ(ControlType::DEFAULT, type);
}

TEST_F(BraveShieldsUtilTest, SetFingerprintingControlType_ForOrigin) {
Expand All @@ -646,31 +625,18 @@ TEST_F(BraveShieldsUtilTest, SetFingerprintingControlType_ForOrigin) {
auto setting = map->GetContentSetting(GURL("http://brave.com"), GURL(),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
setting = map->GetContentSetting(
GURL("http://brave.com"), GURL("https://firstParty"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);

// override should also apply to different scheme
setting = map->GetContentSetting(GURL("https://brave.com"), GURL(),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
setting = map->GetContentSetting(
GURL("https://brave.com"), GURL("https://firstParty"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);

// override should not apply to default
setting =
map->GetContentSetting(GURL(), GURL(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
// override should not apply to default
setting = map->GetContentSetting(GURL(), GURL("https://firstParty"),
ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2);
EXPECT_EQ(CONTENT_SETTING_DEFAULT, setting);
}

TEST_F(BraveShieldsUtilTest, GetFingerprintingControlType_Default) {
Expand All @@ -687,11 +653,6 @@ TEST_F(BraveShieldsUtilTest, GetFingerprintingControlType_Default) {
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_ALLOW);
map->SetContentSettingCustomScope(
ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::FromString("https://firstParty/*"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_ALLOW);
setting = brave_shields::GetFingerprintingControlType(profile(), GURL());
EXPECT_EQ(ControlType::ALLOW, setting);
setting = brave_shields::GetFingerprintingControlType(
Expand All @@ -703,11 +664,6 @@ TEST_F(BraveShieldsUtilTest, GetFingerprintingControlType_Default) {
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_BLOCK);
map->SetContentSettingCustomScope(
ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::FromString("https://firstParty/*"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_BLOCK);
setting = brave_shields::GetFingerprintingControlType(profile(), GURL());
EXPECT_EQ(ControlType::BLOCK, setting);
setting = brave_shields::GetFingerprintingControlType(
Expand All @@ -719,11 +675,6 @@ TEST_F(BraveShieldsUtilTest, GetFingerprintingControlType_Default) {
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_BLOCK);
map->SetContentSettingCustomScope(
ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::FromString("https://firstParty/*"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_ALLOW);
setting = brave_shields::GetFingerprintingControlType(profile(), GURL());
EXPECT_EQ(ControlType::BLOCK, setting);
setting = brave_shields::GetFingerprintingControlType(
Expand All @@ -743,11 +694,6 @@ TEST_F(BraveShieldsUtilTest, GetFingerprintingControlType_ForOrigin) {
ContentSettingsPattern::FromString("http://brave.com/*"),
ContentSettingsPattern::Wildcard(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2, CONTENT_SETTING_ALLOW);
map->SetContentSettingCustomScope(
ContentSettingsPattern::FromString("http://brave.com/*"),
ContentSettingsPattern::FromString("https://firstParty/*"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_ALLOW);
setting = brave_shields::GetFingerprintingControlType(
profile(), GURL("http://brave.com"));
EXPECT_EQ(ControlType::ALLOW, setting);
Expand All @@ -759,11 +705,6 @@ TEST_F(BraveShieldsUtilTest, GetFingerprintingControlType_ForOrigin) {
ContentSettingsPattern::FromString("http://brave.com/*"),
ContentSettingsPattern::Wildcard(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2, CONTENT_SETTING_BLOCK);
map->SetContentSettingCustomScope(
ContentSettingsPattern::FromString("http://brave.com/*"),
ContentSettingsPattern::FromString("https://firstParty/*"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_BLOCK);
setting = brave_shields::GetFingerprintingControlType(
profile(), GURL("http://brave.com"));
EXPECT_EQ(ControlType::BLOCK, setting);
Expand All @@ -775,11 +716,6 @@ TEST_F(BraveShieldsUtilTest, GetFingerprintingControlType_ForOrigin) {
ContentSettingsPattern::FromString("http://brave.com/*"),
ContentSettingsPattern::Wildcard(), ContentSettingsType::PLUGINS,
brave_shields::kFingerprintingV2, CONTENT_SETTING_BLOCK);
map->SetContentSettingCustomScope(
ContentSettingsPattern::FromString("http://brave.com/*"),
ContentSettingsPattern::FromString("https://firstParty/*"),
ContentSettingsType::PLUGINS, brave_shields::kFingerprintingV2,
CONTENT_SETTING_ALLOW);
setting = brave_shields::GetFingerprintingControlType(
profile(), GURL("http://brave.com"));
EXPECT_EQ(ControlType::BLOCK, setting);
Expand Down

0 comments on commit ccb0267

Please sign in to comment.