Enhance theme handling in hooks.server.ts by introducing a set of allowed theme names and updating theme resolution logic to validate against this set.

This commit is contained in:
Sean Morley
2026-07-23 18:12:06 -04:00
parent 6e852b5f5e
commit ce400441c4

View File

@@ -1,6 +1,9 @@
import type { Handle } from '@sveltejs/kit';
import { sequence } from '@sveltejs/kit/hooks';
import { themes } from '$lib';
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
const ALLOWED_THEME_NAMES = new Set(themes.map((theme) => theme.name));
export const authHook: Handle = async ({ event, resolve }) => {
event.cookies.delete('csrftoken', { path: '/' });
@@ -88,7 +91,8 @@ export const authHook: Handle = async ({ event, resolve }) => {
};
export const themeHook: Handle = async ({ event, resolve }) => {
let theme = event.url.searchParams.get('theme') || event.cookies.get('colortheme');
const candidate = event.url.searchParams.get('theme') || event.cookies.get('colortheme');
const theme = candidate && ALLOWED_THEME_NAMES.has(candidate) ? candidate : null;
if (theme) {
return await resolve(event, {