【问题标题】:How Can I remove the X-Frame-Options header in IdentityServer4?如何删除 IdentityServer4 中的 X-Frame-Options 标头?
【发布时间】:2020-07-21 07:02:16
【问题描述】:

我在 .Net Core 3.0 中有一个 IdentityServer4 项目,我尝试删除 X-Frame-Options 标头但失败了。我试过了:

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddAntiforgery(options => options.SuppressXFrameOptionsHeader = true);
    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...
    app.Use(async (context, next) =>
            {               
                context.Response.Headers.Remove("X-Frame-Options");
                await next();
            });
    ...
}

以上是因为我需要从 iframe 加载网页。 我真的很感谢你的帮助。 谢谢。

【问题讨论】:

    标签: iframe .net-core identityserver4 x-frame-options


    【解决方案1】:

    在 iframe 中托管您的登录屏幕确实是一种不好的做法,因为这样进行身份验证的用户不能 100% 确定他正在登录预期的 IdentityServer 而不是被黑服务器。这一切都与信任有关,IdentitServer(或身份提供者)的 URL 是确保用户登录到正确服务器的唯一方法。

    如果您仍需要删除它,请查看 IdentityServer 用户界面中的 SecurityHeadersAttribute.cs 类。

    【讨论】:

    • 感谢您的回复@Tore,我终于按照您的建议从 SecurityHeadersAttribute 文件中删除了标头。
    【解决方案2】:

    我终于从 SecurityHeadersAttribute.cs 文件中删除了标题。我刚刚在同一个文件中添加了 frame-ancestors 内容安全策略,以启用从允许域上的 iframe 加载。

    【讨论】:

      猜你喜欢
      • 2015-09-19
      • 2018-03-10
      • 2016-05-29
      • 2017-06-13
      • 2013-11-16
      • 2015-12-02
      • 1970-01-01
      • 2018-09-04
      • 2011-02-16
      相关资源
      最近更新 更多