3

I am using two Google Cloud Run containers to host different applications. I changed the URLs in the question for privacy reasons (the structure stays the same obviously).

  1. A Laravel Backend which uses Sanctum. This runs on ice-bear-backend-abcde-ey.a.run.app
  2. A VueJS Frontend which runs on ice-bear-frontend-abcde-ey.a.run.app

I use the following configuration in Laravel:

SANCTUM_STATEFUL_DOMAINS=ice-bear-frontend-abcde-ey.a.run.app
SESSION_DOMAIN=.run.app

The backend therefore returns the following cookies: enter image description here However, these cookies are not set by the browser as it rejects the cookies with an error that the domain is not correct. The Error in Firefox "Cookie “XSRF-TOKEN” has been rejected for invalid domain." And the same error in Chrome "This attempt to set a cookie via a Set-Cookie header was blocked because its Domain attribute was invalid with regards to the current host URL."

I tested a lot of different configurations for many hours regarding the SameSite (none, lax) and Secure (true ,false). And obviously, there are also different domains for the cookies (.a.run.app or even ice-bear-frontend-abcde-ey.a.run.app). But I can't get this to work. Unfortunately, I don't have a deep understanding of the configuration of Cookies, and all other questions and solutions here that I tested are about having both on the same domain or only the backend on a subdomain. But those solutions I couldn't get to work.

So I hope somebody with more experience than me has an idea of what is still misconfigured.

1
  • Sorry for the typo. They are being rejected Commented Jun 3, 2024 at 8:33

1 Answer 1

2

So it turns out there is a list of public suffixes maintained by Mozilla and used in most modern browsers: https://publicsuffix.org/ If a domain is on the list those browsers will reject the cookies set on a high-level domain name suffix.

This is also the case for the .run.app Domain from Google Cloud Run. Therefore adding a custom domain and using it solves the problem. This however means that I can not access different revisions directly by domain. So I might change my setup to deploy for pull-request previews the FE and BE together into one single Cloud Run container

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.