Sustainsys / Saml2

Saml2 Authentication services for ASP.NET
Other
961 stars 602 forks source link

Wrap CommandResultExtensions.Apply with error checking to trap null object exceptions #1454

Closed mjorrens1 closed 4 months ago

mjorrens1 commented 5 months ago

We have a variety of customers using the Saml2.AspNetCore2 Nuget package version 2.9.2 in our server-side Blazor application (.Net 8) with no problems. One recent customer though is getting a null object exception error in CommandResultExtensions.Apply (https://github.com/Scalesoft/Sustainsys-Saml2/blob/a6a079aaf436ffb6c366027a5ff27976255dc73a/Sustainsys.Saml2.AspNetCore2/CommandResultExtensions.cs#L12).

It is unclear why the error is happening for this customer and not easy to track down as this method is not wrapped in a try/catch block.

Getting a more specific error would help diagnose the problem with this customer.

Here is the stack trace we see now: 2024-06-05 15:01:51,646 INFO Sustainsys.Saml2.AspNetCore2.Saml2Handler - Successfully processed SAML response _f120046cf810689c4cbbc347aa7ceead and authenticated 700322603 2024-06-05 15:01:51,647 ERROR BudgetPak.ExceptionMiddleware - RequestPath: /Saml2/Acs

Update - 06/11/2024 The cause of the crash above was that the CommandResult.Location that holds the RelayState was null. Once our customer set that properly, there was no crash. The is a check for CommandResult.Location != null in the Apply method of CommandResultExtensions so a bit unclear where it crashed in that routine. Either way, some error trapping on this method would be great to have.