Skip to content

Commit 905aedb

Browse files
authored
Merge commit from fork
1 parent 5463db2 commit 905aedb

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎src/utils/cookie.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe('Set cookie', () => {
350350
}).toThrowError('Partitioned Cookie must have Secure attributes')
351351
})
352352

353-
it('Should throw Error cookie with domain or path containing ";", "\\r", or "\\n"', () => {
353+
it('Should throw Error cookie with domain, path, sameSite, or priority containing ";", "\\r", or "\\n"', () => {
354354
// domain
355355
expect(() => {
356356
serialize('great_cookie', 'banana', { domain: 'example.com;evil' })
@@ -372,6 +372,28 @@ describe('Set cookie', () => {
372372
expect(() => {
373373
serialize('great_cookie', 'banana', { path: '/\nevil' })
374374
}).toThrowError('path must not contain ";", "\\r", or "\\n"')
375+
376+
// sameSite
377+
expect(() => {
378+
serialize('great_cookie', 'banana', { sameSite: 'Strict;evil' as 'Strict' })
379+
}).toThrowError('sameSite must not contain ";", "\\r", or "\\n"')
380+
expect(() => {
381+
serialize('great_cookie', 'banana', { sameSite: 'Strict\revil' as 'Strict' })
382+
}).toThrowError('sameSite must not contain ";", "\\r", or "\\n"')
383+
expect(() => {
384+
serialize('great_cookie', 'banana', { sameSite: 'Strict\nevil' as 'Strict' })
385+
}).toThrowError('sameSite must not contain ";", "\\r", or "\\n"')
386+
387+
// priority
388+
expect(() => {
389+
serialize('great_cookie', 'banana', { priority: 'High;evil' as 'High' })
390+
}).toThrowError('priority must not contain ";", "\\r", or "\\n"')
391+
expect(() => {
392+
serialize('great_cookie', 'banana', { priority: 'High\revil' as 'High' })
393+
}).toThrowError('priority must not contain ";", "\\r", or "\\n"')
394+
expect(() => {
395+
serialize('great_cookie', 'banana', { priority: 'High\nevil' as 'High' })
396+
}).toThrowError('priority must not contain ";", "\\r", or "\\n"')
375397
})
376398

377399
it('Should throw Error for invalid cookie name', () => {

‎src/utils/cookie.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const _serialize = (name: string, value: string, opt: CookieOptions = {}): strin
191191
}
192192
}
193193

194-
for (const key of ['domain', 'path'] as (keyof CookieOptions)[]) {
194+
for (const key of ['domain', 'path', 'sameSite', 'priority'] as (keyof CookieOptions)[]) {
195195
if (opt[key] && /[;\r\n]/.test(opt[key] as string)) {
196196
throw new Error(`${key} must not contain ";", "\\r", or "\\n"`)
197197
}

0 commit comments

Comments
 (0)