Skip to content

Add sameSite: 'lax' to cookie settings - #169

Merged
jean-michelet merged 2 commits into
fastify:mainfrom
aaronofinn:fix/session-cookie-missing-samesite
Sep 14, 2026
Merged

jean-michelet merged 2 commits into
fastify:mainfrom
aaronofinn:fix/session-cookie-missing-samesite

Conversation

@aaronofinn

Copy link
Copy Markdown
Contributor

Description

session.ts sets secure and httpOnly on the session cookie but never sameSite and there's no CSRF token mechanism anywhere in the app either. Whatever protection exists today is Chrome's own implicit default (treating a missing SameSite as Lax), an accident of the browser, not something this app's config actually asserts, and not something every client is guaranteed to apply consistently.

Adding sameSite: 'lax' to the cookie settings allows us to explicitly enforce that the session cookie is only sent on same-site requests, rather than depending on whichever browser happens to be in use applying its own undocumented default when the attribute is missing.

Checklist

@sonarqubecloud

Copy link
Copy Markdown

@jean-michelet

Copy link
Copy Markdown
Member

Adding sameSite: 'lax' to the cookie settings allows us to explicitly enforce that the session cookie is only sent on same-site requests

That's Strict, not Lax.

I planed to introduce CSRF building a SPA, but I always failed to fastify/vite with React.
Let's avoid it for now imo.

@aaronofinn

Copy link
Copy Markdown
Contributor Author

@jean-michelet would you mind merging? I don't have priveleges for some reason

@jean-michelet
jean-michelet merged commit 6617475 into fastify:main Sep 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants