Skip to content

Commit b0ede0f

Browse files
authored
Fix theme cookie parsing boundary checks (#2281)
1 parent c3374e1 commit b0ede0f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/utils/cookies.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export const getThemeCookie = (): string | null => {
88
const themeCookie = cookies.find((cookie) => cookie.trim().startsWith(`${THEME_COOKIE_NAME}=`))
99

1010
if (themeCookie) {
11-
return themeCookie.split('=')[1]
11+
const parts = themeCookie.split('=')
12+
// Safe boundary check: ensure we have at least 2 parts and the value is not empty
13+
return parts.length >= 2 && parts[1] ? parts[1] : null
1214
}
1315

1416
return null
@@ -32,7 +34,9 @@ export const parseThemeCookie = (cookieString: string): string => {
3234
const themeCookie = cookies.find((cookie) => cookie.trim().startsWith(`${THEME_COOKIE_NAME}=`))
3335

3436
if (themeCookie) {
35-
return themeCookie.split('=')[1] || 'true'
37+
const parts = themeCookie.split('=')
38+
// Safe boundary check: ensure we have at least 2 parts and the value is not empty
39+
return parts.length >= 2 && parts[1] ? parts[1] : 'true'
3640
}
3741

3842
return 'true'

0 commit comments

Comments
 (0)