diff --git a/common/shield_exceptions.cc b/common/shield_exceptions.cc index 596242292de..339dadc896b 100644 --- a/common/shield_exceptions.cc +++ b/common/shield_exceptions.cc @@ -40,28 +40,36 @@ bool IsBlockedResource(const GURL& gurl) { bool IsWhitelistedFingerprintingException(const GURL& firstPartyOrigin, const GURL& subresourceUrl) { - static std::map > whitelist_patterns = { + static std::map > whitelist_patterns = { { - GURL("https://uphold.com/"), - std::vector({URLPattern(URLPattern::SCHEME_ALL, - "https://uphold.netverify.com/*")}) + URLPattern(URLPattern::SCHEME_ALL, "https://uphold.com/"), + std::vector({ + URLPattern(URLPattern::SCHEME_ALL, "https://uphold.netverify.com/*"), + URLPattern(URLPattern::SCHEME_ALL, "https://*.veriff.me/*"), + }) + }, + { + URLPattern(URLPattern::SCHEME_ALL, "https://sandbox.uphold.com/"), + std::vector({ + URLPattern(URLPattern::SCHEME_ALL, "https://*.netverify.com/*"), + URLPattern(URLPattern::SCHEME_ALL, "https://*.veriff.me/*"), + }) }, { - GURL("https://sandbox.uphold.com/"), + URLPattern(URLPattern::SCHEME_ALL, "https://*.1password.com/*"), std::vector({URLPattern(URLPattern::SCHEME_ALL, - "https://netverify.com/*")}) + "https://map.1passwordservices.com/*")}) } }; - std::map >::iterator i = - whitelist_patterns.find(firstPartyOrigin); - if (i == whitelist_patterns.end()) { - return false; + for (const auto whitelist : whitelist_patterns) { + if (whitelist.first.MatchesURL(firstPartyOrigin)) { + return std::any_of(whitelist.second.begin(), whitelist.second.end(), + [&subresourceUrl](const URLPattern& pattern) { + return pattern.MatchesURL(subresourceUrl); + }); + } } - std::vector &exceptions = i->second; - return std::any_of(exceptions.begin(), exceptions.end(), - [&subresourceUrl](const URLPattern& pattern) { - return pattern.MatchesURL(subresourceUrl); - }); + return false; } } // namespace brave diff --git a/common/shield_exceptions_unittest.cc b/common/shield_exceptions_unittest.cc index e280dbca28d..01f42d86d20 100644 --- a/common/shield_exceptions_unittest.cc +++ b/common/shield_exceptions_unittest.cc @@ -39,13 +39,16 @@ TEST_F(BraveShieldsExceptionsTest, IsWhitelistedFingerprintingException) { // Tests for sandbox URLs EXPECT_TRUE(IsWhitelistedFingerprintingException( GURL("https://sandbox.uphold.com"), - GURL("https://netverify.com/iframe"))); + GURL("https://sandbox-uphold.netverify.com/iframe"))); + EXPECT_TRUE(IsWhitelistedFingerprintingException( + GURL("https://sandbox.uphold.com/"), + GURL("https://random-subdomain.netverify.com"))); EXPECT_TRUE(IsWhitelistedFingerprintingException( GURL("https://sandbox.uphold.com/"), - GURL("https://netverify.com"))); + GURL("https://uphold.netverify.com"))); EXPECT_FALSE(IsWhitelistedFingerprintingException( GURL("http://sandbox.uphold.com/"), - GURL("https://uphold.netverify.com/"))); + GURL("https://netverify.com/"))); EXPECT_FALSE(IsWhitelistedFingerprintingException( GURL("https://sandbox.uphold.com/"), GURL("http://netverify.com/"))); @@ -53,11 +56,36 @@ TEST_F(BraveShieldsExceptionsTest, IsWhitelistedFingerprintingException) { GURL("https://netverify.com/iframe"), GURL("https://sandbox.uphold.com/"))); EXPECT_FALSE(IsWhitelistedFingerprintingException( - GURL("https://sandbox.uphold.com/"), - GURL("https://uphold.netverify.com/iframe"))); + GURL("https://random-subdomain.uphold.com/"), + GURL("https://netverify.com/iframe"))); EXPECT_FALSE(IsWhitelistedFingerprintingException( - GURL("https://www.sandbox.uphold.com/"), + GURL("http://www.sandbox.uphold.com/"), GURL("https://netverify.com/iframe"))); + + EXPECT_TRUE(IsWhitelistedFingerprintingException( + GURL("https://brave.1password.com"), + GURL("https://map.1passwordservices.com/iframe"))); + EXPECT_TRUE(IsWhitelistedFingerprintingException( + GURL("https://brave.1password.com/randompath"), + GURL("https://map.1passwordservices.com/"))); + EXPECT_TRUE(IsWhitelistedFingerprintingException( + GURL("https://1password.com/"), + GURL("https://map.1passwordservices.com/"))); + EXPECT_FALSE(IsWhitelistedFingerprintingException( + GURL("https://11password.com/"), + GURL("http://map.1passwordservices.com/"))); + EXPECT_FALSE(IsWhitelistedFingerprintingException( + GURL("https://map.1passwordservices.com/"), + GURL("https://map.1passwordservices.com/"))); + EXPECT_FALSE(IsWhitelistedFingerprintingException( + GURL("http://brave.1password.com/"), + GURL("https://map.1passwordservices.com/iframe"))); + EXPECT_FALSE(IsWhitelistedFingerprintingException( + GURL("https://1password.1passwordservices.com/"), + GURL("https://map.1passwordservices.com/"))); + EXPECT_FALSE(IsWhitelistedFingerprintingException( + GURL("https://brave.1password.com/"), + GURL("https://randompath.1passwordservices.com/"))); } } // namespace