Skip to content

Commit 2a4e223

Browse files
authored
fix: Add SameSite=Lax to cookies for improved security (#23)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Closes #10
1 parent 0ef40bd commit 2a4e223

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/color-scheme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function subscribeToSchemeChange(
2121
const schemaMatch = window.matchMedia('(prefers-color-scheme: dark)')
2222
function handleThemeChange() {
2323
const value = schemaMatch.matches ? 'dark' : 'light'
24-
document.cookie = `${cookieName}=${value}; Max-Age=31536000; Path=/`
24+
document.cookie = `${cookieName}=${value}; Max-Age=31536000; SameSite=Lax; Path=/`
2525
subscriber(value)
2626
}
2727
schemaMatch.addEventListener('change', handleThemeChange)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function checkClientHints() {
7878
.join(',\n')}
7979
];
8080
for (const hint of hints) {
81-
document.cookie = encodeURIComponent(hint.name) + '=' + encodeURIComponent(hint.actual) + '; Max-Age=31536000; path=/';
81+
document.cookie = encodeURIComponent(hint.name) + '=' + encodeURIComponent(hint.actual) + '; Max-Age=31536000; SameSite=Lax; path=/';
8282
if (decodeURIComponent(hint.value) !== hint.actual) {
8383
cookieChanged = true;
8484
}

src/reduced-motion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function subscribeToMotionChange(
2121
const motionMatch = window.matchMedia('(prefers-reduced-motion: reduce)')
2222
function handleMotionChange() {
2323
const value = motionMatch.matches ? 'reduce' : 'no-preference'
24-
document.cookie = `${cookieName}=${value}; Max-Age=31536000; Path=/`
24+
document.cookie = `${cookieName}=${value}; Max-Age=31536000; SameSite=Lax; Path=/`
2525
subscriber(value)
2626
}
2727
motionMatch.addEventListener('change', handleMotionChange)

0 commit comments

Comments
 (0)