我有两个网站,比如说example.com和anotherexample.net。 在anotherexample.net/page.html上,我有一个IFRAME SRC=“http://example.com/someform.asp”。IFRAME显示一个表单供用户填写并提交到http://example.com/process.asp。当我在它自己的浏览器窗口中打开表单(“someform.asp”)时,一切正常。 然而,当我在ie6或ie7中加载someform.asp作为IFRAME时,example.com的cookie没有保存。在Firefox中,这个问题不会出现。

出于测试目的,我在http://newmoon.wz.cz/test/page.php上创建了一个类似的设置。

example.com使用基于cookie的会话(对此我无能为力),因此如果没有cookie, process.asp将无法执行。我如何迫使IE保存这些cookie ?

嗅探HTTP流量的结果:在GET /someform.asp响应中,有一个有效的每会话Set-Cookie报头(例如Set-Cookie: ASPKSJIUIUGF=JKHJUHVGFYTTYFY),但在POST /process.asp请求中,根本没有Cookie报头。

Edit3:一些AJAX+服务器端脚本显然能够避开这个问题,但这看起来非常像一个bug,而且它还打开了一组全新的安全漏洞。我不希望我的应用程序使用漏洞+安全漏洞的组合只是因为它很容易。

编辑:P3P政策是根本原因,详细解释如下。


当前回答

这篇文章提供了一些关于P3P的评论,以及一个减少IE7和IE8问题的捷径解决方案。

其他回答

在Rails 3.2中,我使用:

class ApplicationController < ActionController::Base  

  before_filter :set_p3p  

  private  
    # for IE session cookies thru iframe  
    def set_p3p  
      headers['P3P'] = 'CP="ALL DSP COR CURa ADMa DEVa OUR IND COM NAV"'  
    end  
end  

我从http://dot-net-web-developer-bristol.blogspot.com/2012/04/setting-p3p-header-in-rails-session.html得到了这个

更好的解决方案是在iframe中对页面进行Ajax调用,以获取/设置cookie…

任何人在node.js中遇到这个问题。

然后添加这个p3p模块,并在中间件中启用这个模块。

npm install p3p

我正在使用express,所以我在app.js中添加了它

首先在app.js中需要该模块

var express = require('express');
var app = express();
var p3p = require('p3p');

然后将其用作中间件

app.use(p3p(p3p.recommended));

它将在res对象中添加p3p头文件。不需要做任何额外的事情。

更多信息请访问:

https://github.com/troygoode/node-p3p

我正在调查这个关于通过Azure访问控制服务登录的问题,并且无法连接任何东西的头部和尾部。

然后,无意中看到了这个帖子https://blogs.msdn.microsoft.com/ieinternals/2011/03/10/beware-cookie-sharing-in-cross-zone-scenarios/

简而言之,IE不会跨区域共享cookie。互联网vs.可信站点)。

所以,如果你的IFrame目标和html页面在不同的区域的P3P不会有任何帮助。

我也有这个问题,我想我会张贴我在我的MVC2项目中使用的代码。当你在页面生命周期中添加头时要小心,否则你会得到一个HttpException“服务器不能在HTTP头发送后追加头”。我在onactionexecution方法上使用了自定义ActionFilterAttribute(在动作执行之前调用)。

/// <summary>
/// Privacy Preferences Project (P3P) serve a compact policy (a "p3p" HTTP header) for all requests
/// P3P provides a standard way for Web sites to communicate about their practices around the collection, 
/// use, and distribution of personal information. It's a machine-readable privacy policy that can be 
/// automatically fetched and viewed by users, and it can be tailored to fit your company's specific policies.
/// </summary>
/// <remarks>
/// More info http://www.oreillynet.com/lpt/a/1554
/// </remarks>
public class P3PAttribute : ActionFilterAttribute
{
    /// <summary>
    /// On Action Executing add a compact policy "p3p" HTTP header
    /// </summary>
    /// <param name="filterContext"></param>
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext.Current.Response.AddHeader("p3p","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");

        base.OnActionExecuting(filterContext);
    }
}

使用示例:

[P3P]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewData["Message"] = "Welcome!";

        return View();
    }

    public ActionResult About()
    {
        return View();
    }
}