Open JeroMiya opened 10 months ago
That makes sense, the nonce cookie isn't consumed & deleted until late in the validation process. Maybe that could happen earlier?
If there's an id token: https://github.com/dotnet/aspnetcore/blob/e6be3e95fec33ca3a3b576df4b265ead680a91a0/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L669
If there's a code: https://github.com/dotnet/aspnetcore/blob/e6be3e95fec33ca3a3b576df4b265ead680a91a0/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L752
The logic for deleting the right cookie only cross checks against the received code/token, that would have to be relaxed in the error scenario. https://github.com/dotnet/aspnetcore/blob/e6be3e95fec33ca3a3b576df4b265ead680a91a0/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1062-L1090
Looks like this issue has been identified as a candidate for community contribution. If you're considering sending a PR for this issue, look for the Summary Comment
link in the issue description. That comment has been left by an engineer on our team to help you get started with handling this issue. You can learn more about our Help Wanted process here
@JeroMiya Thanks for posting this question. Just curious, were you able to delete the nonce/correlation cookie from server side? I'm trying to delete these two types of cookie so that they are not building up
@JeroMiya Thanks for posting this question. Just curious, were you able to delete the nonce/correlation cookie from server side? I'm trying to delete these two types of cookie so that they are not building up
It's funny, we actually decided to port the Angular app to Blazor. Since we are using enhanced navigation, we removed the need to implement silent login using an iframe in the frontend, since the redirect happens on the server side before the frontend even loads (or it happens at navigation time if it happens post load). So, I didn't need to go back and implement a workaround. But the problem will still exist for anybody trying to implement the silent login flow with a more traditional frontend spa following the latest OIDC recommendations.
Is there an existing issue for this?
Describe the bug
This issue has a similar symptom as other reported issues, but I believe has a different cause:
For context, we have an application that authenticates with OIDC to an identity server that is on the same domain/site as our application. We're using Duende.Bff and we have a silent login flow implemented, where an iframe is opened up to
/bff/silent-login
./silent-login
issues a challenge (thus setting the nonce and correlation cookies) and redirects to the identity server using theprompt=none
parameter. If the user is already logged into the identity server, then the IS redirects back to/signin-oidc
, which then deletes the nonce and correlation cookies. That's expected behavior. The problem occurs when the user is not already signed into the identity server. In this case, the IS redirects back to/signin-oidc
with the?error=login_required
parameter. When this happens, the/signin-oidc
endpoint does NOT delete the nonce and correlation cookies. And, while Duende.Bff correctly notifies the parent frame via a message that silent login was unsuccessful (so that we can notify the user and prompt for them to login manually), this leaves around extra nonce and correlation cookies until they expire.It does not take long for these extra cookies to build up to the point that we get errors for cookies being too big. Around 4 or 5 navigations to the site without being logged in, within a 15 minute window, will cause the errors to occur. Users clicking on a handful of deep links or accidently double clicking the refresh button a couple of times while not being logged in will trigger the errors, so it's plausible this will occur outside of QA testing.
I've noticed some differences in the successful vs unsuccessful request, though I don't know if they are relevant or are the cause:
code
,scope
,state
,session_state
, andiss
parameterserror=login_required
,state
, andsession_state
parameters (i.e. missingcode
andscope
parameters)Thus, I'm not sure if this is expected behavior, given that the unsuccessful request is missing the
code
parameter - perhaps there is no way for the OIDC middleware to associate it with the original nonce/correlation cookies? Please advise. Our options to mitigate this issue are limited, outside of eliminating silent login functionality which is an option of last resort given we are attempting to support SSO for multiple applications, and that would be a bad user experience.Note: contrary to previously reported issues, I can verify that this is not due to a cookie SameSite issue (the identity server is on the same site, and I can confirm that the cookies are being sent correctly with the
/signin-oidc
request). I can also confirm that there is no login redirect loop happening, and that there is only one challenge being made (in Duende.Bff's implementation of the/bff/silent-login
endpoint).Expected Behavior
When the identity server redirects back to
/signin-oidc
with the?error=login_required
parameter, I expect that it will still delete the nonce and correlation cookies corresponding to the original request, just as it does when the?error=login_required
is not present in the request.Steps To Reproduce
Here is the setup code for our API:
And here is the silent-login functionality on the frontend side (note the issue occurs with or without the
redirectToLogin
functionality below):Exceptions (if any)
No response
.NET Version
8.0.100
Anything else?
ASP.NET Core version is 6.0.25
dotnet --info
: