From ada8ffd3b905c4d4c2d560c4a1229e3818c9e519 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Wed, 3 Sep 2025 23:27:00 +0530 Subject: [PATCH] fix: make CSRF cookies accessible in embedded iframe contexts (#23556) - Use SameSite=None for HTTPS and SameSite=Lax for development - Follows same pattern as reserveSlot handler for embed compatibility - Fixes 403 errors when cancelling bookings in embedded forms Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/web/app/api/csrf/route.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/web/app/api/csrf/route.ts b/apps/web/app/api/csrf/route.ts index 86d4ba410c..33d5dbc9b8 100644 --- a/apps/web/app/api/csrf/route.ts +++ b/apps/web/app/api/csrf/route.ts @@ -1,15 +1,21 @@ import { randomBytes } from "crypto"; import { NextResponse } from "next/server"; +import { WEBAPP_URL } from "@calcom/lib/constants"; + export async function GET() { const token = randomBytes(32).toString("hex"); const res = NextResponse.json({ csrfToken: token }); + // We need this cookie to be accessible from embeds where the booking flow is displayed within an iframe on a different origin. + // For third‑party iframe contexts (embeds on other sites), browsers require SameSite=None and Secure to make the cookie available. + // For local development on http://localhost we fall back to SameSite=Lax to avoid requiring https during development. + const useSecureCookies = WEBAPP_URL.startsWith("https://"); res.cookies.set("calcom.csrf_token", token, { httpOnly: true, - secure: process.env.NODE_ENV === "production", - sameSite: "lax", + secure: useSecureCookies, + sameSite: useSecureCookies ? "none" : "lax", path: "/", });