diff --git a/Oqtane.Server/wwwroot/js/interop.js b/Oqtane.Server/wwwroot/js/interop.js index 9bc74bb8..725e8ce5 100644 --- a/Oqtane.Server/wwwroot/js/interop.js +++ b/Oqtane.Server/wwwroot/js/interop.js @@ -1,11 +1,25 @@ var Oqtane = Oqtane || {}; Oqtane.Interop = { - setCookie: function (name, value, days) { + setCookie: function (name, value, days, secure, httpOnly, sameSite) { var d = new Date(); d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); - document.cookie = name + "=" + value + ";" + expires + ";path=/"; + var cookieString = name + "=" + value + ";" + expires + ";path=/"; + + // Add SameSite attribute + if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") { + cookieString += `; SameSite=${sameSite}`; + } + + // Add Secure attribute + if (secure) { + cookieString += "; Secure"; + } + + // Note: HttpOnly cannot be set here; it needs to be handled server-side. + + document.cookie = cookieString; }, getCookie: function (name) { name = name + "=";