IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Correlation failed at signin-oidc redirect

Open rohan-gaitonde opened this issue 9 years ago • 35 comments

I keep receiving the following error after the Consent screen where I am going to the client “signin-oidc” url (please refer to images in attached doc for reference):

Unhandled remote failure (Correlation failed)

This was not an issue on my development build (VS2015 /w IISExpress) and only started after I had published the application.

From what I could find on Google, I can see that the issue is cause due to missing cookies. Would be helpful if I could get a better understanding and also some tips on how to debug it.

I have attached the debug log from the client, and from Fiddler, for reference.

logs.docx

Some background on my current setup –

  • IdentityServer with ASP.Net Core Identity Integration and EntityFramework persistence layer (combined from your ASP Identity and EntityFramework Quickstarts)
  • MVC Client (created using the MVCHyrbid Quickstart)

Both applications are deployed on separate domains:

  • IdentityServer is on a Windows Server 2012 R2 machine behind IIS 8.5
  • Client is on Windows Server 2008 R2 behind IIS 7.5

Appreciate the help!

rohan-gaitonde avatar Jan 20 '17 08:01 rohan-gaitonde

I am hitting this with the following combination:

  1. Browser incognito mode
  2. Application is behind Azure gateway

I am not even using IdentityServer; it is plain old Azure AD authentication (openid). I see that Cookies->{Mysitename} has the following:

image

HANDLING IN CODE I tried to handle the OnRemoteFailure() event as suggested above, and redirect to "/" which is a secure endpoint for me, but it causes an infinite loop of authentication from / to /signin-oidc to / to /signin-oidc... perhaps I should redirect somewhere else? Or write a specific page that will hard clear the cookie cache and then redirect to the "/" page?

WORKAROUND

  1. Users can go to the homepage again and hit F5 until this works. It seems that each F5 gets them moving a step ahead and once the OpenID cookies are populated, everything else (I have more auth after openid finishes, via adal.js for AJAX use).
  2. Bypass the application gateway and use the direct service fabric cluster DNS name (not acceptable as it is http).

DETAILS System.Exception: Correlation failed. at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()

image

sathiathirumal avatar Apr 30 '18 17:04 sathiathirumal

It's a bit off topic for this issue @sathiathirumal, this being about identity server. You're better asking such things on stack overflow. But yes, of course if authentication fails and on failure you redirect to a secure end point, that's going to trigger authentication again and thus the infinite loop.

coffeymatt avatar May 01 '18 09:05 coffeymatt

Fair enough @coffeymatt - I will pursue this in a more appropriate forum. My point was that this seems to happen even outside of IdentityServer, so I am not sure if the issue is further upstream and generally related to running your services behind an application gateway (somehow).

sathiathirumal avatar May 01 '18 21:05 sathiathirumal

@sathiathirumal I am hitting same problem. Do you solve this issue?

My environment is:

  • 4 nodes Service Fabric Cluster ( IP is :192.168.100.16-192.168.100.19)
  • 2 nodes NLB+ARR as Load Balance, I have Virtual IP is 192.168.100.60, NLB1 IP is 192.168.100.13, NLB2 IP is 192.168.100.14
  • STS web stateless service run on 4 SF nodes
  • Client(a management console web) also run on 4 SF nodes

My problem is :

  • When I open mc web in Chrome with 192.168.100.60 (with NLB+ARR), then login with sts, I get error "Correlation failed".
  • When I open mc web in Chrome with 192.168.100.13 (only with ARR), then login with sts, I also get same error.
  • When I open mc web in Chrome with 192.168.100.16 (access SF node directly), then login with sts, it is working. STS always run on 4 SF nodes with NLB+ARR in above 3 situations.

heavenwing avatar May 29 '18 08:05 heavenwing

@heavenwing I have been posting on this at https://github.com/aspnet/Security/issues/1755

sathiathirumal avatar May 31 '18 05:05 sathiathirumal

In case anyone runs into this issue: we had the exact same problem, turned out it had to do with the data protection APIs. I detailed it on my blog (https://www.kevindockx.com/solving-correlation-failed-state-property-not-found-errors-openid-connect-middleware-asp-net-core/), but to summarize: the OIDC middleware uses the data protection APIs to encrypt/decrypt state. When decryption fails, state is null, thus resulting in a Correlation failed: state not found error. In our case, decryption failed because different keys were used for encryption/decryption, a pretty common problem when deploying behind a load balancer. The solution was to use a shared key store.

KevinDockx avatar Jun 01 '18 09:06 KevinDockx

@heavenwing see https://github.com/aspnet/Security/issues/1755#issuecomment-392803709 on how I solved this for my issue. (hint: yes it was the DataProtection layer missing and OIDC middleware being unable to decrypt cookies that were generated/encrypted on a different node)

sathiathirumal avatar Jun 01 '18 17:06 sathiathirumal

For me this issue was using the default Cookie Policy:

public void Configure...
{
    // This will override cookie settings for OpenIdConnect
    // Nonce and Correlation Cookies included.
    app.UseCookiePolicy(); 
}

DwaynesWorld avatar Oct 20 '18 22:10 DwaynesWorld

I had the same problem and I fixed it using @coffeymatt suggestion.

options.Events.OnRemoteFailure = context => { if (context.Failure.Message.Contains("Correlation failed")) context.Response.Redirect("/"); else context.Response.Redirect("/Error");

     context.HandleResponse();

      return Task.CompletedTask;

};

Daniel-iel avatar Nov 06 '18 17:11 Daniel-iel

I had two instances of identity server, one as primary one and other acting as external identity provider for primary one. When I try to login from an javascript client I am able to authenticate the user and when redirecting to application I am getting as Correlation failed. Can someone help me? image

muralisambu avatar Dec 18 '18 12:12 muralisambu

The exact issue that causes this is in the AspnetCore authentication flow, specifically in this class: RemoteAuthenticationHandler.cs. If you look in there you will see a number of causes for the message: the correlation cookie was never issued, is for a different auth flow than the one in progress, or has expired for example. One thing that can help with debugging is to make your client app log at the Trace level: you can see in that file that the client auth framework actually does quite a bit of logging, but all of it is invisible at the normal 'Warning' level except for the final exception.

ChrisPritchard avatar Dec 18 '18 17:12 ChrisPritchard

In our case, this was the reason #1510 . It results in the same behaviour so I decided to drop this here. (kudos: https://github.com/aspnet/Security/issues/1755#issuecomment-395698175)

vetras avatar Apr 01 '19 17:04 vetras

I've also encountered this issue and it was caused by ForwardedHeadersOptions not being set to forward XForwardedProto. The app was running behind an IIS proxy and because the protocol was not being forwarded, the redirect went to http instead of https (and http was not allowed in RedirectUris). So enforcing the default config solved the issue:

services.Configure<ForwardedHeadersOptions>(options =>
{
    options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
 });

mvacha avatar Apr 03 '19 14:04 mvacha

@brockallen @openidauthority What sort of security purposes are served by the RemoteAuthenticationTimeout described here: https://github.com/IdentityServer/IdentityServer4/issues/720#issuecomment-311208551 ? I have some ideas but would like to know what the official reason is or what sorts of attacks this can help defend against.

My guess was that there could be information stored in the state that could be misused if a user leaves the login page open, not realizing the page contains this information (similar to leaving a site logged in on a public computer). For example, a user might receive an invite link to my application, follow the link which redirects them to the oauth server login page (which would securely encrypt the various invite token properties into the state param), and then leave that page open. Without the expiring cookie based on RemoteAuthenticationTimeout another user could log in to the page and redirect back to my application, and have essentially stolen the invite token and applied it to their own user account. With the expiring cookie, they will redirect back to the application but not successfully complete the login/signup.

Maybe I'm way off here though, so I would like to know what else this helps prevent.

dferretti avatar Nov 27 '19 21:11 dferretti

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 10 '20 12:01 lock[bot]