Skip to content

Commit

Permalink
fix: cookiehub destroying csrf token
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Jan 10, 2025
1 parent 6e0b060 commit cc8a23a
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions apps/ui/components/ExternalScripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@ 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",
];

// Hack to make cookiehub not destroy our cookies
// temporary for a few weeks to fix critical production issue
const addCookieHubExceptions = `
const cookies = ["csrftoken", "sessionid", "language"];
for (let i = 0; i < cookies.length; i++) {
window.__cookiehub.cookies.push({
category: (window.__cookiehub.categories.find((c) => c.implicit).id),
expiry: "365 {day}",
display_name: cookies[i],
hide: 0,
hosts: ${JSON.stringify(hosts)},
http_only: 0,
id: 99990 + i,
name: cookies[i],
path: "/",
prefix: 0,
secure: 0,
third_party: 0,
type: 1
});
}
`;
export function ExternalScripts({
cookiehubEnabled,
matomoEnabled,
Expand All @@ -25,7 +54,7 @@ export function ExternalScripts({
__html: `
var cpm = {
cookie: {
domain: ''
domain: "",
},
language: document.documentElement.lang !== null
? document.documentElement.lang.substr(0, 2)
Expand All @@ -34,7 +63,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);
`,
Expand Down

0 comments on commit cc8a23a

Please sign in to comment.