我有两个网站,比如说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政策是根本原因,详细解释如下。


当前回答

如果你拥有需要嵌入的域,那么你可以,在调用包含IFrame的页面之前,重定向到那个域,它将创建cookie并重定向回来, 如下所述:http://www.mendoweb.be/blog/internet-explorer-safari-third-party-cookie-problem/

这不仅适用于ie浏览器,也适用于Safari浏览器(因为Safari浏览器也会屏蔽第三方cookie)。

其他回答

我让它工作了,但解决方案有点复杂,所以请耐心等待。

发生了什么

实际上,Internet Explorer对IFRAME页面的信任程度较低(IE称其为“第三方”内容)。如果IFRAME内的页面没有隐私政策,则其cookie将被阻止(状态栏中的眼睛图标表示,当您单击它时,它将显示被阻止的url列表)。

(来源:piskvor.org)

在这种情况下,当cookie被阻塞时,会话标识符不会发送,目标脚本抛出'session not found'错误。

(我已经尝试将会话标识符设置到表单中,并从POST变量加载它。这本来是可行的,但出于政治原因,我不能这么做。)

可以使IFRAME内的页面更加可信:如果内页发送带有IE可接受的隐私策略的P3P报头,则cookie将被接受。

如何解决

创建p3p策略

W3C教程是一个很好的起点。我已经浏览了它,下载了IBM隐私策略编辑器,并在那里创建了隐私策略的表示,并为它指定了一个名称以供引用(这里是policy1)。

注意:在这一点上,你实际上需要找出你的网站是否有隐私政策,如果没有,就创建它——它是否收集用户数据,什么样的数据,它用它做什么,谁可以访问它,等等。你需要找到这些信息并思考。仅仅把几个标签拼凑在一起是不够的。这一步不能纯粹在软件中完成,而且可能是高度政治化的(例如。“我们是否应该出售我们的点击统计数据?”)。

(如。“本网站由ACME有限公司运营,使用匿名的会话标识符进行操作,仅在明确允许的情况下收集用户数据,仅用于以下目的,仅在必要时存储数据,只有我们公司才能访问它,等等”)。

(使用此工具编辑时,可以查看策略中的错误/遗漏。同样非常有用的标签是“HTML策略”:在底部,它有一个“策略评估”-一个快速检查策略是否会被IE的默认设置阻止)

编辑器导出到.p3p文件,该文件是上述策略的XML表示形式。此外,它还可以导出该策略的“紧凑版本”。

链接到策略

然后需要一个政策参考文件(http://example.com/w3c/p3p.xml)(网站使用的隐私政策索引):

<META>
  <POLICY-REFERENCES>
    <POLICY-REF about="/w3c/example-com.p3p#policy1">
      <INCLUDE>/</INCLUDE>
      <COOKIE-INCLUDE/>
    </POLICY-REF>
  </POLICY-REFERENCES>
</META>

<INCLUDE>显示将使用此策略的所有uri(在我的示例中是整个站点)。我从Editor导出的策略文件上传到http://example.com/w3c/example-com.p3p

发送带有响应的压缩头

我已经在example.com设置了web服务器来发送带有响应的压缩头,就像这样:

HTTP/1.1 200 OK 
P3P: policyref="/w3c/p3p.xml", CP="IDC DSP COR IVAi IVDi OUR TST"
// ... other headers and content

policyref是策略引用文件的相对URI(该文件又引用隐私策略),CP是紧凑的策略表示。请注意,示例中的P3P头的组合可能不适用于您的特定网站;您的P3P头必须如实代表您自己的隐私政策!

利润!

在此配置中,Evil Eye不会出现,cookie甚至保存在IFRAME中,应用程序可以正常工作。

编辑:不要做什么,除非你喜欢从诉讼中辩护

一些人建议“在你的P3P头中加入一些标签,直到邪恶之眼放弃”。

标签不仅仅是一堆比特,它们具有现实世界的含义,它们的使用赋予您现实世界的责任!

例如,假装您从未收集用户数据可能会让浏览器高兴,但如果您实际收集用户数据,P3P就与现实相冲突。简单地说,你是在故意欺骗你的用户,这在某些国家可能是犯罪行为。就像"进监狱,拿不到200美元"

以下是一些示例(完整的标签集请参阅p3pwriter):

NOI : "Web Site does not collected identified data." (as soon as there's any customization, a login, or any data collection (***** Analytics, anyone?), you must acknowledge it in your P3P) STP: Information is retained to meet the stated purpose. This requires information to be discarded at the earliest time possible. Sites MUST have a retention policy that establishes a destruction time table. The retention policy MUST be included in or linked from the site's human-readable privacy policy." (so if you send STP but don't have a retention policy, you may be committing fraud. How cool is that? Not at all.)

我不是律师,但我不愿意去法庭上看看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验证器进行测试

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

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

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

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

这终于为我工作了(经过大量的忙乱和使用ibm策略生成器生成了一些策略)。您可以在这里下载策略生成器:http://www.softpedia.com/get/Security/Security-Related/P3P-Policy-Editor.shtml

我再也不能从IBM官方网站下载生成器了。

我在我的Web-App的根文件夹中创建了这些文件

/index.php
/w3c/policy.html (Human readable format)
/w3c/p3p.xml
/w3c/policy.p3p

Index.php:只发送一个额外的头文件:

header('P3P: policyref="/w3c/p3p.xml", CP="ALL DSP NID CURa ADMa DEVa HISa OTPa OUR NOR NAV DEM"');

p3p.xml的内容

<META>
    <POLICY-REFERENCES>
        <POLICY-REF about="/w3c/policy.p3p#App">
            <INCLUDE>/</INCLUDE>
            <COOKIE-INCLUDE/>
        </POLICY-REF>
    </POLICY-REFERENCES>
</META>

policy.html文件的内容

<html> <head> <STYLE type="text/css"> title { color: #3333FF} </STYLE> <title>Privacy Statement for YOUR COMPANY NAME</title> </head> <body> <h1 class="title">Privacy Policy</h1> <!-- "About Us" section of privacy policy --> <h2>About Us</h2> <p>This is a privacy policy for YOUR COMPANY NAME. Our homepage on the Web is located at <a href="YOURWEBSITE"> YOURWEBSITE</a>. The full text of our privacy policy is available on the Web at <a href="ABSOLUTE URL OF THIS FILE"> ABSOLUTE URL OF THIS FILE</a> This policy does not tell users where they can go to exercise their opt-in or opt-out options. <p>We invite you to contact us if you have questions about this policy. You may contact us by mail at the following address: <pre>FIRSTNAME LASTNAME YOUR ADDRESS HERE </pre> <p>You may contact us by e-mail at <a href="mailto:info@YOURMAIL.de"> info@YOURMAIL.eu</a>. You may call us at TELEPHONENUMBER. <!-- "Privacy Seals" section of privacy policy --> <h2>Dispute Resolution and Privacy Seals</h2> <p>We have the following privacy seals and/or dispute resolution mechanisms. If you think we have not followed our privacy policy in some way, they can help you resolve your concern. <ul> <li> <b>Dispute</b>: Contact us for further information </ul> <!-- "Additional information" section of privacy policy --> <h2>Additional Information</h2> <p> This policy is valid for 1 day from the time that it is loaded by a client. </p> <!-- "Data Collection" section of privacy policy --> <h2>Data Collection</h2> <p>P3P policies declare the data they collect in groups (also referred to as "statements"). This policy contains 1 data group. <hr width="50%" align="center"> <h3>Group "App control data"</h3> <p>We collect the following information: <ul> <li>HTTP cookies</li> </ul> <p>This data will be used for the following purposes:</p> <ul> <li>Completion and support of the current activity.</li> <li>Web site and system administration.</li> <li>Research and development.</li> <li>Historical preservation.</li> <li>Other purposes<p>Control Flow of the application</p></li> </ul> <p>This data will be used by ourselves and our agents. <p>The data in this group has been marked as non-identifiable. This means that there is no reasonable way for the site to identify the individual person this data was collected from. <p>The following explanation is provided for why this data is collected:</p> <blockquote>This cookie data is only used to control the application within an iframe (e.g. a Facebook App)</blockquote> <!-- "Use of Cookies" section of privacy policy --> <hr width="50%" align="center"> <h2>Cookies</h2> <p>Cookies are a technology which can be used to provide you with tailored information from a Web site. A cookie is an element of data that a Web site can send to your browser, which may then store it on your system. You can set your browser to notify you when you receive a cookie, giving you the chance to decide whether to accept it. <p>Our site makes use of cookies. Cookies are used for the following purposes: <ul> <li>Site administration <li>Completing the user's current activity <li>Research and development <li>Other (Control Flow of the application) </ul> <!-- "Compact Policy Explanation" section of privacy policy --> <hr width="50%" align="center"> <h2>Compact Policy Summary</h2> <p>The compact policy which corresponds to this policy is: <pre> CP="ALL DSP NID CURa ADMa DEVa HISa OTPa OUR NOR NAV" </pre> <p>The following table explains the meaning of each field in the compact policy. <center><table width="80%" border="1" cols="2"> <tr><td align="center" valign="top" width="20%"><b>Field</b></td><td align="center" valign="top" width="80%"><b>Meaning</b></td></tr> <tr><td align="left" valign="top" width="20%"><tt>CP=</tt></td> <td align="left" valign="top" width="80%">This is the compact policy header; it indicates that what follows is a P3P compact policy.</td></tr> <tr><td align="left" valign="top" width="20%"><tt>ALL</tt></td> <td align="left" valign="top" width="80%"> Access to all collected information is available. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>DSP</tt></td> <td align="left" valign="top" width="80%"> The policy contains at least one dispute-resolution mechanism. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>NID</tt></td> <td align="left" valign="top" width="80%"> The information collected is not personally identifiable. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>CURa</tt></td> <td align="left" valign="top" width="80%"> The data is used for completion of the current activity. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>ADMa</tt></td> <td align="left" valign="top" width="80%"> The data is used for site administration. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>DEVa</tt></td> <td align="left" valign="top" width="80%"> The data is used for research and development. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>HISa</tt></td> <td align="left" valign="top" width="80%"> The data is used for historical archival purposes. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>OTPa</tt></td> <td align="left" valign="top" width="80%"> The data is used for other purposes. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>OUR</tt></td> <td align="left" valign="top" width="80%"> The data is given to ourselves and our agents. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>NOR</tt></td> <td align="left" valign="top" width="80%"> The data is not kept beyond the current transaction. </td></tr> <tr><td align="left" valign="top" width="20%"><tt>NAV</tt></td> <td align="left" valign="top" width="80%"> Navigation and clickstream data is collected. </td></tr> </table></center> <p>The compact policy is sent by the Web server along with the cookies it describes. For more information, see the P3P deployment guide at <a href="http://www.w3.org/TR/p3pdeployment">http://www.w3.org/TR/p3pdeployment</a>. <!-- "Policy Evaluation" section of privacy policy --> <hr width="50%" align="center"> <h2>Policy Evaluation</h2> <p>Microsoft Internet Explorer 6 will evaluate this policy's compact policy whenever it is used with a cookie. The actions IE will take depend on what privacy level the user has selected in their browser (Low, Medium, Medium High, or High; the default is Medium. In addition, IE will examine whether the cookie's policy is considered satisfactory or unsatisfactory, whether the cookie is a session cookie or a persistent cookie, and whether the cookie is used in a first-party or third-party context. This section will attempt to evaluate this policy's compact policy against Microsoft's stated behavior for IE6. <p><b>Note:</b> this evaluation is currently experimental and should not be considered a substitute for testing with a real Web browser. <p><b>Satisfactory policy</b>: this compact policy is considered <em>satisfactory</em> according to the rules defined by Internet Explorer 6. IE6 will accept cookies accompanied by this policy under the High, Medium High, Medium, Low, and Accept All Cookies settings. </body></html>

policy.p3p的内容

<?xml version="1.0"?>
<POLICIES xmlns="http://www.w3.org/2002/01/P3Pv1">
    <!-- Generated by IBM P3P Policy Editor version Beta 1.12 built 2/27/04 1:19 PM -->

    <!-- Expiry information for this policy -->
    <EXPIRY max-age="86400"/>

<POLICY
    name="App"
    discuri="ABSOLUTE URL TO policy.html"
    xml:lang="de">
    <!-- Description of the entity making this policy statement. -->
    <ENTITY>
    <DATA-GROUP>
<DATA ref="#business.name">COMPANY NAME</DATA>
<DATA ref="#business.contact-info.online.email">info@YOURMAIL.eu</DATA>
<DATA ref="#business.contact-info.online.uri">YOURWEBSITE</DATA>
<DATA ref="#business.contact-info.telecom.telephone.number">YOURPHONENUMBER</DATA>
<DATA ref="#business.contact-info.postal.organization">FIRSTNAME LASTNAME</DATA>
<DATA ref="#business.contact-info.postal.street">STREET</DATA>
<DATA ref="#business.contact-info.postal.city">CITY</DATA>
<DATA ref="#business.contact-info.postal.stateprov">STAGE</DATA>
<DATA ref="#business.contact-info.postal.postalcode">POSTALCODE</DATA>
<DATA ref="#business.contact-info.postal.country">Germany</DATA>
    </DATA-GROUP>
    </ENTITY>

    <!-- Disclosure -->
    <ACCESS><all/></ACCESS>


    <!-- Disputes -->
    <DISPUTES-GROUP>
        <DISPUTES resolution-type="service" service="YOURWEBSITE CONTACT FORM" short-description="Dispute">
            <LONG-DESCRIPTION>Contact us for further information</LONG-DESCRIPTION>
    <!-- No remedies specified -->
        </DISPUTES>
    </DISPUTES-GROUP>

    <!-- Statement for group "App control data" -->
    <STATEMENT>
        <EXTENSION optional="yes">
            <GROUP-INFO xmlns="http://www.software.ibm.com/P3P/editor/extension-1.0.html" name="App control data"/>
        </EXTENSION>

    <!-- Consequence -->
    <CONSEQUENCE>
This cookie data is only used to control the application within an iframe (e.g. a Facebook App)</CONSEQUENCE>

    <!-- Data in this statement is marked as being non-identifiable -->
    <NON-IDENTIFIABLE/>

    <!-- Use (purpose) -->
    <PURPOSE><admin/><current/><develop/><historical/><other-purpose>Control Flow of the application</other-purpose></PURPOSE>

    <!-- Recipients -->
    <RECIPIENT><ours/></RECIPIENT>

    <!-- Retention -->
    <RETENTION><no-retention/></RETENTION>

    <!-- Base dataschema elements. -->
    <DATA-GROUP>
    <DATA ref="#dynamic.cookies"><CATEGORIES><navigation/></CATEGORIES></DATA>
    </DATA-GROUP>
</STATEMENT>

<!-- End of policy -->
</POLICY>
</POLICIES>

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

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

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

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

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

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

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