| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks. Care to cc me on the bug for visibility?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks. Care to cc me on the bug for visibility?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
TEST_F(ExtensionCookiesTest, AppendMatchingCookiesWithUserBlockedSite) {Add a comment of your choosing? Just an example:
```suggestion
// Ensures cookies from domains explicitly blocked by the user are excluded from
// matches.
TEST_F(ExtensionCookiesTest, AppendMatchingCookiesWithUserBlockedSite) {
```
Unsure if all regression tests in the bug are necessary? Should something like [this](crrev.com/c/8261206) be added to this CL?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +2 |
TEST_F(ExtensionCookiesTest, AppendMatchingCookiesWithUserBlockedSite) {Add a comment of your choosing? Just an example:
```suggestion
// Ensures cookies from domains explicitly blocked by the user are excluded from
// matches.
TEST_F(ExtensionCookiesTest, AppendMatchingCookiesWithUserBlockedSite) {
```
Done
Unsure if all regression tests in the bug are necessary? Should something like [this](crrev.com/c/8261206) be added to this CL?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
5 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: chrome/browser/extensions/api/cookies/cookies_unittest.cc
Insertions: 61, Deletions: 18.
@@ -309,6 +309,37 @@
EXPECT_CHECK_DEATH(cookies_helpers::CreateCookie(*opaque_cookie, "0"));
}
+namespace {
+
+std::vector<Cookie> GetMatchingCookiesForExtension(
+ const Extension* extension,
+ const std::string& domain = "example.com") {
+ auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
+ "ABC", "DEF", domain, "/", base::Time(), base::Time(), base::Time(),
+ base::Time(), false, false, net::CookieSameSite::NO_RESTRICTION,
+ net::COOKIE_PRIORITY_DEFAULT, net::CookieSourceType::kOther);
+ if (!cookie) {
+ return {};
+ }
+
+ base::DictValue dict;
+ dict.Set("storeId", "0");
+ auto details = GetAll::Params::Details::FromValue(dict);
+ if (!details) {
+ return {};
+ }
+
+ std::vector<Cookie> match_vector;
+ cookies_helpers::AppendMatchingCookiesFromCookieListToVector(
+ {*cookie}, &details.value(), extension, &match_vector,
+ net::CookiePartitionKeyCollection());
+ return match_vector;
+}
+
+} // namespace
+
+// Ensures cookies from domains explicitly blocked by the user are excluded from
+// matches.
TEST_F(ExtensionCookiesTest, AppendMatchingCookiesWithUserBlockedSite) {
base::test::ScopedFeatureList feature_list(
extensions_features::kExtensionsMenuAccessControl);
@@ -329,25 +360,37 @@
std::move(user_blocked_hosts),
/*user_allowed_hosts=*/{});
- auto cookie = net::CanonicalCookie::CreateUnsafeCookieForTesting(
- "ABC", "DEF", "example.com", "/", base::Time(), base::Time(),
- base::Time(), base::Time(), false, false,
- net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT,
- net::CookieSourceType::kOther);
- ASSERT_TRUE(cookie);
-
- base::DictValue dict;
- dict.Set("storeId", "0");
- auto details = GetAll::Params::Details::FromValue(dict);
- ASSERT_TRUE(details);
-
- std::vector<Cookie> match_vector;
- cookies_helpers::AppendMatchingCookiesFromCookieListToVector(
- {*cookie}, &details.value(), extension.get(), &match_vector,
- net::CookiePartitionKeyCollection());
-
// Since example.com is user-blocked, the cookie must not be matched.
- EXPECT_TRUE(match_vector.empty());
+ EXPECT_TRUE(GetMatchingCookiesForExtension(extension.get()).empty());
+}
+
+// Ensures cookies from domains with withheld host permissions are excluded from
+// matches.
+TEST_F(ExtensionCookiesTest, AppendMatchingCookiesWithWithheldPermissions) {
+ base::test::ScopedFeatureList feature_list(
+ extensions_features::kExtensionsMenuAccessControl);
+
+ base::ListValue host_permissions;
+ host_permissions.Append("*://*.example.com/*");
+
+ scoped_refptr<const Extension> extension =
+ ExtensionBuilder("Test Extension")
+ .SetManifestKey("host_permissions", std::move(host_permissions))
+ .Build();
+
+ // Withhold the host permission from the extension.
+ URLPatternSet withheld_hosts;
+ withheld_hosts.AddPattern(
+ URLPattern(URLPattern::SCHEME_ALL, "*://*.example.com/*"));
+
+ extension->permissions_data()->SetPermissions(
+ std::make_unique<PermissionSet>(),
+ std::make_unique<PermissionSet>(APIPermissionSet(),
+ ManifestPermissionSet(),
+ withheld_hosts.Clone(), URLPatternSet()));
+
+ // Since the permission is withheld, the cookie must not be matched.
+ EXPECT_TRUE(GetMatchingCookiesForExtension(extension.get()).empty());
}
} // namespace extensions
```
[Extensions] Enforce user site restrictions in chrome.cookies API
Previously, the chrome.cookies API verified host access permissions
using PermissionsData::HasHostPermission(url) which checks explicit
manifest host permissions and enterprise policy host blocks, but does
not check user host restrictions or withheld permissions.
So when a user explicitly turns off extensions for a site or withholds
host permissions, an extension with host permissions could continue
using chrome.cookies methods to read, create, and remove cookies for
that domain.
This CL replaces the HasHostPermission check with GetPageAccess which is
a superset of what HasHostPermission checks that also validates user
site restrictions, withheld permissions, enterprise policy, and
restricted URLs.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |