AntiForgery token validation failed using 2FA flow #377
Replies: 2 comments
-
It should be possible to have antiforgery tokens enabled on both post actions. The antiforgery tokens an ASP.NET Core are bound to the current user. If you have indeed logged out and then visit the login page again, the anti forgery token generated for that login page should be bound to the now anonymous session. When testing this, are you running everything in the same browser tab, or do you do them in parallel in different tabs? The reason I'm asking is because if the login form is rendered before the logout is completed, the token will be bound to the session that is about to be logged out. Could you also please share some more information on how the 2FA login is implemented? Is this the ASP.NET Identity model with a separate cookie scheme for supporting 2FA? |
Beta Was this translation helpful? Give feedback.
-
Yes, I am running in the same browser tab. Login -> Logout -> Login back again. I also have a FE app (Angular) and a BFF service sitting inside a k8s cluster. Duende services (STS, Admin and Admin api) run inside App Services.
In the BFF service I have this setup for OIDC flow:
and also:
Yes, we have a partial cookie issues after login with username/password until the 2FA flow is completed. Only then the full cookie gets generated. Below is the code from the POST /Account/Login endpoint.
Here I have the code for POST /Account/Login2FA endpoint:
Currently the issue with anti forgery is gone, but if I want to logout from user A and login to user B (in the same tab) then I get redirected to the login page no matter what. I guess somehow the middleware calls the /bff/logout endpoint but behind the scenes the cookies are not cleared automatically. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using Duende IdentityServer v7.0.5 in a web app (Angular) that uses BFF and STS services. After I perform a login using the 2FA flow then a logout and another login right after, I get the error below after I type the username/password (before the 2FA step):
After many attempts to fix this, I noticed that if I disable the [ValidateAntiForgeryToken] from the POST Login endpoint the error no longer appears. Insted, I kept the same [ValidateAntiForgeryToken] attribute on the 2FA endpoint.
I suspect this is the expected behavior since the full Identity cookie is not issued until the 2FA step is finished. Before we had 2FA enabled, the full Identity cookie was issued right after the POST Login endpoint and this was the place where the antiforgery cookie was generated as well.
Currently the login endpoints look like this:
and
and
Is there another approach to this scenario or is this solution sufficient?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions