Skip to content

Commit

Permalink
use 'lax' instead of 'Lax' as default for cookie sameSite option (#271)
Browse files Browse the repository at this point in the history
Change to support @fastify/cookie ^11.0.0

The downstream jshttp/cookie module now enforces the sameSite option to
be lowercase, which means this default is causing the plugin to throw
when setting the session cookie.

Signed-off-by: Niall Molloy <niall.molloy@engineering.digital.dwp.gov.uk>
  • Loading branch information
gunjam authored Oct 10, 2024
1 parent da1ad38 commit 4ad874e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = class Cookie {
if (request.protocol === 'https') {
this.secure = true
} else {
this.sameSite = 'Lax'
this.sameSite = 'lax'
this.secure = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"url": "git+https://github.com/fastify/session.git"
},
"devDependencies": {
"@fastify/cookie": "^10.0.0",
"@fastify/cookie": "^11.0.0",
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"c8": "^10.1.2",
Expand Down
4 changes: 2 additions & 2 deletions test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ test("clears cookie if not backed by a session, and there's nothing to save", as
})

t.assert.strictEqual(response.statusCode, 200)
t.assert.strictEqual(response.headers['set-cookie'], 'sessionId=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax')
t.assert.strictEqual(response.headers['set-cookie'], 'sessionId=; Max-Age=0; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax')
})

test("clearing cookie sets the domain if it's specified in the cookie options", async t => {
Expand All @@ -853,7 +853,7 @@ test("clearing cookie sets the domain if it's specified in the cookie options",
})

t.assert.strictEqual(response.statusCode, 200)
t.assert.strictEqual(response.headers['set-cookie'], 'sessionId=; Domain=domain.test; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax')
t.assert.strictEqual(response.headers['set-cookie'], 'sessionId=; Max-Age=0; Domain=domain.test; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax')
})

test('does not clear cookie if no session cookie in request', async t => {
Expand Down

0 comments on commit 4ad874e

Please sign in to comment.