Weird "Unable to unprotect the message.State" error

See original GitHub issue

My Web app uses Microsoft.Identity.Web and Microsoft.Identity.Web.UI (1.16.1) to authentication the users. The Web apps are behind BIG-IP for load-balancing and redundancy.

I recently run into an authentication error (500 on the callback URL) on a particular workstation with the browser hitting the load balancer. The Fiddler trace (attached) shows that the .AspNetCore.Correlation and .AspNetCore.OpenIdConnect.Nounce cookies are not included in the request message sent to the callback URL (signin-oidc). The Web app reports “Unable to unprotect the message.State” error as below:

System.Exception: An error was encountered while handling the remote login.
   at async Task<bool> Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
   at async Task Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at async Task CSG.Configuration.AzureSsoService.MiddleWare.RequestResponseLogger.TraceResponseMessage(HttpContext context) in d:/Jenkins/workspace/22.1.0.0.0-ACPx-Configuration-DSM/Src/WorkerService/AzureSsoService/MiddleWare/RequestResponseLogger.cs:line 62
   at async Task CSG.Configuration.AzureSsoService.MiddleWare.RequestResponseLogger.TraceResponseMessage(HttpContext context) in d:/Jenkins/workspace/22.1.0.0.0-ACPx-Configuration-DSM/Src/WorkerService/AzureSsoService/MiddleWare/RequestResponseLogger.cs:line 76
   at async Task CSG.Configuration.AzureSsoService.MiddleWare.RequestResponseLogger.Invoke(HttpContext context) in d:/Jenkins/workspace/22.1.0.0.0-ACPx-Configuration-DSM/Src/WorkerService/AzureSsoService/MiddleWare/RequestResponseLogger.cs:line 26
   at async Task Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)+Awaited(?) ---> System.Exception: Unable to unprotect the message.State.

   --- End of inner exception stack trace ---

Some other facts:

  1. On the workstation that has the above error, the authentication goes through if the browser bypasses the load balancer and hits the Web app host directly.
  2. On other hosts the authentication is successful using the same account and going through the load balancer.

I am puzzled how the load balancer and the particular workstation can interact to prevent the .AspNet.Core.* cookies from being included in the signin-oidc request message.

AzureSsoTrace.saz.gz

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20

github_iconTop GitHub Comments

1reaction
sxseba1commented, Apr 21, 2023

@deadlydog , Thanks for the pointer to using cookie affinity on ingress / load balancer. I was able to fix it with the same solution.

@michiproep , Well, this is the first time I am implementing in dotnet core web app that uses oidc. I didn’t have to worry about these in Angular SPA implementations as it will be the same browser client and do not have to worry about server load balancing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core 3.1 Unable to unprotect the message.State ...
This error "Exception: Unable to unprotect the message.State", usually occurs when you have multiple OIDC middleware.
Read more >
Unable to unprotect the message.State - ASP.NET Core
Basically what happened was that the wrong handler ran when the callback was executed, and it, correctly, failed to unpack the message. builder....
Read more >
Issue in Azure Ad authentication. Error: Unable to unprotect ...
"I believe you are getting the Unable to unprotect the message.State error because one of your OIDC providers is trying to decrypt/unprotect the...
Read more >
Asp.net Core MVC application with Azure AD ...
Unable to unprotect Message.State error. I have a ASP.NET Core 3.1 MVC application which is integrated with AZURE AD for authentication.
Read more >
Unable to unprotect the message.State
We're developing an aspnet core website with webapi backend all on a cloud platform. The auth part is implemented with openidconnect and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found