white-article-28775
08/03/2022, 4:34 PMedgeConfig
, as in the NextJS example) I'm using .adminExtendSession(sessionId)
and the service always returns 403 Forbidden:
{
"id": "security_csrf_violation",
"code": 403,
"status": "Forbidden",
"request": "bac7d4f7-084b-449d-bdcd-9f3065a13838",
"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"
}
I have asked this before here and was told that the route isn't even protected so that error makes no sense.
I cleared my cookies, tried from incognito, tried from a different domain, had many other people try, doesn't matter. It just won't work.
We've checked cors, enabled all methods, we use the adminDeleteIdentity
route regularly and that one works, but extend does not.
The docs feature an example curl command - using curl returns the same exact error.
I am at the end of my rope with this and would like some help. 😞
@high-optician-2097fast-lunch-54279
proud-plumber-24205
08/03/2022, 8:07 PMPATCH
request and not a GET
or POST
when testing with cURL
? Some of the commands on the documentation might be incomplete, do you have an exact reference from where you copied the command?
Also CSRF errors are browser based errors, do they also happen on curl, or do you get a different error there?white-article-28775
08/04/2022, 6:53 AMadminDeleteIdentity
and it works as expected.
cURL was definitely right, but also sent the request to public. One devops guy actually tried sending a cURL directly to the admin service and that one worked! But it's not something we can do using the SDK since all requests go to the same place.
The error form cURL is the same exact CSRF error.proud-plumber-24205
08/04/2022, 7:44 AMproud-plumber-24205
08/04/2022, 7:49 AMwhite-article-28775
08/04/2022, 7:50 AMproud-plumber-24205
08/04/2022, 7:57 AMwhite-article-28775
08/04/2022, 8:04 AMproud-plumber-24205
08/04/2022, 8:21 AMproud-plumber-24205
08/04/2022, 8:22 AMwhite-article-28775
08/04/2022, 8:23 AMwhite-article-28775
08/04/2022, 8:26 AMV0alpha2Api
or two instances of the apiHandler or both?proud-plumber-24205
08/04/2022, 8:51 AMV0alpha2Api
https://github.com/ory/kratos-selfservice-ui-react-nextjs/blob/master/pkg/sdk/index.tswhite-article-28775
08/04/2022, 8:56 AM/api/.ory/
for the api handler, and it's the api handler that reads the url from envproud-plumber-24205
08/04/2022, 8:57 AM/api/.ory
handler and then configure the V0alpha2Api
yourself to point it to your Kratos URLwhite-article-28775
08/04/2022, 9:06 AMexport const ory = new V0alpha2Api(new Configuration({
basePath: '<https://ory-url>',
baseOptions: {
withCredentials: true
}
}));
?white-article-28775
08/04/2022, 10:08 AMV0alpha2Api
just ends up failing every request... am I missing something?white-article-28775
08/04/2022, 10:51 AMedgeConfig
clears this issue...white-article-28775
08/04/2022, 11:14 AMV0alpha2Api
, and also a second copy of the apiHandler (it genuinely didn't work otherwise). This second copy has apiBaseUrlOverride
set to the admin service url, and the client instance has basePath
set to /api/.ory-admin
.
I'm sure this is not what you intended at all, but this is the best I could come up with.
Session extension works now with this setup.bland-eye-99092
08/04/2022, 11:30 AMwhite-article-28775
08/04/2022, 11:31 AMbland-eye-99092
08/04/2022, 1:32 PMadminDeleteIdentity
path is not ignored by the CSRF handler when redirecting from the public API. The related lines are here: https://github.com/ory/kratos/blob/master/session/handler.go#L79-L81
There, the path /sessions/*/extend
needs to be added. Feel free to open a PR.