-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LogoutHandler doesn't handle expired sessions #10
Comments
The logout code was inherited and I think it needs some work. However, I don't have an IDP anymore to test with, so frankly I am probably not qualified to make sweeping changes like what I need to be made here... but I do accept pull requests from people that are! That said, just to document the problem: The logout handler is dependent in several places on a valid session. It uses this to grab the name of the IDP the user was originally authorized against, so it knows where to send the logout request / response (depending on if its IDP initiated or not, there's several different flows possible here, so its a LITTLE complex, but not overly so). In the simple case (direct Logout.ashx browser redirect, no SAML request), a simple session check and short circuit could be viable. There's even a TODO in this area pointing to something better being possible than the exception being thrown here (e.g., do the local logout just in case, but don't bother sending an IDP logout request), just probably needs validating that that is kosher (though I wouldn't see why it wouldn't be: the session is already dead). The harder cases are the IDP requested ones. There are two possible explanations for why it does what it does here:
I think I could probably make some changes here that would be semi-safe refactoring. I'll play with it and see what I think. In the mean time, to your original question: If you are dealing with an IDP initiated logout flow, you might be a little SOL here. If you just have a link to Logout.ashx somewhere that people are clicking on to get to this, then you could absolutely shim your own endpoint in that they bounce through that adds this session check. In the case their session is already dead, just move on and redirect them somewhere else, otherwise redirect them to the Logout.ashx endpoint. Fairly simple little hack, if not ideal. |
I made a branch with the changes that I THINK should be made here to make it better. It would need to be tested before merging back in though, and needs security review to make sure the changes around relying on request identifier for getting IDP metadata doesn't open up any unintended security issues. |
I encountered the same problem. The SAML2 package relies on the ASP Session to hold some state that is required during logout. I have had some success duplicating this state in the ASP authentication token, using a custom IAction. ` /// Modelleert enkele IDP-sessiegegevens /// IDP is de Identity Provider, zoals DigiD. /// public class IDPSession { public string IDP { get; set; } public string SessionID { get; set; } public string NameIdFormat { get; set; } }
` In global.asax, for each HTTP request, I take these items from the cookie, and add them to the Session state, where SAML2 expects these items to be. `
` Now during logout, SAML2 finds the required values in the ASP Session, even if this session is new and empty. Perhaps I will try making a custom state manager for SAML2 that holds SAML2's state in an encrypted cookie for this purpose alone. |
Did you try the branch mentioned here? It's waiting for merge based on testing, and it at least refactored part of this. It's been a while now, but if you need this as well and are willing to work through the testing with me, I can help get that resolved. |
I've not been able to test, as the project I used this lib on has been in production for a while and I don't have access to another IdP with SAML to test this out on. Would love to see this tested and confirmed, because it still is a "known bug" in our app when logging out. |
I am randomly getting this unhandled exception,
SAML2.Saml20Exception: Unknown identity provider
, when my users try to log out after having previously logged in. Here's the Stack Trace:For the "logout" link, I am simply setting the
HREF
to the/Logout.ashx
URL, which goes through the SAML2 handler and then redirects to the configured logout url (see config below).I cannot seem to reproduce this and was hoping you could shine a light on where I can start looking to debug this issue.
Not sure what all additional information could be helpful, but here's my web.config showing the forms and the SAML configuration:
I think I may have tracked this down to the user having had their ASP.NET Session expired on the server, and when the SAML2 Logout handler tries to access session data to find the identity provider, it is no longer available.
Not sure what the best way to handle this behavior more elegantly for my users. Should I provide a "shim" logout action that check session before redirecting to the Logout.ashx handler?
Any other thoughts?
The text was updated successfully, but these errors were encountered: