Monday, October 12, 2020

Investigation and fix for SubmitCurrentVisitorOrder: Object reference not set to an instance of an object.

Recently, We got this issue while processing the order, Here are the investigation and fix details

We did a third party payment integration and while the payment party submit the success request to our website (XP + XC 9.3) we took the transaction details, Add a new components and send it to create the order.

The order created successfully but XC didn't redirect to order confirmation page, I think the process is after the order submission XC internally call the SubmitCurrentVisitorOrder to get the order details and show to the order confirmation page.



Investigation -  The error was clear the context was missing of visitor could be related to ant forgery or some missing handshake.

the point was the it was working fine in Firefox browser, so first we compare all cookies and session with Mozila and found a diff.


Mozila - We didn't find any diff.



We noticed that in Chrome there are mismatch in the ASP.NET_SessionId and there are a few missing cookies Global Analytics.

We have disabled the analytics and after that we found the same ASP.NET_SessionId and Analytics cookies,

So the issue was related to analytics, We have turned it off and raised a Sitecore ticket for the further investigation, I will keep you posted for the further update.



Sunday, October 11, 2020

Simple powershell ISE script to replace/correct sitecore content items.

  Recntly, I got a requirement to update all the content item, basically replacing all spaces with _ (under score).

Here is simple script to do that.

 cd '/sitecore/content/Home/Test'  
 Get-ChildItem -Recurse . | Where-Object { $_.Name -match " " } | ForEach-Object {   
   $originalName = $_.Name  
   $newName = $originalName -Replace " ", "_"  
   Write-Host "Renaming item from " -nonewline;  
   Write-Host $originalName -f Yellow -nonewline;  
   Write-Host " to " -nonewline;  
   Write-Host $newName -f Green;  
   $_.Editing.BeginEdit()  
   $_.Name = $newName;  
   $_.Editing.EndEdit()  
 }  

We can extend this script to update/assoicate the image url for the catalog items and so It's taht much easy.

Friday, October 9, 2020

Sitecore XC 9.3 - HttpAntiForgeryException during third party payment integration and enable SameSite cookies with .Net framework 4.7.1.

 Recently, I have integrated a third party payment system with the Sitecore XC 9.3.

The high-level process flow was that our Application would open the payment gateway with some hash key generated (based on a few fields), Application will also send the redirect URL in case of failure and success.

Now, Once we open the payment gateway and when it redirects to our website, It fails only in chrome browser and it was happening randomly, not always.

We did the investigation and discussed with the payment provider, They did mention below details.

The issue is missing Session-Id when the payment provider returns for the diff domain, and because of change in Session, the Sitecore XC application understands this as an attack and didn't get the context.

The default Asp.Net Session-Id is SeamSite = Lax


More details about available here  - t.ly/cAp0

Details - Short Description of Incident


Q.1 How does Chrome `SameSite` Cookie policy affect my browser redirection integration? In Chrome v.84 SameSite cookie attribute is released which if not handled by the server may lead to an issue causing loss of session data or session ID gets NULL. Merchants might experience a sudden surge of incomplete orders at their end Q.2 About Chrome's `SameSite` Cookie Policy For users running Chrome v.84 and higher, Chrome is enforcing a secure-by-default cookie classification system treating cookies that have not declared `SameSite` value as `SameSite=Lax` cookies. Only cookies set as `SameSite=None` will be available, provided they are being accessed from secure connections. Chrome 84 release note link for reference:https://support.google.com/chrome/a/answer/7679408?hl=en Q.3 How to fix (or prepare) for it? Session data is not a part of PayU integration, it is managed by merchants. You can refer to the link below and make required changes.Below link can be used for reference.( Ref. https://web.dev/samesite-cookies-explained/ )


Reference - https://docs.microsoft.com/en-us/aspnet/samesite/csmvc



I was using .Net framework version 4.7.1 and had no time to migrate the version at this short time, now the second option is how to manage this in .Net framework version 4.7.1, I found a solution and able to get the appropriate result, here are the details.

I rad 100's of the article and StackOverflow post on that to use custom modules and so but finally able to manage through the below steps -

Overview

========

The <sessionState cookieSameSite="None" /> and <httpCookies requireSSL="true"/> settings in web.config

set the SameSite=None and Secure cookie attributes of the ASP.NET session cookie but don't take into 

account incompatible browsers.

The SameSiteNone HTTP Module is an alternative approach that sets the SameSite=None and Secure cookie attributes 

if the browser is compatible and clears the SameSite attribute if the browser is incompatible.

Incompatible browsers are listed at:

https://www.chromium.org/updates/same-site/incompatible-clients

It requires .NET framework v4.8 or later to be installed on the web server.

The web application does not have to target .NET framework v4.8 or later.

Configuration

=============

Add the following to the application's web.config.

  <system.webServer>

    <modules>

      <add name="SameSiteNoneHttpModule" type="ComponentSpace.SameSiteNoneHttpModule"/>

    </modules>

  </system.webServer>

Copy the ComponentSpace.SameSiteNone.dll to the application's bin folder.

Specifying the Cookies

======================

By default the HTTP module monitors the ASP.NET_SessionId cookie and updates it, if required.


The SameSiteNoneCookies app setting in the application's web.config may specify a comma-separated list of cookies to monitor.

  <appSettings>

    <add key="SameSiteNoneCookies" value="ASP.NET_SessionId, some-other-cookie"/>

  </appSettings>

I found this dll from the ComponentSpace, but can't see the link anymore so adding the package reference here if anyone wants to download and try

t.ly/4a7E


Even, After this change, We couldn't resolve the issue and finally followed below approach to provide the fix.

We created an intermediate page to redirect the response from the payment provider and redirect again to the Sitecore XC review page.

That change also sometimes got fail (I know it's weird).

 Finally, on the review page, in case if we were getting the null response from the payment provider (Transaction null), we were calling the payment provider API again to get the latest transaction update. As there was an option to get the transaction details based on input value transaction id ( which we generate before calling the payment provider), We used the same pre-transaction Id to get the response, and that has wholly unblocked us.

Let me know if you have any questions,

Sitecore XC 9.3 Bizfx - Fix for weird Display text and images.

 Recently, I found a difference in Bizfx dashboard and the inventory was not loading properly (Not showing sellable items).




I checked the log and found the Redis OOTM error, Increasing the Redis memory had resolved the issue.



Thursday, October 8, 2020

Sitecore XC 9.3 - Investigation and fix for PolicySet json is not valid.

 


Recently, I have created a new plugin and published my changes, during the bootstrap, I noticed below error.
 "@odata.context": "https://localhost:5000/CommerceOps/$metadata#Commands/$entity",  
 "@odata.type": "#Sitecore.Commerce.Core.Commands.BootstrapCommand",  
 "Id": "2ac9de6b5e6449458cf4276f2043762a",  
 "ResponseCode": "Error",  
 "Messages": [  
  {  
   "MessageDate": "2020-10-08T07:17:30.7284748Z",  
   "Code": "Error",  
   "Text": "PolicySet json is not valid.",  
   "CommerceTermKey": "InvalidPolicySetJson"  
  }  
 ]  
 }  


Initially, I thought it's related to json format of the policy so I quickly revalidated all the format but the format was okay.

I compared the field in the ClientPolicy.cs and Policy.json file those were identical, After a quick investigation, I noticed that the namespace of my class file was not correct, Channing the correct namespace fixed that issue.

I didn't see any hint in output response which can point out that the issue in a particular file, I had to review all the recent files, I think we should have that option, If I get a chance I will share my feedback with the Sitecore or will extend and update in my next blogs.

Please let me know if have any question related to this issue.








Wednesday, October 7, 2020

XP and XC 9.3 - Fix for antiforgery error while user registration and login


During a new CD server machine setup, I found this issue during the login and registration, the error is very straight forward and self-explanatory that it's related to security/ or access of the token beetwen sites.

Error Details
 27432 22:33:04 ERROR One or more exceptions occurred while processing the subscribers to the 'sessionEnd:batch:starting' event.  
 Exception[1]: Sitecore.XConnect.XdbCollectionUnavailableException   
 Message[1]: An error occurred while sending the request.   
 Source[1]: Sitecore.Xdb.Common.Web   
   at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock[TResult](Func`1 taskFactory)  
   at Sitecore.XConnect.Client.XConnectSynchronousExtensions.SuspendContextLock(Func`1 taskFactory)  
   at Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.Initialize(XmlNode configNode)  
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)  
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)  
   at Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert)  
   at Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient(String clientConfigPath)  
   at Sitecore.Analytics.XConnect.DataAccess.BatchEnabledXdbRuntimeContext..ctor(IXdbContextFactory factory)  
   at Sitecore.Analytics.Events.BatchEventHandler.OnBatchStarting(Object sender, EventArgs args)  
   at Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters, EventResult result)   
 27432 22:33:04 ERROR Cannot execute 'sessionEnd:batch:starting' event  
 Exception: System.AggregateException  
 Message: One or more exceptions occurred while processing the subscribers to the 'sessionEnd:batch:starting' event.  
 Source: Sitecore.Kernel  
   at Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters, EventResult result)  
   at Sitecore.Events.Event.RaiseEvent(String eventName, Object[] parameters)  
   at Sitecore.Kernel.Web.SessionExpirationProcessor.TryRaiseEvent(String eventName, Object[] parameters)  
 Nested Exception  
 Exception: Sitecore.XConnect.XdbCollectionUnavailableException  
 Message: An error occurred while sending the request.  
 Source: Sitecore.Xdb.Common.Web  
   at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock[TResult](Func`1 taskFactory)  
   at Sitecore.XConnect.Client.XConnectSynchronousExtensions.SuspendContextLock(Func`1 taskFactory)  
   at Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.Initialize(XmlNode configNode)  
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)  
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)  
   at Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert)  
   at Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient(String clientConfigPath)  
   at Sitecore.Analytics.XConnect.DataAccess.BatchEnabledXdbRuntimeContext..ctor(IXdbContextFactory factory)  
   at Sitecore.Analytics.Events.BatchEventHandler.OnBatchStarting(Object sender, EventArgs args)  
   at Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters, EventResult result)  
 Nested Exception  
 Exception: System.Net.Http.HttpRequestException  
 Message: An error occurred while sending the request.  
 Source: mscorlib  
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  

here is a good read about the anti

https://www.c-sharpcorner.com/article/understand-antiforgeri-token-in-asp-net-mvc/#:~:text=Anti-forgery%20stands%20for%20%E2%80%9CAct%20of%20copying%20or%20imitating,trusted%20source%20sending%20the%20data%20to%20the%20site.

https://www.devcurry.com/2013/01/what-is-antiforgerytoken-and-why-do-i.html

Solution -  I opened the mmc.exe, selected the certificates and allowed all application pools access to the CD server certificate.



Sitecore XP and XC fix for Odata Client, version = 6.19.0.21114- The System cannot find the file specified.

 


Recently, I got above error during the setup of a new CD server (XP (CD role) + XC(Shop role)) 

Seems very straight forward that there is a diff in Microsoft.OData.Client assembly version.

I took the latest configuration (Including web.conf) and dll from one of the working CD server and that change had resolved the issue.