1

我使用 ADFS 2.0 作为使用 asp.net mvc2 和 SQL Server 2012 开发的应用程序的身份验证过程。为了解决这个问题:点击劫持(又名跨站点框架或 XSF),我们设置了 X-Frame- web.config 文件中值为 DENY 的选项。

重现步骤: 1. 使用 Chrome 浏览器使用有效凭据登录应用程序。2.系统向我显示应用程序登陆页面。3. 点击 F12 打开开发者工具选项。4. 现在单击注销选项并导航到控制台窗口。5. 系统显示 ADFS Signout 页面,但我仍然在控制台窗口中收到错误,如下所述:

拒绝在框架中显示“ https://mytestwebsite.com/?wa=wsignoutcleanup1.0 ”,因为它将“X-Frame-Options”设置为“DENY”。

在检查 ADFS Sognout 页面的 ViewSource 时,我看到以下内容:

<iframe class="Test" src="https://mytestwebsite.com/?wa=wsignoutcleanup1.0">
</iframe>

谁能建议我解决上述问题的最佳方法?

4

1 回答 1

0

一种选择是什么都不做。注销清理的重要部分是删除 mytestwebsite.com 的身份验证 cookie,这仍然可以完成,因为 http 标头仍在处理中,即使未显示生成的 iframe 内容。

允许 iframe 内容呈现仅在以下情况下很重要:

  • 您的 Web 应用程序执行进一步的下游注销清理。即它包含自己的 iframe 标签来注销其他应用程序,或者
  • 您的 STS 使用 <img> 标记而不是 iframe 进行注销清理,并且您希望 WIF 返回的绿色勾号图像出现,或者
  • 您真的,真的不希望浏览器控制台中出现无害的错误消息。

如果确实有必要,您可以以编程方式将 x-frame-options DENY 添加到除 WS-federation 注销清理之外的所有响应。

对于 ASP.NET MVC 应用程序,您可以使用(在 Global.asax.cs 中):

    public override void Init()
    {
        base.Init();
        FederatedAuthentication.WSFederationAuthenticationModule.SigningOut += this.WSFederationAuthenticationModuleOnSigningOut;
    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        Response.Headers["X-Frame-Options"] = "DENY";
    }

    private void WSFederationAuthenticationModuleOnSigningOut(object sender, SigningOutEventArgs args)
    {
        if (args.IsIPInitiated)
        {
            Response.Headers.Remove("X-Frame-Options");
        }
    }
于 2015-03-18T22:16:37.033 回答