gpt4 book ai didi

c# - 覆盖登录页面上的防伪 token 错误

转载 作者:太空狗 更新时间:2023-10-29 22:57:34 25 4
gpt4 key购买 nike

我的网站收到大量以下错误:

The provided anti-forgery token was meant for a different claims-baseduser than the current user.

The anti-forgery cookie token and form field token do not match.

如果防伪 token 不针对任何用户但包含登录页面上的用户,我想防止网站抛出错误,例如:

The provided anti-forgery token was meant for user "", but the currentuser is "Garret".

我不希望此异常应用于登录页面以外的任何其他页面。所以我不想将 AntiForgeryConfig.SuppressIdentityHeuristicChecks = true; 添加到整个站点。我还想尽可能保证网站的安全,因为它包含 HIPAA 数据。 我能做些什么来尽可能保证它的安全,但仍然试图防止登录页面上出现这个错误,因为它使用户难以使用?

该站点托管在负载平衡服务器上,但我认为这不是问题所在。我认为该错误主要是由于使用浏览器的后退按钮、登录页面在登录前打开了一段时间、已经登录或多次按登录导致的。此外,一些用户通过可能未加载页面并只是试图发布登录信息的应用程序访问它。

所以请告诉我最好的选择是什么,以防止登录页面上出现此错误,同时仍然尽可能安全?

最佳答案

我最终做的是在检查用户是否登录后手动检查防伪 token ,它似乎在提供相同安全性的同时工作。

    [HttpPost]
[AllowAnonymous]
//[ValidateAntiForgeryToken]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
// Skip the login process if the user is already logged in
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Index", "Home");
}
// Check the anti forgery token now
System.Web.Helpers.AntiForgery.Validate();
...

关于c# - 覆盖登录页面上的防伪 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37477723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com