gentle-bird-90474
05/18/2022, 8:22 AMauth.mydomain.tld
and we have numerous feature environments, e.g. prod.mydomain.tld
, staging.mydomain.tld
and feature123.mydomain.tld
. Logins from all of the feature environments fail with a security_csrf_violation
and the message "the request was rejected to protect you from Cross-Site-Request-Forgery"
. Local setup with Ory proxy works fine.
I believe this to maybe be the root cause:
• when the browser sends a request to <https://auth.mydomain.tld/self-service/login/browser>
, the server responds with a csrf_token_<someid>
cookie. the cookies domain uses mydomain.tld
.
• this csrf_token_<someid>
cookie however is never stored on the browser, so obviously also not sent in subsequent requests (I have withCredentials: true
added to axios)
To the best of my knowledge and what I’ve read, Browsers should store the cookie and send it to other subdomains of mydomain.tld
as well but this is not happening. So what am I missing? Can somebody help?steep-lamp-91158
mydomain.tld
? Can you check that in the browser console and Kratos config?gentle-bird-90474
05/18/2022, 10:35 AMgentle-bird-90474
05/18/2022, 1:44 PMgentle-bird-90474
05/18/2022, 1:45 PMsteep-lamp-91158
steep-lamp-91158
gentle-bird-90474
05/18/2022, 1:49 PMgentle-bird-90474
05/19/2022, 12:10 PMwithCredentials: true
set on the Axios config. According to https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch, this is required for cookies to be set cross-origin:
• Unlessis called with thefetch()
option set tocredentials
, `fetch()`:include
◦ won’t send cookies in cross-origin requests
◦ won’t set any cookies sent back in cross-origin responses(
withCredentials
on Axios controls credentials
on fetch API)gentle-bird-90474
05/19/2022, 12:31 PMwithCredentials: true
needs to be set also for the initial GET requests that initializes the login flow, not only for the subsequent POST in which login credentials are submitted. If not included in the initial GET the Browser does not have (and subsequently does not send) the CSRF tokens required for the POST to succeed.steep-lamp-91158
gentle-bird-90474
05/19/2022, 1:24 PM