【发布时间】:2018-11-03 10:40:47
【问题描述】:
我有一个连接到 Identity server 4 身份服务器的 Asp .net mvc 应用程序。当我发布应用程序时,我被这个错误迷住了。
从上游读取响应标头时,上游发送了太大的标头
我已经追踪到这个upstream sent too big header while reading response header from upstream
我无法更改配置,系统管理员已声明我们需要使标题更小。
看了之后,我不得不同意这些标题有点广泛。
应用中的 Startup.cs
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = Configuration["ServiceSettings:IdentityServerEndpoint"];
options.RequireHttpsMetadata = true;
options.ClientId = Configuration["ServiceSettings:ClientId"];
options.ClientSecret = Configuration["ServiceSettings:secret"];
options.Scope.Add("testapi");
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Events = new OpenIdConnectEvents()
{
OnRemoteFailure = ctx =>
{
_logger.LogCritical($"Remote Faliure: {ctx.Failure}");
ctx.HandleResponse();
return Task.FromResult(0);
}
};
});
我一直在寻找,我似乎无法找到限制这个巨大标题大小的方法。
【问题讨论】:
-
您需要将身份验证信息存储在服务器上,而不是存储在 cookie 中。这是一个示例代码,展示了如何做到这一点:github.com/aspnet/Security/tree/dev/samples/CookieSessionSample(关键部分是
.AddCookie(o => o.SessionStore = new MemoryCacheTicketStore())) -
奇怪我的代码直接来自Identiy server 4教程。
-
如果我在本地运行它,它工作正常。该用户还可以登录另一个使用隐式授权的应用程序,该应用程序与这个混合的应用程序相对。 (抱怨索赔规模)
-
我们遇到了同样的问题(使用 .NET Framework 客户端,但我认为原因在 .NET Core 中是相同的) - 微软中间件和随之而来的加密正在创建这个巨大的饼干。索赔的数量并不重要(或至少不重要)。我们最终按照 Evk 的建议进行了操作——将身份验证信息存储在数据库中并发布我们自己的 cookie。我们将 cookie 从大约 3k 缩小到小于 0.5k,问题就消失了。
-
@m3n7alsnak3 这对无状态运行有何影响?
标签: c# header asp.net-core-mvc identityserver4