question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid state cookie

See original GitHub issue

Describe the bug Transient errors that say “Invalid state cookie” from the BankIdHandler.

This report is from Slack user Anton K: I can provoke this error myself by removing the “__ActiveLogin.BankIdState”-cookie or by modifying the value within the cookie during the login flow. This got me thinking that some devices/browser may have problems setting the cookie. The cookie is set as HTTP-Only, Secure and Lax.

What area is it related to BankId

To Reproduce Steps to reproduce the behavior:

  1. Remove “__ActiveLogin.BankIdState” cookie
  2. See error

Expected behavior Successful signin.

Screenshots

[2021-11-29 09:57:57 Error] Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware
An unhandled exception has occurred while executing the request.
System.Exception: An error was encountered while handling the remote login.
 ---> System.Exception: Invalid state cookie
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()
   at IdentityServer4.Hosting.FederatedSignOut.AuthenticationRequestHandlerWrapper.HandleRequestAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

NuGet package version 4.0.0

Runtime version netcoreapp3.1

Smartphone (please complete the following information):

  • ios
  • safari

Only seen on ios and safari. Unknown versions.

User reports being able to sign in “sometimes” and then not so it seems to be a transient error where we sometimes get into a bad state. Perhaps due to refresh/reload/back button pressing or using old/stale data.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
PeterOrneholmcommented, Jan 18, 2022

A beta is now released to NuGet - please try it out when you have time! https://www.nuget.org/packages/ActiveLogin.Authentication.BankId.AspNetCore/4.1.0-beta-1

Ping @span @antonkallenberg

0reactions
antonkallenbergcommented, Jan 26, 2022

@PeterOrneholm Have created our own IBankIdInvalidStateHandler. Tested in my local development environment, works great! Not deployed to production yet, but it “works on my machine”. Great job, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Invalid state cookie. An error was encountered while ...
c# - Invalid state cookie. An error was encountered while handling the remote login. ASP.NET Core MVC external social login - Stack Overflow....
Read more >
C# – Invalid state cookie. An error was encountered while ...
C# – Invalid state cookie. An error was encountered while handling the remote login. ASP.NET Core MVC external social login – iTecNote.
Read more >
Invalid cookie domain - WebDriver - MDN Web Docs
The invalid cookie domain error is a WebDriver error that occurs when an illegal attempt was made to set a cookie under a...
Read more >
Troubleshoot WordPress Plugin Invalid State Errors
Common causes of the invalid state error · Cached callback URLs · Cached cookies and URL parameters · Page refresh after error message...
Read more >
Error: Invalid state returned from Google oAuth provider on ...
Hello everyone, My Next-Auth application works completely fine when am running this in local environment, the redirection from google, ...
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