Media URL generator, SSL offloading and CSP's
a

Arie

about 1 year ago
Dear Umbraco guru's, πŸ˜‰ I've been looking for a solution to a problem regarding to generating URL's for images in a specific situation. I have Umbraco running inside a docker container with a nginx server on ubuntu. Nginx is set up to offload SSL to improve performance on the Kestrel side. In my AppSettings, Umbrco.CSM.Global.UseHttps is set to false. When I browse my media library, images cannot be displayed in Firefox on Mac due to the image url's that are generated. The url's are generated with http scheme, which is to be expected since we are not running on https. The issue is that Firefox is blocking the requests due to CSP violations (see attachment 1). I have tried to set CSP via Middleware but ended up with 2 CSP's for which the most limiting CSP will be used by the browser (see attachment 2). Any idea on how to fix this. I would like Umbraco to always render 'https' scheme for the links it generates for all media and content in loadbalanced / proxied environments. Update: Additional fact is that when I view the details of the image, the image is rendered since it uses a relative URL. This means that the image is accessible. Best regards, Arie https://cdn.discordapp.com/attachments/1297930835055480893/1297930835265192018/image.png?ex=6717b7c9&is=67166649&hm=5b2a213ce4a6fc66b750aef4085c17b167caa01a6ac7947b6742e38cc4f75105& https://cdn.discordapp.com/attachments/1297930835055480893/1297930835571507251/image.png?ex=6717b7c9&is=67166649&hm=9ec674bf406173d014505a03d542e4145d58aa059f0a4967ccb3d4f6a0f9a5af&
[SOLVED] Contentment datalist source with value converter changes between U10 & U13?
d

D_Inventor

over 1 year ago
I am using Contentment 4.6.1 (but also tried 4.7.0) to create a custom picker. The items have an integer id, so I implemented both
IDataListSource
and
IDataSourceValueConverter
. This works for my Umbraco 10 site, I get the picker and the picked items are returned as a list of nullable integers. After upgrading to Umbraco 13, the picker still works, but the values are no longer converted to nullabel integers. When I run the modelsbuilder, all nullable integer properties are replaced with strings. Is there something I'm missing between U10 and U13 so my custom data list keeps working? Here is the code for reference:
csharp
public class TaxonomyDataList : IDataListSource, IDataSourceValueConverter
{
    private readonly ITaxonomyService _taxonomyService;

    // πŸ‘‡ The constructor here is called when I debug
    public TaxonomyDataList(ITaxonomyService taxonomyService)
    {
        _taxonomyService = taxonomyService;
    }

    // --trivial properties omitted for brevity--

    // πŸ‘‡ This part is NOT called
    public object ConvertValue(Type type, string value)
    {
        return int.TryParse(value, out var intValue) ? intValue : null!;
    }

    public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
    {
        var items = new List<DataListItem>();

        // HACK: it's required to run an async task inside a sync context
        var collection = Task.Run(() => _taxonomyService.List(tagsOnly: true)).Result;

        foreach ( var item in collection.Words)
        {
            items.Add(new DataListItem
            {
                Name = item.Word,
                Value = item.Id.ToString()
            });
        }

        return items;
    }

    // πŸ‘‡ This part is NOT called
    public Type GetValueType(Dictionary<string, object> config)
    {
        return typeof(Nullable<int>);
    }
}