Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Commit

Permalink
fix: sent cookies with sameSite=none
Browse files Browse the repository at this point in the history
So Chrome will include it in cross-site requests
  • Loading branch information
coderbyheart committed Sep 13, 2021
1 parent 5199cfe commit 080fd5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/authenticateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const authCookie = (
secure: true,
httpOnly: true,
expires: new Date(Date.now() + lifetimeInMinutes * 60 * 1000),
sameSite: 'none',
},
]

Expand All @@ -72,6 +73,7 @@ export const expireAuthCookie = (): [string, string, CookieOptions] => [
secure: true,
httpOnly: true,
expires: new Date(Date.now() - 60 * 1000),
sameSite: 'none',
},
]

Expand Down
12 changes: 10 additions & 2 deletions src/tests/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ describe('User account API', () => {

const cookieInfo = parseCookie(res.header['set-cookie'][0] as string)
expect(cookieInfo[authCookieName]).toBeDefined()
expect(cookieInfo.options).toMatchObject({ Path: '/', HttpOnly: true })
expect(cookieInfo.options).toMatchObject({
Path: '/',
HttpOnly: true,
sameSite: 'none',
})
const expiresIn =
new Date(cookieInfo.options.Expires).getTime() - Date.now()
expect(expiresIn).toBeLessThan(30 * 60 * 1000)
Expand Down Expand Up @@ -207,7 +211,11 @@ describe('User account API', () => {
.expect(204)
const cookieInfo = parseCookie(res.header['set-cookie'][0] as string)
expect(cookieInfo[authCookieName]).toBeDefined()
expect(cookieInfo.options).toMatchObject({ Path: '/', HttpOnly: true })
expect(cookieInfo.options).toMatchObject({
Path: '/',
HttpOnly: true,
sameSite: 'none',
})
const expiresIn =
new Date(cookieInfo.options.Expires).getTime() - Date.now()
expect(expiresIn).toBeLessThan(0) // Expires is in the past
Expand Down

0 comments on commit 080fd5d

Please sign in to comment.