Cookie blocked/not saved in IFRAME in Internet Explorer

前端 未结 22 2117
死守一世寂寞
死守一世寂寞 2020-11-22 00:53

I have two websites, let\'s say they\'re example.com and anotherexample.net. On anotherexample.net/page.html, I have an IFRAME S

相关标签:
22条回答
  • 2020-11-22 01:01

    A better solution would be to make an Ajax call inside the iframe to the page that would get/set cookies...

    0 讨论(0)
  • 2020-11-22 01:02

    This is a great topic on the issue, however I found that one important detail (which was essential at least in my case) that was not posted here or anywhere else (I apologize if I just missed it) was that the P3P line must be passed in header of EVERY file sent from the 3rd party server, even files not setting or using the cookies such as Javascript files or images. Otherwise the cookies will be blocked. I have more on this in a post here: http://posheika.net/?p=110

    0 讨论(0)
  • 2020-11-22 01:02

    I know it's a bit late to put my contribution on this subject but I lost so many hours that maybe this answer will help somebody.

    I was trying to call a third party cookie on my site and of course it was not working on Internet Explorer 10, even at a low security level... don't ask me why. In the iframe I was calling a read_cookie.php (echo $_COOKIE) with ajax.

    And I don't know why I was incapable of setting the P3P policy to solve the problem...

    During my search I saw something about getting the cookie in JSON working. I don't even try because I thought that if the cookie won't pass through an iframe, it will not pass any more through an array...

    Guess what, it does! So if you json_encode your cookie then decode after your ajax request, you'll get it!

    Maybe there is something I missed and if I did, all my apologies, but i never saw something so stupid. Block third party cookies for security, why not, but let it pass if encoded? Where is the security now?

    I hope this post will help somebody and again, if I missed something and I'm dumb, please educate me!

    0 讨论(0)
  • 2020-11-22 01:06

    Anyone having this problem in node.js.

    Then add this p3p module, and enable this module at middleware.

    npm install p3p
    

    I am using express so I add it in app.js

    First require that module in app.js

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

    then use it as middleware

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

    It will add p3p headers at res object. No need to do any extra things.

    You will get more info at:

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

    0 讨论(0)
  • 2020-11-22 01:08

    I've spend a large part of my day looking into this P3P thing and I feel the need to share what I've found out.

    I've noticed that the P3P concept is very outdated and seems only to be really used/enforced by Internet Explorer (IE).

    The simplest explanation is: IE wants you to define a P3P header if you are using cookies.

    This is a nice idea, and luckily most of the time not providing this header won't cause any issues (read browser warnings). Unless your website/web application is loaded into an other website using an (i)Frame. This is where IE becomes a massive pain in the ***. It will not allow you to set a cookie unless the P3P header is set.

    Knowing this I wanted to find an answer to the following two questions:

    1. Who cares? In other words, can I be sued if I put the word "Potato" in the header?
    2. What do other companies do?

    My findings are:

    1. No one cares. I'm unable to find a single document that suggests this technology has any legal weight. During my research I didn't find a single country around the world that has adopted a law that prevents you from putting the word "Potato" in the P3P header
    2. Both Google and Facebook put a link in their P3P header field referring to a page describing why they don't have a P3P header.

    The concept was born in 2002 and it baffles me that this outdated and legally unimplemented concept is still forced upon developers within IE. If this header doesn't have have any legal ramifications this header should be ignored (or alternatively, generate a warning or notification in the console). Not enforced! I'm now forced to put a line in my code (and send a header to the client) that does absolutely nothing.

    In short - to keep IE happy - add the following line to your PHP code (Other languages should look similar)

    header('P3P: CP="Potato"');
    

    Problem solved, and IE is happy with this potato.

    0 讨论(0)
  • 2020-11-22 01:08

    This is buried in the comments of other answers, but I almost missed it, so it seems like it deserves its own answer.

    To review: in order for IE to accept 3rd party cookies, you need serve your files with an http header called p3p in the format:

    CP="my compact p3p policy"
    

    BUT, p3p is pretty much dead as a standard at this point and you can easily get IE to work without investing the time and legal resources in creating a real p3p policy. This is because if your compact p3p policy header is invalid, IE actually treats it as a good policy and accepts 3rd party cookies. So you can use a p3p header such as this

    CP="This site does not have a p3p policy."
    

    You can optionally include a link to a page that explains why you don't have a p3p policy, as Google and Facebook do (they point here: https://support.google.com/accounts/answer/151657 and here: https://www.facebook.com/help/327993273962160/).

    Finally, it's important to note that all files served from the 3rd party site need to have the p3p header, not just the one that sets the cookie, so you may not be able to just do this in your PHP, asp.net, etc code. You are probably better off setting in up on the web server level (i.e. in IIS or Apache).

    0 讨论(0)
提交回复
热议问题