Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4714 as well as breaking change in #4712 #4725

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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