Skip to content

Commit

Permalink
Merge pull request #4725 from sbwalker/dev
Browse files Browse the repository at this point in the history
fix #4714 as well as breaking change in #4712
  • Loading branch information
sbwalker authored Oct 14, 2024
2 parents 0e5b370 + 93bc1cd commit d952c33
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Oqtane.Client/UI/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public Interop(IJSRuntime jsRuntime)
_jsRuntime = jsRuntime;
}

public async Task SetCookie(string name, string value, int days)
{
await SetCookie(name, value, days, true, "Lax");
}

public Task SetCookie(string name, string value, int days, bool secure, string sameSite)
{
try
Expand Down
8 changes: 4 additions & 4 deletions Oqtane.Maui/wwwroot/js/interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Oqtane.Interop = {
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
var cookieString = name + "=" + value + ";" + expires + ";path=/";
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
cookieString += `; SameSite=${sameSite}`;
}
if (secure) {
cookieString += "; Secure";
cookieString += "; secure";
}
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
cookieString += "; SameSite=" + sameSite;
}
document.cookie = cookieString;
},
Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Server/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@
Expires = DateTimeOffset.UtcNow.AddYears(1),
SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax, // Set SameSite attribute
Secure = true, // Ensure the cookie is only sent over HTTPS
HttpOnly = true // Optional: Helps mitigate XSS attacks
HttpOnly = false // cookie is updated using JS Interop
};

Context.Response.Cookies.Append(
Expand Down
8 changes: 4 additions & 4 deletions Oqtane.Server/wwwroot/js/interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Oqtane.Interop = {
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
var cookieString = name + "=" + value + ";" + expires + ";path=/";
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
cookieString += `; SameSite=${sameSite}`;
}
if (secure) {
cookieString += "; Secure";
cookieString += "; secure";
}
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
cookieString += "; SameSite=" + sameSite;
}
document.cookie = cookieString;
},
Expand Down

0 comments on commit d952c33

Please sign in to comment.