From 642bafaecc8d46605033857f7e76f8dbb6993693 Mon Sep 17 00:00:00 2001 From: Joonatan Kuosa Date: Fri, 10 Jan 2025 10:38:34 +0200 Subject: [PATCH] wip: fix: cookiehub destroying csrf token --- apps/ui/components/ExternalScripts.tsx | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/apps/ui/components/ExternalScripts.tsx b/apps/ui/components/ExternalScripts.tsx index e3fd19c893..27463d39c7 100644 --- a/apps/ui/components/ExternalScripts.tsx +++ b/apps/ui/components/ExternalScripts.tsx @@ -2,6 +2,31 @@ import React from "react"; import Script from "next/script"; import { isBrowser } from "@/modules/const"; +const hosts = [ + "tilavaraus.hel.fi", + "tilavaraus.dev.hel.ninja", + "tilavaraus.test.hel.ninja", + "tilavaraus.stage.hel.ninja", +]; + +const addCookieHubExceptions = ` + console.log("Adding cookiehub exceptions"); + window.__cookiehub.cookies.push({ + category: (window.__cookiehub.categories.find((c) => c.implicit).id), + expiry: "365 {day}", + display_name: "csrftoken", + hide: 0, + hosts: ${JSON.stringify(hosts)}, + http_only: 0, + id: 99999, + name: "csrftoken", + path: "/", + prefix: 0, + secure: 0, + third_party: 0, + type: 1 + }); +`; export function ExternalScripts({ cookiehubEnabled, matomoEnabled, @@ -25,7 +50,7 @@ export function ExternalScripts({ __html: ` var cpm = { cookie: { - domain: '' + domain: "", }, language: document.documentElement.lang !== null ? document.documentElement.lang.substr(0, 2) @@ -34,7 +59,10 @@ var cpm = { (function(h,u,b){ var d=h.getElementsByTagName("script")[0],e=h.createElement("script"); e.async=true;e.src='https://cookiehub.net/c2/c7e96adf.js'; -e.onload=function(){u.cookiehub.load(b);} +e.onload=function(){ + u.cookiehub.load(b); + ${addCookieHubExceptions}; +} d.parentNode.insertBefore(e,d); })(document,window,cpm); `,