5

We've migrated our Sitecore solution from Sitecore 9.3 to 10.4 and GlassMapper is used to map items on backend code (GlassMapper updated too - latest version).

On some RichText fields we have Sitecore internal links. For the application users without permission to read the referenced item in that link, the following error is thrown and the field content/component is not displayed on front-end:

    ERROR Failed to render field
    Exception: Glass.Mapper.MapperException
    Message: Failed to render field {FDC75776-18F5-48EC-8AD6-CAE7EF986A2F} on item {4771E685-AB76-473E-9556-6DB57A4EF37D}
    Source: Glass.Mapper.Sc
       at Glass.Mapper.Sc.DataMappers.SitecoreFieldStringMapper.RunPipeline(Field field, GetOptionsSc options) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldStringMapper.cs:line 94
       at Glass.Mapper.Sc.DataMappers.SitecoreFieldStringMapper.GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldStringMapper.cs:line 63
       at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.LoadValue(AbstractPropertyConfiguration propertyConfiguration) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:line 115
       at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.Intercept(IInvocation invocation) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:line 85
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.Proxies.IMilkConsignmentOverviewProxy.get_TableCaptionContent()
       at lambda_method(Closure , MilkConsignmentOverview )
       at Glass.Mapper.Sc.GlassHtml.NormalModeOutput[T](Expression`1 field, Expression`1 standardOutput, T model, SafeDictionary`1 dictionary) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\GlassHtml.cs:line 639
       at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\GlassHtml.cs:line 603
    
    Nested Exception
    
    Exception: System.NullReferenceException
    Message: Object reference not set to an instance of an object.
    Source: Sitecore.Kernel
       at Sitecore.Links.UrlBuilders.Helpers.ItemPathBuilder.GetRelativePath(Item item, SiteInfo site)
       at Sitecore.Links.UrlBuilders.Helpers.ItemPathBuilder.Build(Item item, SiteInfo site)
       at Sitecore.Links.UrlBuilders.ItemUrlBuilder.UpdateItemPathParts(Item item, UrlBuildModel model, ItemUrlBuilderOptions options)
       at Sitecore.Links.UrlBuilders.ItemUrlBuilder.Build(Item item, ItemUrlBuilderOptions options)
       at Sitecore.Links.DynamicLink.BuildItemUrl(ItemUrlBuilderOptions options)
       at Sitecore.Links.ItemLinkExpander.Expand(String& text, ItemUrlBuilderOptions urlOptions)
       at Sitecore.Links.LinkProvider.LinkParser.ExpandDynamicLinks(String text, ItemUrlBuilderOptions options)
       at Sitecore.Links.LinkProvider.ExpandDynamicLinks(String text, Boolean resolveSites)
       at Sitecore.Links.DefaultLinkManager.ExpandDynamicLinks(String text, Boolean resolveSites)
       at Sitecore.Pipelines.RenderField.ExpandLinks.Process(RenderFieldArgs args)
       at (Object , Object )
       at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
       at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
       at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
       at Glass.Mapper.Sc.DataMappers.SitecoreFieldStringMapper.RunPipeline(Field field, GetOptionsSc options) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldStringMapper.cs:line 84

The workaround to fix the error is setting configuration on the model attribute: Setting = SitecoreFieldSettings.RichTextRaw

Do you know what was changed maybe from the previous Sc version implementation?

Since we have many models, is there a more generic way to fix this behaviour?

Thanks for your help.

2 Answers 2

2

I was able to reproduce this issue on Sitecore 10.4 and latest glass mapper version. The reason we are getting this issue is when there are internal links on the rich text, it gets converted to the friendly url using the Sitecore.Pipelines.RenderField.ExpandLinks processor inside the renderField pipeline.

The ExpandLinks processor internally calls the Sitecore.Links.Item.ItemLinkExpander class to tranform the internal links. Inside this class, Sitecore.Links.DynamicLink object is build to get the item url. DynamicLink object then calls the BuildItemUrl function, which have the check for when the item is null, return item not found link.

enter image description here

But since will getting the item, security check is disable hence the item level check is skipped inside this class.

Above function then calls the LinkManager.GetItemUrl function which then calls the GetRelativePath function inside the ItemPathBuilder class. Inside this function, item is fetched without the security disable check and hence its gets failed while retrieving Paths property.

enter image description here

I hope this clarifies you the reason behind this issue. I believe you should raise a Sitecore ticket for this behaviour and they can help with the hotfix for this.

Update:

One of the ways to solve this would be by overriding the ExpandLinks processor with SecurityDisabler option as below.

using Sitecore.Pipelines.RenderField;
using Sitecore.SecurityModel;

public class CustomExpandLinks : ExpandLinks
{
    public override void Process(RenderFieldArgs args)
    {
       using (new SecurityDisabler())
       {
          base.Process(args);
       }
    }
}

This custom processor then needs to be patched in as below to replace ExpandLinks processor.

<?xml version="1.0"?>
<configuration>
   <sitecore>
     <pipelines>
         <renderField>
                <processor patch:instead="*[@type='Sitecore.Pipelines.RenderField.ExpandLinks, Sitecore.Kernel']" type="SitecoreScaledExtensions.Pipelines.CustomExpandLinks,SitecoreScaledExtensions"/>
          </renderField>
        </pipelines>
   </sitecore>
</configuration>

Note: This would solve the exception you are getting but the links inside the href in the rich text will not contain 404, as we have disabled the security check while reading links in the rich text. But once the user visit those links those would redirect to 404 page.

Hope this helps!!! Let me know in case you have any queries.

0

I ran into the same issue where indeed the dynamic link expander didn't take into account item permissions. And instead of failing silently it throws a null reference.

I ended up making my own custom processor:

Patched into config:

<pipelines>
        <renderField>
            <processor
                type="XXX.Foundation.SitecoreExtensions.Extensions.CustomExpandLinks, XXX.Foundation.SitecoreExtensions"
                patch:instead="processor[@type='Sitecore.Pipelines.RenderField.ExpandLinks, Sitecore.Kernel']" />
        </renderField>
    </pipelines>

With code:

using Sitecore.Pipelines.RenderField;
using Sitecore.SecurityModel;
namespace XXX.Foundation.SitecoreExtensions.Extensions
{
 public class CustomExpandLinks : Sitecore.Pipelines.RenderField.ExpandLinks
 {
    public override void Process(RenderFieldArgs args)
    {
        // Disable security to allow to read cross site link resolving
        using (new SecurityDisabler())
        {
            base.Process(args);
        }
    }
 }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.