Search code examples
cookiesiframesafarisession-cookiessamesite

Send Ajax request with cookie from 3rd Party Iframe - Safari 14+


I have a server side application that uses cookies for session management. The browser has some script that sends an ajax request to add information to the session. This is working well and in production.

The business wants to be able to insert this application in other companies' websites via iframes. ie myapp.com is in an iframe in otherbusiness.com and when the user clicks a button in the application in the iframe launched from myapp.com, it sends a request with a cookie that contains the session id to update the user's session on the myapp.com server.

For the browser to be able to send a cookie, 3rd party cookies needs to be enabled by setting the cookie options of SameSite=None and Secure. This works for all browsers except Safari.

Safari no longer accepts 3rd party cookies.

The only solution I can come up with is to use session ids in the URL but this is a little cumbersome.

Can anyone suggest a better option or perhaps a good implementation of session ids in the url?


Solution

  • I used hidden html fields to pass the session id and expiration.

    My server side code checks for a cookie if it cannot find it, looks for the session id and expiration in the hidden fields.

    This avoids security issues with passing the id in the url. It is a little clumsy to implement but it works.