Heya guys! Im trying to implement the recovery bro...
# talk-kratos
g
Heya guys! Im trying to implement the recovery browser flow in self-hosted kratos and I keep running into csrf errors and Im at my wits end here. The docs say I have to attach the csrf cookie and to include the csrf_token value before doing a post request to "http://127.0.0.1:4433/self-service/recovery?flow=x&token=y" I have double, triple checked the csrf values before sending the request and i just keep getting errors. Im using axios to do the post request if that makes any difference. these are real values I used for testing. and the logs the config:
Copy code
method: 'post',
  maxBodyLength: Infinity,
  url: '<http://127.0.0.1:4433/self-service/recovery?flow=249ff35c-ba79-4603-b9cc-24a03aa26a96&token=078560>',
  headers: {
    accept: 'application/json',
    'Content-Type': 'application/json',
    Cookie: 'csrf_token_806060ca5bf70dff3caa0e5c860002aade9d470a5a4dce73bcfa7ba10778f481=CkFsLXg7UVAskKdL8FLMdg/z/SXhl2n5xcBwchR9/Vw=; Path=/; Max-Age=31536000; HttpOnly; Secure; SameSite=Lax'
  },
  data: '{"code":"078560","csrf_token":"iMp6iqxXeaOW1t6+DQXZA4cC4x2LE3MDV5cdpyMCv8fAYQIO61CceuhI1dJbpYd0F/XgAkB2aKPRuXe/zWW5sg==","method":"code"}'
}
the logs:
Copy code
time=2023-02-12T22:27:55+05:30 level=debug msg=A recovery flow is being retried because a validation error occurred. audience=application error=map[debug: details:map[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 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. stack_trace:
<http://github.com/ory/kratos/selfservice/flow.EnsureCSRF|github.com/ory/kratos/selfservice/flow.EnsureCSRF>....

..../project/x/httploadermiddleware.go:23 status:Forbidden status_code:403] http_request=map[headers:map[accept:application/json accept-encoding:gzip, compress, deflate, br connection:close content-length:137 content-type:application/json cookie:[csrf_token_806060ca5bf70dff3caa0e5c860002aade9d470a5a4dce73bcfa7ba10778f481=CkFsLXg7UVAskKdL8FLMdg/z/SXhl2n5xcBwchR9/Vw=; Path=/; Max-Age=31536000; HttpOnly; Secure; SameSite=Lax] user-agent:axios/1.2.2] host:127.0.0.1:4433 method:POST path:/self-service/recovery query:flow=249ff35c-ba79-4603-b9cc-24a03aa26a96&token=078560 remote:127.0.0.1:65291 scheme:http] service_name=Ory Kratos service_version=v0.11.0
time=2023-02-12T22:27:55+05:30 level=info msg=Encountered self-service recovery error. audience=audit error=map[debug: details:map[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 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. stack_trace:
<http://github.com/ory/kratos/selfservice/flow.EnsureCSRF|github.com/ory/kratos/selfservice/flow.EnsureCSRF>
        /project/selfservice/flow/request.go:70.....