我有两个网站,比如说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政策是根本原因,详细解释如下。
任何人在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
你也可以将p3p.xml和policy.xml文件结合起来:
单击/ home / ubuntu sites -分享- w3c xml p3p。
<META xmlns="http://www.w3.org/2002/01/P3Pv1">
<POLICY-REFERENCES>
<POLICY-REF about="#policy1">
<INCLUDE>/</INCLUDE>
<COOKIE-INCLUDE/>
</POLICY-REF>
</POLICY-REFERENCES>
<POLICIES>
<POLICY discuri="" name="policy1">
<ENTITY>
<DATA-GROUP>
<DATA ref="#business.name"></DATA>
<DATA ref="#business.contact-info.online.email"></DATA>
</DATA-GROUP>
</ENTITY>
<ACCESS>
<nonident/>
</ACCESS>
<!-- if the site has a dispute resolution procedure that it follows, a DISPUTES-GROUP should be included here -->
<STATEMENT>
<PURPOSE>
<current/>
<admin/>
<develop/>
</PURPOSE>
<RECIPIENT>
<ours/>
</RECIPIENT>
<RETENTION>
<indefinitely/>
</RETENTION>
<DATA-GROUP>
<DATA ref="#dynamic.clickstream"/>
<DATA ref="#dynamic.http"/>
</DATA-GROUP>
</STATEMENT>
</POLICY>
</POLICIES>
</META>
我发现添加头的最简单的方法是通过Apache代理和使用mod_headers,就像这样:
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /home/ubuntu/sites/shared/w3c/
ProxyRequests off
ProxyPass /w3c/ !
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
ProxyPreserveHost on
Header add p3p 'P3P:policyref="/w3c/p3p.xml", CP="NID DSP ALL COR"'
</VirtualHost>
因此,除了发送到/w3c/p3p.xml的请求外,我们将所有请求都代理到我们的应用服务器。
您可以使用W3C验证器进行测试
我也有这个问题,我想我会张贴我在我的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();
}
}
任何人在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