【问题标题】:400 Bad Request Request Header Or Cookie Too Large using Sustainsys.Saml2使用 Sustainsys.Saml2 的 400 错误请求标头或 Cookie 太大
【发布时间】:2021-03-06 00:38:20
【问题描述】:

在我的应用中使用 SustainSys.Saml2 库时出现浏览器错误:

400 Bad Request
Request Header Or Cookie Too Large
nginx/1.14.0

我认为减少我的 cookie 大小可能会有所帮助,我只需要来自声明数据的电子邮件,所以我认为如果我可以保存电子邮件声明并删除其他声明,它可能会减少我的 cookie 大小和修复此错误。

我阅读了对类似问题 (SustainSys.Saml2 Request length header too long) 的回复,并查找了有关如何实施 AcsCommandResultCreated 以删除未使用的声明(并希望减少 cookie 大小)的一些信息。我没有找到很多文档,但确实拼凑了一些想法和代码来尝试尝试一下。

我已经在我的 global.asax 以及一个控制器操作中尝试了这段代码(我在 Saml2/Acs 之后创建了“returnUrl”)。我的 FedAuth cookie(由 Saml2/Acs 设置)看起来一点也不小。任何cmets或建议?谢谢。

// Check if email claim exists
var principal = ClaimsPrincipal.Current;
var userEmail = principal.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Email)?.Value;

// Create new command result that only contains the email claim
if (userEmail != null)
{
      var emailClaim = principal.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Email);
                
      Sustainsys.Saml2.Configuration.Options.FromConfiguration.Notifications.AcsCommandResultCreated =
      (commandResult, response) =>
      {
           var newCommandResult = new Sustainsys.Saml2.WebSso.CommandResult();
           newCommandResult.Principal.Claims.Append(emailClaim);
           commandResult = newCommandResult;
      };
}

更新: 事实证明,我使用的测试环境(使用 nginx)需要增加请求头缓冲区的大小。添加这些 cookie 会将大小增加到大约 9500 字节,默认情况下,nginx 的请求标头缓冲区大小低于此大小(我认为是 8000)。联系运行 nginx 的测试服务器的代码所有者,并增加它解决了我的问题,而无需减小我的 cookie 大小。

【问题讨论】:

    标签: cookies model-view-controller sustainsys-saml2 .net-framework-4.8


    【解决方案1】:

    您是否有很多失败的身份验证尝试?这可能会在域上留下很多 Saml2.XYZ 相关 cookie。尝试检查浏览器开发工具并清理它们。

    “标头太大”通常是在用户尝试登录多次但失败并且这些 cookie 卡住时发生的情况。真正的问题通常是其他问题 - 导致身份验证失败以及相关 cookie 不断累积。

    【讨论】:

    • 我没有失败的身份验证尝试。更多信息:我将我的应用程序用作外部应用程序的代理。我正在使用带有扩展应用程序请求路由和 URL 重写的 IIS 来重写 url 并将请求从浏览器传递到外部应用程序。我只在 /logout 和 /refresh 上看到过这个错误。直接向外部应用程序发出请求(没有我的代理应用程序),/logout 端点正在响应五个 cookie 上的 Set-Cookie 以使它们过期。那么也许 Sustainsys 库在通过代理时不喜欢该操作?
    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    相关资源
    最近更新 更多