我有两个网站,比如说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问题的捷径解决方案。

其他回答

一种可能的做法是将域添加到工具-> internet选项-> privacy -> sites: somedomain.com -> allow -> OK。

我可以通过简单地在IFrame (PHP解决方案)中添加这个小标题来消除邪恶的眼睛:

header('P3P: CP="NOI ADM DEV COM NAV OUR STP"');

记住按ctrl+F5重新加载你的网站,否则资源管理器可能仍然会显示邪恶之眼,尽管它工作正常。这可能是为什么我有这么多问题让它工作的主要原因。

根本不需要策略文件。

编辑: 我发现了一篇很好的博客文章,解释了IFrames中cookie的问题。它在c#代码中也有一个快速修复: 框架,ASPX页面和拒绝的cookie

我知道现在在这个问题上发表我的观点有点晚了,但我浪费了这么多时间,也许这个答案会帮助到别人。

我试图在我的网站上调用第三方cookie,当然它不能在ie10上工作,即使是在低安全级别…别问我为什么。在iframe中,我用ajax调用read_cookie.php (echo $_COOKIE)。

我不知道为什么我不能设置P3P策略来解决这个问题……

在我的搜索过程中,我看到了一些关于在JSON中获得cookie的工作。我甚至没有尝试,因为我认为如果cookie不会通过iframe,它将不会再通过数组…

你猜怎么着,确实如此!所以如果你json_encode你的cookie,然后解码后你的ajax请求,你会得到它!

也许我错过了什么,如果我错过了,我很抱歉,但我从没见过这么蠢的东西。阻止第三方cookie的安全性,为什么不,但让它通过编码?保安现在在哪里?

我希望这篇文章能帮助别人,如果我错过了什么,我很笨,请教育我!

我也有这个问题,我想我会张贴我在我的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();
    }
}

在Rails中,我使用这个宝石:https://github.com/merchii/rack-iframe Bawically它设置了一组没有引用文件的缩写:https://github.com/merchii/rack-iframe/blob/master/lib/rack/iframe.rb#L8

当您完全不关心p3p内容的含义时,它很容易安装。