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

Add support for partitioned cookies to CookieStore. #206

Merged
merged 9 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 55 additions & 0 deletions explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
+ [Read a cookie](#read-a-cookie)
+ [Read multiple cookies](#read-multiple-cookies)
+ [Read the cookies for a specific URL](#read-the-cookies-for-a-specific-url)
+ [Read a partitioned cookie](#read-a-partitioned-cookie)
* [The Modifications API](#the-modifications-api)
+ [Write a cookie](#write-a-cookie)
+ [Write a partitioned cookie](#write-a-partitioned-cookie)
+ [Delete a cookie](#delete-a-cookie)
+ [Delete a partitioned cookie](#delete-a-partitioned-cookie)
+ [Access all the cookie data](#access-all-the-cookie-data)
* [The Change Events API](#the-change-events-api)
+ [Get change events in documents](#get-change-events-in-documents)
Expand Down Expand Up @@ -263,6 +266,22 @@ any URL under their scope.
Documents can only obtain the cookies at their current URL. In other words,
the only valid `url` value in Document contexts is the document's URL.

### Read a partitioned cookie

If the user agent supports
DCtheTall marked this conversation as resolved.
Show resolved Hide resolved
[cookie partitioning](https://github.com/DCtheTall/CHIPS), then the cookie
DCtheTall marked this conversation as resolved.
Show resolved Hide resolved
objects will have a boolean value indicating if the cookie is partitioned.

```javascript
// Read a cookie set without the Partitioned attribute.
const cookie = await cookieStore.get('session_id');
console.log(cookie.partitioned); // -> false

// Read a Partitioned cookie from a third-party context.
DCtheTall marked this conversation as resolved.
Show resolved Hide resolved
const cookie = await cookieStore.get('__Host-third_party_session_id');
console.log(cookie.partitioned); // -> true
```

## The Modifications API

Both documents and service workers access the same modification API, via the
Expand Down Expand Up @@ -292,6 +311,21 @@ await cookieStore.set({
});
```

### Write a partitioned cookie

If the user agent supports [cookie partitioning](https://github.com/WICG/CHIPS)
DCtheTall marked this conversation as resolved.
Show resolved Hide resolved
then you can set a partitioned cookie in a third-party context using the following.

```javascript
await cookieStore.set({
name: '__Host-third_party_session_id',
value: 'foobar',
path: '/',
sameSite: 'none'
// `Secure` is implicitly set
});
```

### Delete a cookie

```javascript
Expand All @@ -316,6 +350,27 @@ try {
}
```

### Delete a partitioned cookie

If the user agent supports [cookie partitioning](https://github.com/WICG/CHIPS)
DCtheTall marked this conversation as resolved.
Show resolved Hide resolved
then it is possible for a site to set both a partitioned and unpartitioned
cookie with the same name.

In this edge case, if a site would like to distinguish between whether they
DCtheTall marked this conversation as resolved.
Show resolved Hide resolved
want to delete their partitioned and unpartitioned cookie, they can provide
a `partitioned` attribute. If the site wants to delete the partitioned cookie,
the site could use:

```javascript
await cookieStore.delete({
name: '__Host-third_party_session_id',
partitioned: true
});
```

If the site wants to delete the unpartitioned cookie, change the `partitioned`
field to `false`.

### Access all the cookie data

The objects returned by `get` and `getAll` contain all the information in the
Expand Down
2 changes: 1 addition & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ dictionary CookieStoreDeleteOptions {
required USVString name;
USVString? domain = null;
USVString path = "/";
boolean? partitioned;
boolean partitioned;
};

dictionary CookieListItem {
Expand Down