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

feat(dbAuth): Lax SameSite cookie policy #11889

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions .changesets/11889.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- feat(dbAuth): Lax SameSite cookie policy (#11889) by @Tobbe

Setting the `SameSite` cookie policy to `Lax` allows users to be immediately
authenticated when arriving from external domains.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const handler = async (
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development',

// If you need to allow other domains (besides the api side) access to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const handler = async (
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development',

// If you need to allow other domains (besides the api side) access to
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/test-project/api/src/functions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const handler = async (
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development',

// If you need to allow other domains (besides the api side) access to
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/auth/dbauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ cookie: {
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: true,
// Domain: 'example.com',
},
Expand Down Expand Up @@ -360,7 +360,7 @@ cookie: {
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development' ? true : false,
// highlight-next-line
Domain: 'example.com'
Expand Down Expand Up @@ -564,7 +564,7 @@ export const handler = async (event, context) => {
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development' ? true : false,
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const authHandler = new DbAuthHandler(event, context, {
cookie: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: true,
},
forgotPassword: forgotPasswordOptions,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/how-to/oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ const secureCookie = (user) => {
`Expires=${expires.toUTCString()}`,
'HttpOnly=true',
'Path=/',
'SameSite=Strict',
'SameSite=Lax',
`Secure=${process.env.NODE_ENV !== 'development'}`,
]
const data = JSON.stringify({ id: user.id })
Expand Down Expand Up @@ -731,7 +731,7 @@ const secureCookie = (user) => {
`Expires=${expires.toUTCString()}`,
'HttpOnly=true',
'Path=/',
'SameSite=Strict',
'SameSite=Lax',
`Secure=${process.env.NODE_ENV !== 'development'}`,
]
const data = JSON.stringify({ id: user.id })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,7 @@ describe('dbAuth', () => {
attributes: {
Path: '/',
HttpOnly: true,
SameSite: 'Strict',
SameSite: 'Lax',
Secure: true,
Domain: 'example.com',
},
Expand All @@ -2580,7 +2580,7 @@ describe('dbAuth', () => {
expect(attributes.length).toEqual(6)
expect(attributes[0]).toEqual('Path=/')
expect(attributes[1]).toEqual('HttpOnly')
expect(attributes[2]).toEqual('SameSite=Strict')
expect(attributes[2]).toEqual('SameSite=Lax')
expect(attributes[3]).toEqual('Secure')
expect(attributes[4]).toEqual('Domain=example.com')
expect(attributes[5]).toMatch(`Expires=`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,7 @@ describe('dbAuth', () => {
attributes: {
Path: '/',
HttpOnly: true,
SameSite: 'Strict',
SameSite: 'Lax',
Secure: true,
Domain: 'example.com',
},
Expand All @@ -2380,7 +2380,7 @@ describe('dbAuth', () => {
expect(attributes.length).toEqual(6)
expect(attributes[0]).toEqual('Path=/')
expect(attributes[1]).toEqual('HttpOnly')
expect(attributes[2]).toEqual('SameSite=Strict')
expect(attributes[2]).toEqual('SameSite=Lax')
expect(attributes[3]).toEqual('Secure')
expect(attributes[4]).toEqual('Domain=example.com')
expect(attributes[5]).toMatch(`Expires=`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const handler = async (
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development',

// If you need to allow other domains (besides the api side) access to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const handler = async (
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development' ? true : false,

// If you need to allow other domains (besides the api side) access to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const handler = async (
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development' ? true : false,

// If you need to allow other domains (besides the api side) access to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const handler = async (
attributes: {
HttpOnly: true,
Path: '/',
SameSite: 'Strict',
SameSite: 'Lax',
Secure: process.env.NODE_ENV !== 'development' ? true : false,

// If you need to allow other domains (besides the api side) access to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ test('Retrieving request details in a', async ({ page }) => {
expires: Math.floor(Date.now() / 1000) + 300, // 5 minutes from now in seconds
secure: true,
httpOnly: true,
sameSite: 'Strict',
sameSite: 'Lax',
},
])

Expand Down
Loading