title: Safari 13+ iframe blocks CORS cookies
body: <p>Safari flat out doesn't let you set cookies in iframes of domains different than the parent domain, server-side CORS headers be damned.</p>
  <blockquote>
  <p>To clarify: user is on domainA.com. An iframe for domainB.com is open,
  and attempts to authenticate the user on domainB.com inside the
  iframe. Set-Cookie header is returned from the server inside the domainB.com iframe, with all the required headers, but Safari isn't sending it back in subsequent calls.</p>
  </blockquote>
  <p>An old workaround was doing a form submit from the iframe, and set the cookie in the response. I guess they liked the fact that the user was clicking something to submit the form. You'd have to poll for the cookie to see when the response came back, as form submits have no callbacks, and in the case of HttpOnly cookies you couldn't, but hey, it worked! Until it didn't.</p>
  <p>Then, a more recent workaround was redirecting the user to the iframe domain in a brand new window/tab, setting a random cookie there, and from that moment on, that subdomain was &quot;trusted&quot; inside the iframe. Again, it required a click to open the new window/tab, and there was even a visual indication of the new tab opening. Much security, such standards.</p>
  <p><strong>And now, as of Safari 13 - No more workaround. No more secure iframe cookie setting</strong> </p>
  <p>Any other authentication scheme isn't good for us (e.g. Auth-X header). We need to use an HttpOnly secure cookie, as we don't want that token to be in any way accessible by javascript client-side.</p>
  <p>To be clear, everything works great on any other browser.</p>
  <p><a href="https://bugs.webkit.org/show_bug.cgi?id=200857" rel="noreferrer">Relevant WebKit Bugzilla</a></p>
  <p>Does anyone have any suggestions?</p>
  <p><strong>Edit:</strong></p>
  <p>Thanks for the link @tomschmidt, that seems like the right direction.
  I tried using Apple's Storage Access API, but unfortunately, although I'm making sure to request access before initializing my login logic with the API:</p>
  <pre class="lang-js prettyprint-override"><code>requestStorageAccess = async() =&gt; {
      return new Promise(resolve =&gt; {
        //@ts-ignore
        document.requestStorageAccess().then(
          function () {
            console.log('Storage access was granted');
            resolve(true);
          },
          function () {
            console.log('Storage access was denied');
            resolve(false);
          }
        );    
      });
    }
  
  
  const storageAccessGranted = await requestStorageAccess();
  console.log(storageAccessGranted) // prints 'true'
  await login();
  </code></pre>
  <p>Still, the cookies received on the /login API response are not getting sent in subsequent calls to the API :(</p>
  <p><strong>Edit 2 (May 2021):</strong></p>
  <p>Safari 14 has added <strong>another</strong> breaking change:</p>
  <p><a href="https://webkit.org/blog/11545/updates-to-the-storage-access-api/" rel="noreferrer">https://webkit.org/blog/11545/updates-to-the-storage-access-api/</a></p>
  <p>Go Apple go! You're making us reminisce about IE6.</p>