Unverified Commit 43a70c7e authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix Cookie Expiration (#10634)

parent ee7ea03a
...@@ -414,13 +414,19 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> { ...@@ -414,13 +414,19 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> {
? previous ? previous
: []), : []),
serialize(COOKIE_NAME_PRERENDER_BYPASS, '', { serialize(COOKIE_NAME_PRERENDER_BYPASS, '', {
maxAge: 0, // To delete a cookie, set `expires` to a date in the past:
// https://tools.ietf.org/html/rfc6265#section-4.1.1
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
expires: new Date(0),
httpOnly: true, httpOnly: true,
sameSite: 'strict', sameSite: 'strict',
path: '/', path: '/',
}), }),
serialize(COOKIE_NAME_PRERENDER_DATA, '', { serialize(COOKIE_NAME_PRERENDER_DATA, '', {
maxAge: 0, // To delete a cookie, set `expires` to a date in the past:
// https://tools.ietf.org/html/rfc6265#section-4.1.1
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
expires: new Date(0),
httpOnly: true, httpOnly: true,
sameSite: 'strict', sameSite: 'strict',
path: '/', path: '/',
......
...@@ -106,6 +106,7 @@ function runTests() { ...@@ -106,6 +106,7 @@ function runTests() {
const cookies = res.headers const cookies = res.headers
.get('set-cookie') .get('set-cookie')
.replace(/(=\w{3}),/g, '$1')
.split(',') .split(',')
.map(cookie.parse) .map(cookie.parse)
...@@ -113,15 +114,17 @@ function runTests() { ...@@ -113,15 +114,17 @@ function runTests() {
expect(cookies[0]).toMatchObject({ expect(cookies[0]).toMatchObject({
Path: '/', Path: '/',
SameSite: 'Strict', SameSite: 'Strict',
'Max-Age': '0', Expires: 'Thu 01 Jan 1970 00:00:00 GMT',
}) })
expect(cookies[0]).toHaveProperty('__prerender_bypass') expect(cookies[0]).toHaveProperty('__prerender_bypass')
expect(cookies[0]).not.toHaveProperty('Max-Age')
expect(cookies[1]).toMatchObject({ expect(cookies[1]).toMatchObject({
Path: '/', Path: '/',
SameSite: 'Strict', SameSite: 'Strict',
'Max-Age': '0', Expires: 'Thu 01 Jan 1970 00:00:00 GMT',
}) })
expect(cookies[1]).toHaveProperty('__next_preview_data') expect(cookies[1]).toHaveProperty('__next_preview_data')
expect(cookies[1]).not.toHaveProperty('Max-Age')
}) })
/** @type import('next-webdriver').Chain */ /** @type import('next-webdriver').Chain */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment