CookieStore: Add validation behavior for __Host- prefixed cookies
This change adds the following checks for "__Host-" prefixed cookies:
1. Disallows overwriting with an explicit domain
2. Disallows non "/" path
This behavior is mentioned in the spec here [1].
Creating a cookie that violates this will cause a crash without
this change.
[1] https://wicg.github.io/cookie-store/#prefixes
Change-Id: I20968f11759019921aa7a6b37602878a17b091ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151825
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760776}
diff --git a/cookie-store/cookieStore_special_names.tentative.https.any.js b/cookie-store/cookieStore_special_names.tentative.https.any.js
index a4b3117..1419666 100644
--- a/cookie-store/cookieStore_special_names.tentative.https.any.js
+++ b/cookie-store/cookieStore_special_names.tentative.https.any.js
@@ -32,3 +32,24 @@
`Deleting ${prefix} cookies should not fail in secure context`);
}, `cookieStore.delete with ${prefix} name on secure origin`);
});
+
+promise_test(async testCase => {
+ const currentUrl = new URL(self.location.href);
+ const currentDomain = currentUrl.hostname;
+ await promise_rejects_js(testCase, TypeError,
+ cookieStore.set('__Host-cookie-name', 'cookie-value', {
+ domain: currentDomain
+ }));
+}, 'cookieStore.set with __Host- prefix and a domain option');
+
+promise_test(async testCase => {
+ await cookieStore.set('__Host-cookie-name', 'cookie-value', { path: "/" });
+
+ assert_equals(
+ (await cookieStore.get(`__Host-cookie-name`)).value, "cookie-value");
+
+ await promise_rejects_js(testCase, TypeError,
+ cookieStore.set('__Host-cookie-name', 'cookie-value', {
+ path: "/path"
+ }));
+}, 'cookieStore.set with __Host- prefix a path option');