【发布时间】:2022-01-18 12:43:27
【问题描述】:
在 .net Core 中,我们使用 IAntiforgery 配置防伪功能以及 [ValidateAntiForgeryToken] 或 AutoValidateAntiforgeryToken 来防止跨站点请求伪造 (XSRF/CSRF) 攻击。
在我们使用的中间件中配置防伪功能
var antiforgery = app.Services.GetRequiredService<IAntiforgery>();
app.Use((context, next) =>
{
var requestPath = context.Request.Path.Value;
if (string.Equals(requestPath, "/", StringComparison.OrdinalIgnoreCase)
|| string.Equals(requestPath, "/index.html", StringComparison.OrdinalIgnoreCase))
{
var tokenSet = antiforgery.GetAndStoreTokens(context);
context.Response.Cookies.Append("XSRF-TOKEN", tokenSet.RequestToken!,
new CookieOptions { HttpOnly = false });
}
return next(context);
});
现在我的问题是如果我们设置 new CookieOptions { HttpOnly = True }); 那么我们需要在服务器端和客户端做哪些改变
【问题讨论】:
标签: c# .net asp.net-core csrf x-xsrf-token