Notes/src/routes/csrf_protection.ts
Panagiotis Papadopoulos 9382c278b3 fix(csrf): add exception for electron for httpOnly cookie
it does not seem to like having httpOnly set in electron
2025-01-17 17:26:52 +01:00

17 lines
597 B
TypeScript

import { doubleCsrf } from "csrf-csrf";
import sessionSecret from "../services/session_secret.js";
import { isElectron } from "../services/utils.js";
const doubleCsrfUtilities = doubleCsrf({
getSecret: () => sessionSecret,
cookieOptions: {
path: "", // empty, so cookie is valid only for the current path
secure: false,
sameSite: "strict",
httpOnly: !isElectron() // set to false for Electron, see https://github.com/TriliumNext/Notes/pull/966
},
cookieName: "_csrf"
});
export const { generateToken, doubleCsrfProtection } = doubleCsrfUtilities;