diff --git a/deno.json b/deno.json index 2fc3c138e..d36213309 100644 --- a/deno.json +++ b/deno.json @@ -36,5 +36,5 @@ "jsx": "react-jsx", "jsxImportSource": "preact" }, - "version": "0.53.3" + "version": "0.53.4" } diff --git a/vtex/utils/segment.ts b/vtex/utils/segment.ts index 36eb9cfce..2d2ab7a76 100644 --- a/vtex/utils/segment.ts +++ b/vtex/utils/segment.ts @@ -171,11 +171,15 @@ export const setSegmentBag = ( const token = serialize(segment); setSegmentInBag(ctx, { payload: segment, token }); + const hostname = (new URL(req.url)).hostname; + const cookieDomain = hostname.startsWith(".") ? hostname : `.${hostname}`; + // Avoid setting cookie when segment from request matches the one generated if (vtex_segment !== token) { setCookie(ctx.response.headers, { value: token, name: SEGMENT_COOKIE_NAME, + domain: hostname === "localhost" ? "localhost" : cookieDomain, path: "/", secure: true, httpOnly: true,