When a user clicks a button on my site, a new window is opened to a third party site where the user browses items. After clicking an item, the new window is redirected back to my site with data about the item.
At this point (after the final redirect back to my site, not before), my site's session cookie (along with other cookies, my csrf token cookie is affected as well) is erased/lost/refreshed or whatever. If I reload the page on the "main" window (or even the new window), the old session is gone and the user is redirected back to my login page.
Example of the response header set-cookie on my site:
mysite_session=XXXXXXXXXXXXX; path=/; domain=.mysite.test; httponly; samesite=lax
I am using Laravel framework for PHP, although this should not be a factor as I had this same exact problem using pure PHP before I started converting my app to Laravel.
Code about each step:
- User clicks a button on my site.
$(document).on("click", "#btn-open", function()
{
const url = "https://mysite.test/browse";
window.open(url, "_blank", "scrollbars=yes,resizable=yes");
});
1.5. A new window is opened. This will go through my site to get a single-use url to the third party site using their API.
https://mysite.test/browse is technically just:
<?php
$api = new ThirdPartyApi(/* data and stuff */);
$url = $api->getBrowseUrl();
?>
<html>
<body>
<h1>Wait - Redirecting...</h1>
<script>window.location.href = "<?php $url;?>";</script>
</body>
</html>
User is redirected to the third party site (different domain).
After clicking an item, the user is redirected back to my site (https://mysite.test/return) with POST-data about the item.
https://mysite.test/return is technically just:
<?php
$itemData = json_encode($_POST["item"]);
?>
<html>
<body>
<script>
const itemData = <?php $itemData;?>;
// Do stuff with item data, example commented as it's unrelated
//window.opener.thirdPartyCallbackFunc(itemData);
//window.close();
</script>
</body>
</html>
I just cannot understand how is it possible that a third party site can somehow cause my own site's cookie to get modified.
Is it possible that the third party site is doing something strange with cookies or have I done something wrong? Anyone got any ideas?