Skip to content

Commit c7e8f68

Browse files
fix: default cookie sameSite to 'lax' instead of 'none'
sameSite: 'none' sends cookies on all cross-site requests, weakening CSRF protection. Defaulting to 'lax' while allowing env override. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9441273 commit c7e8f68

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

shared/authentication/src/auth.definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const auth: Auth = betterAuth({
8787
// Subdomain-friendly cookie setting (recommended over cross-site cookies)
8888
advanced: {
8989
defaultCookieAttributes: {
90-
sameSite: 'none',
90+
sameSite: (process.env.COOKIE_SAME_SITE as 'lax' | 'strict' | 'none') || 'lax',
9191
secure: true,
9292
},
9393
},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
describe('auth.definition.ts cookie configuration', () => {
5+
const authDefPath = path.resolve(
6+
__dirname,
7+
'../../../shared/authentication/src/auth.definition.ts'
8+
);
9+
let source: string;
10+
11+
beforeAll(() => {
12+
source = fs.readFileSync(authDefPath, 'utf-8');
13+
});
14+
15+
it('should not use sameSite: none (weakens CSRF protection)', () => {
16+
const hardcodedNone = /sameSite:\s*['"]none['"]/;
17+
expect(source).not.toMatch(hardcodedNone);
18+
19+
expect(source).toMatch(/sameSite:/);
20+
});
21+
22+
it('should set secure: true on cookies', () => {
23+
expect(source).toMatch(/secure:\s*true/);
24+
});
25+
});

0 commit comments

Comments
 (0)