Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent permissive HTTPS Upgrade settings from leaking from normal to incognito windows #17421

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions browser/brave_shields/https_upgrade_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,73 @@ IN_PROC_BROWSER_TEST_F(HttpsUpgradeBrowserTest_FlagDisabled, CheckUpgrades) {
}
}
}

IN_PROC_BROWSER_TEST_F(HttpsUpgradeBrowserTest, IsolateSettings) {
// Test host URLs.
GURL host1("https://example1.test");
GURL host2("https://example2.test");

// Test profiles
Profile* normal_profile = chrome_test_utils::GetProfile(this);
Profile* incognito_profile = normal_profile->GetOffTheRecordProfile(
Profile::OTRProfileID::PrimaryID(), /*create_if_needed=*/true);

auto* normal_map =
HostContentSettingsMapFactory::GetForProfile(normal_profile);
auto* incognito_map =
HostContentSettingsMapFactory::GetForProfile(incognito_profile);

// Disable upgrades for a site.
brave_shields::SetHttpsUpgradeControlType(normal_map, ControlType::ALLOW,
host1);
brave_shields::SetHttpsUpgradeControlType(incognito_map, ControlType::ALLOW,
host2);

// Disabled upgrade per-site in normal windows should not apply to incognito
// windows, nor vice versa.
EXPECT_EQ(ControlType::ALLOW,
brave_shields::GetHttpsUpgradeControlType(normal_map, host1));
EXPECT_EQ(ControlType::BLOCK_THIRD_PARTY,
brave_shields::GetHttpsUpgradeControlType(incognito_map, host1));
EXPECT_EQ(ControlType::BLOCK_THIRD_PARTY,
brave_shields::GetHttpsUpgradeControlType(normal_map, host2));
EXPECT_EQ(ControlType::ALLOW,
brave_shields::GetHttpsUpgradeControlType(incognito_map, host2));

// Set strict per-site settings.
brave_shields::SetHttpsUpgradeControlType(normal_map, ControlType::BLOCK,
host1);
brave_shields::SetHttpsUpgradeControlType(incognito_map, ControlType::BLOCK,
host2);

// A strict per-site setting in normal windows does apply to incognito
// windows, but not vice versa.
EXPECT_EQ(ControlType::BLOCK,
brave_shields::GetHttpsUpgradeControlType(normal_map, host1));
EXPECT_EQ(ControlType::BLOCK,
brave_shields::GetHttpsUpgradeControlType(incognito_map, host1));
EXPECT_EQ(ControlType::BLOCK,
brave_shields::GetHttpsUpgradeControlType(incognito_map, host2));
EXPECT_EQ(ControlType::BLOCK_THIRD_PARTY,
brave_shields::GetHttpsUpgradeControlType(normal_map, host2));

// Set global setting to strict.
brave_shields::SetHttpsUpgradeControlType(normal_map, ControlType::BLOCK,
GURL());

// Strict global upgrades should apply to both normal and incognito windows.
EXPECT_EQ(ControlType::BLOCK,
brave_shields::GetHttpsUpgradeControlType(normal_map, GURL()));
EXPECT_EQ(ControlType::BLOCK,
brave_shields::GetHttpsUpgradeControlType(incognito_map, GURL()));

// Set global setting to disabled.
brave_shields::SetHttpsUpgradeControlType(normal_map, ControlType::ALLOW,
GURL());

// Disabled global upgrades should apply to normal windows but not incognito.
EXPECT_EQ(ControlType::ALLOW,
brave_shields::GetHttpsUpgradeControlType(normal_map, GURL()));
EXPECT_EQ(ControlType::BLOCK_THIRD_PARTY,
brave_shields::GetHttpsUpgradeControlType(incognito_map, GURL()));
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class BraveContentSettingsBrowserTest : public InProcessBrowserTest {
ContentSettingsType::NOTIFICATIONS,
ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER,
ContentSettingsType::IDLE_DETECTION,
ContentSettingsType::BRAVE_HTTPS_UPGRADE,
};
if (base::Contains(kOffTheRecordAwareTypes, content_type)) {
return current_setting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void ContentSettingsRegistry::BraveInit() {
WebsiteSettingsInfo::TOP_ORIGIN_ONLY_SCOPE,
WebsiteSettingsRegistry::DESKTOP |
WebsiteSettingsRegistry::PLATFORM_ANDROID,
ContentSettingsInfo::INHERIT_IN_INCOGNITO,
ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE,
ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS);

Register(ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "base/containers/contains.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/features.h"

#if !BUILDFLAG(IS_IOS)
Expand All @@ -29,6 +30,7 @@ bool IsMorePermissive_BraveImpl(ContentSettingsType content_type,
ContentSettingsType::NOTIFICATIONS,
ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER,
ContentSettingsType::IDLE_DETECTION,
ContentSettingsType::BRAVE_HTTPS_UPGRADE,
};

const bool is_more_permissive = IsMorePermissive(setting, initial_setting);
Expand Down