From e1b65a346e32375f7d3b0ae3c65485b7f7fea47e Mon Sep 17 00:00:00 2001 From: Beyondo <58893646+Beyondo@users.noreply.github.com> Date: Sun, 22 Dec 2024 03:13:35 +0200 Subject: [PATCH 1/2] Update cookie.ts --- src/utils/cookie.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/cookie.ts b/src/utils/cookie.ts index 16986667d..8c9903fd7 100644 --- a/src/utils/cookie.ts +++ b/src/utils/cookie.ts @@ -24,6 +24,7 @@ export type CookieOptions = { signingSecret?: string sameSite?: 'Strict' | 'Lax' | 'None' | 'strict' | 'lax' | 'none' partitioned?: boolean + priority?: 'Low' | 'Medium' | 'High' prefix?: CookiePrefixOptions } & PartitionedCookieConstraint export type CookiePrefixOptions = 'host' | 'secure' @@ -204,6 +205,10 @@ const _serialize = (name: string, value: string, opt: CookieOptions = {}): strin cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}` } + if (opt.priority) { + cookie += `; Priority=${opt.priority}` + } + if (opt.partitioned) { // FIXME: replace link to RFC // https://www.ietf.org/archive/id/draft-cutler-httpbis-partitioned-cookies-01.html#section-2.3 From 3f0e470575488931eea72722af51125e89b4e0a8 Mon Sep 17 00:00:00 2001 From: Beyondo <58893646+Beyondo@users.noreply.github.com> Date: Sun, 22 Dec 2024 19:50:30 +0200 Subject: [PATCH 2/2] Integrated `priority` option into setCookie serialization tests --- src/utils/cookie.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/cookie.test.ts b/src/utils/cookie.test.ts index d8ba7e515..199f7185d 100644 --- a/src/utils/cookie.test.ts +++ b/src/utils/cookie.test.ts @@ -170,10 +170,11 @@ describe('Set cookie', () => { maxAge: 1000, expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900)), sameSite: 'Strict', + priority: 'High', partitioned: true, }) expect(serialized).toBe( - '__Secure-great_cookie=banana; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Partitioned' + '__Secure-great_cookie=banana; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Priority=High; Partitioned' ) }) @@ -185,10 +186,11 @@ describe('Set cookie', () => { maxAge: 1000, expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900)), sameSite: 'Strict', + priority: 'High', partitioned: true, }) expect(serialized).toBe( - '__Host-great_cookie=banana; Max-Age=1000; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Partitioned' + '__Host-great_cookie=banana; Max-Age=1000; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Priority=High; Partitioned' ) }) @@ -210,10 +212,11 @@ describe('Set cookie', () => { maxAge: 1000, expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900)), sameSite: 'Strict', + priority: 'High', partitioned: true, }) expect(serialized).toBe( - 'great_cookie=banana.hSo6gB7YT2db0WBiEAakEmh7dtwEL0DSp76G23WvHuQ%3D; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Partitioned' + 'great_cookie=banana.hSo6gB7YT2db0WBiEAakEmh7dtwEL0DSp76G23WvHuQ%3D; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Priority=High; Partitioned' ) })