How to set a cookie for iframe on the same domain

2019-06-18 20:18发布

问题:

I'm trying to make integration of etherpad-lite in the CMS Plone, following Example 1 of the official documentation http://etherpad.org/doc/v1.2.7/

Portal places the cookie "sessionID" with the given value on the client and creates an iframe including the pad.

Everythings goes well except for the cookie. Reading documentation the best pratice seems to make etherpad-lite in the same domain under a specific path. This is what I have done using /pad/ path.

Plone side if no session has been created, I created on, I add a cookie and then I'm doing a redirect to the same page to be sure the cookie is in the browser.

As a results my cookie is added to the request of the main page but not ob the iframe request.

Here is the google chrome console network tab for the main page and the iframe:

http://toutpt.makina-corpus.org/en/images/cookie-in-iframe/

The code corresponding to the setCookie is at https://github.com/toutpt/collective.etherpad/blob/master/collective/etherpad/archetypes.py#L100

回答1:

For posterity, here's the answer from @AskoSoukka identified and "accepted" in the comments above:

How does the actual cookie stored in you browser look like? Probably, you need to explicitly specify path="/" in setCookie kwargs to make it work for the whole domain.