diff --git a/packages/astro/src/core/session/runtime.ts b/packages/astro/src/core/session/runtime.ts index 13d689143fe5..47bd332feb9c 100644 --- a/packages/astro/src/core/session/runtime.ts +++ b/packages/astro/src/core/session/runtime.ts @@ -11,6 +11,7 @@ export const PERSIST_SYMBOL = Symbol(); const DEFAULT_COOKIE_NAME = 'astro-session'; const VALID_COOKIE_REGEX = /^[\w-]+$/; +const VALID_SESSION_ID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; interface SessionEntry { data: any; @@ -430,7 +431,7 @@ export class AstroSession { #ensureSessionID() { if (!this.#sessionID) { const cookieValue = this.#cookies.get(this.#cookieName)?.value; - if (cookieValue) { + if (cookieValue && VALID_SESSION_ID_REGEX.test(cookieValue)) { this.#sessionID = cookieValue; this.#sessionIDFromCookie = true; } else {