2

Recently, we received a website visit report indicating a significant number of non-existent language versions visits on our Sitecore 9.3 website (see to the image below).

enter image description here

We have only enabled the English version, so we are concerned whether these records are a result of external tools attacking our site or if this is a normal occurrence. This issue started occurring since last month.

We would greatly appreciate guidance on how to prevent such occurrences and ensure the security of our website. Please provide any advice or recommendations you may have.

What is the recommended approach for handling inactive language versions on Sitecore 9.3? Currently, when accessing an inactive language version, it returns an empty header using the default layout, which is not considered best practice. Please provide guidance on how to handle this situation appropriately.

1 Answer 1

2

Ideally, when there is no language version, 404 Page Not Found status should be returned.

Long long time ago I wrote a blog post with sample code which sets Sitecore.Context.Item to null if the item doesn't have language version.

You can find it in wayback machine:

https://web.archive.org/web/20150324234154/http://www.cognifide.com/blogs/sitecore/sitecore-displaying-pages-without-a-language-version/

In shortcut - register your processor after ItemResolver or some other custom item resolvers that you have in your application:

<processor type="Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel"/>
<processor type="MyAssembly.MyNamespace.ItemLaguageVersionValidator, MyAssembly" />

And in the code check number of versions in current language like that:

public class ItemLaguageVersionValidator : Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
    public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
    {
        // don't change the flow of Experience Editor or Preview mode
        if (!Context.PageMode.IsNormal)
            return;

        if (Context.Item != null 
            && Context.Item.Paths.IsContentItem
            && Context.Item.Versions.Count == 0)
        {
            Log.Info($"Not existing language '{Context.Item.Language}' request for item '{Context.Item.Paths.FullPath}'", this);
            Context.Item = null;
        }
    }
}
1
  • Hi @Marek Musielak, Massive thanks for your detailed reply and will have a try.
    – Alexander
    Commented Aug 10, 2023 at 9:58

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.