bored-vegetable-68997
08/16/2022, 8:29 AMui
with nuxt
. Most of the time I use the SDK to communicate with Kratos
and it works fine, but to submit flows I simply use fetch()
. No I'm facing the problem, that Kratos
responds with a 403
, saying that the csrf_token
is missing. I already went through the (pitfalls)[https://www.ory.sh/docs/kratos/debug/csrf#running-on-separate-sub-domains] and for me the the request headers are all set (cookie) and the request body looks fine too. Does anyone know what I'm missing? And how can I check if the csrf-token in the cookie matches the one in the form, as they look different?
I am running Kratos
and the ui
as docker containers.
Request:
POST /?flow=d16e0089-a607-4070-b12e-90a81f07ef2b HTTP/1.1
Host: 127.0.0.1:4433
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: <http://127.0.0.1:3000/>
content-type: application/json
Content-Length: 216
Origin: <http://127.0.0.1:3000>
DNT: 1
Connection: keep-alive
Cookie: csrf_token_806060ca5bf70dff3caa0e5c860002aade9d470a5a4dce73bcfa7ba10778f481=g0nlXiujTgN6cDGdx4pqJN6oiW5SHKxutbstbG8apKw=
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
Body:
{
"csrf_token": "AoL6XD3nMeIy8o4VtGHoamjpgAPX2DbIL3/0KvZk1xiByx8CFkR/4UiCv4hz64JOtkEJbYXEmqaaxNlGmX5ztA==",
"method": "password",
"password": "adw1221aS",
"traits": {
"email": "<mailto:ad@lo.de|ad@lo.de>",
"name": {
"first": "hhfr",
"last": "hrww"
}
}
}
Thank you!bland-eye-99092
08/16/2022, 8:32 AMbored-vegetable-68997
08/16/2022, 8:34 AM{
"error": {
"id": "security_csrf_violation",
"code": 403,
"status": "Forbidden",
"reason": "Please retry the flow and optionally clear your cookies. The request was rejected to protect you from Cross-Site-Request-Forgery (CSRF) which could cause account takeover, leaking personal information, and other serious security issues.",
"details": {
"docs": "<https://www.ory.sh/kratos/docs/debug/csrf>",
"hint": "The anti-CSRF cookie was found but the CSRF token was not included in the HTTP request body (csrf_token) nor in the HTTP Header (X-CSRF-Token).",
"reject_reason": "The HTTP Cookie Header was set and a CSRF token was sent but they do not match. We recommend deleting all cookies for this domain and retrying the flow."
},
"message": "the request was rejected to protect you from Cross-Site-Request-Forgery"
}
}
better-garden-63533
08/16/2022, 8:34 AMbland-eye-99092
08/16/2022, 8:35 AMbland-eye-99092
08/16/2022, 8:37 AMbored-vegetable-68997
08/16/2022, 8:42 AMbland-eye-99092
08/16/2022, 8:43 AMbland-eye-99092
08/16/2022, 8:44 AMbored-vegetable-68997
08/16/2022, 8:46 AMbored-vegetable-68997
08/16/2022, 8:48 AMbland-eye-99092
08/16/2022, 8:53 AMbored-vegetable-68997
08/16/2022, 9:22 AMPOST /self-service/registration?flow=57f6e2e1-b85f-465f-b6a1-ddae97b2a9a0 HTTP/1.1
Host: 127.0.0.1:4433
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
Content-Length: 225
Origin: <http://127.0.0.1:3000>
DNT: 1
Connection: keep-alive
Referer: <http://127.0.0.1:3000/>
Cookie: csrf_token_806060ca5bf70dff3caa0e5c860002aade9d470a5a4dce73bcfa7ba10778f481=CnZCaDRekkEhK4PrZH/R0ashn3uhiiVbeNM2+U/UCdg=
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
{
"csrf_token": "WH/Fwpe6kDys6HlKr+EhWE9Ziv6lKsvI+kFgRFkiJUhSCYeqo+QCfY3D+qHLnvCJ5HgVhQSg7pOCkla9FvYskA==",
"method": "password",
"password": "asdeqw121QA",
"traits": {
"email": "peter@pan.mail",
"name": {
"first": "ASDw",
"last": "kjkji"
}
}
}
However the response is status 200
.proud-plumber-24205
08/16/2022, 9:53 AMproud-plumber-24205
08/16/2022, 9:56 AMproud-plumber-24205
08/16/2022, 9:57 AMfetch(url, {
credentials: 'include'
})
bored-vegetable-68997
08/16/2022, 10:03 AM/self-service/registration
of course. And I was just calling /
. 😄
Thank you all for your help!