umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.36k stars 2.64k forks source link

IVirtualPageControllers localize based on browser-headers since the introduction of EagerMatcherPolicy #16626

Closed kasparboelkjeldsen closed 1 week ago

kasparboelkjeldsen commented 1 week ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.3.2 or newer, including 13.4.0-rc2

Bug summary

If you are using an IVirtualPageController with a mapped endpoint, and in the view or controller utilize Umbracos dictionary or other features that rely on the CurrentUICulture of the current thread, it will chose the language/culture based of browser headers and not the domain setup in Umbraco.

When I manually disable the new EagerMatcherPolicy service and rely on the standard non-optimized behavior everything works as it should.

Specifics

I have set up a POC on this public repository

https://github.com/kasparboelkjeldsen/Umbraco.LocalizationBugIn13.3.2/tree/main

It includes database and everything for ease of reproduction.

I discovered this bug when a customer was experiencing weird behavior for some of their users - specifically those using Edge or Brav browser, but not those using Chrome.

After a long investigation I've tracked it down to being due to the "Accept-Language" header being sent by the browsers being different, and Chrome (for Danes at least) will start it's header with "da-DK" whereas the other browsers won't.

I don't know the exact machnics of MachingPolicies well enough to know how this happens, but the end result is, that the "System.Threading.Thread.CurrentThread.CurrentUICulture" will differ on the View, based of the browser-headers.

As Umbracos dictionary and I assume other things rely on the CurrentUICulture being set correctly based of the domain and language setup in the CMS this can have quite severe consequences.

In my POC you will see a frontpage that has a single dictionary key, with the default language being danish. There is no english domain setup, so we should never see the english dictionary key.

I have then set up the route /silly to go through a IVirtualPage controller that just loads the same content. This time the dictionary item will be in English if the browser hasn't sent a accept-language header that starts with "da-DK".

I've included a lazy JS test on the page as well so you don't have to fiddle with browers and settings to test it.

image

Steps to reproduce

You can pull down the POC or

Expected result / actual result

I expect my translations to be in the language I've set for the domain in Umbraco

github-actions[bot] commented 1 week ago

Hi there @kasparboelkjeldsen!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

kasparboelkjeldsen commented 1 week ago

Further testing: It's worth noting that if your languages don't include English as one of them, anyone visiting a page that is handled through the EagerMatcherPolicy that doesn't happen to have the correct accept-lanuage in their request header will get blank dictionary values.

Zeegaan commented 1 week ago

Fixed in https://github.com/umbraco/Umbraco-CMS/pull/16635