Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this a bad practice? #214

Open
EmanuelAguilar74 opened this issue Mar 6, 2021 · 2 comments
Open

Is this a bad practice? #214

EmanuelAguilar74 opened this issue Mar 6, 2021 · 2 comments

Comments

@EmanuelAguilar74
Copy link

EmanuelAguilar74 commented Mar 6, 2021

What Is the issue?

I'm doing a workaround for the new privacy policies on Safari and Brave for my injectable chat widget. I need access and set cookies for my chat app, so I decided to go with this.

The child expose this methods to the parent
image

Then, on the parent I create this handlers
image

This way I can get/set cookies on the parent from the child using a promise approach.
Example:
const cookie = await connection.sendMessage({ event: 'get-cookie', payload: { cname: 'cookie-name' } });

await connection.sendMessage({ event: 'set-cookie', payload: { cname: 'cookie-name', cvalue: cookieValue, exdays: expirationTime }})

@kovacs
Copy link

kovacs commented Apr 26, 2021

following

@tmikaeld
Copy link

tmikaeld commented May 31, 2021

This is very much valid, since the PostMessage API is mature and even used by payment processors such as Klarna and Stripe, however, this approach does remove the ability to be able to use secure cookies, so I would be careful when using this for authentication or sessions. If you do use it for that, make sure that you don't have any unprotected inputs or script execution, since any script injected could steal the cookie details.

Considering there's an upcoming fork of this lib, might want to check it out.

And also consider setting a Content-Security-Policy header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants