Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeremias 53 posts 278 karma points
    Nov 30, 2017 @ 10:02
    Jeremias
    0

    Securing Images from ImageCropper

    Hello together,

    I need to secure some files from the media-folder. Reason for this is, that I have an intranet and a website in the same umbraco-instance. Now everybody could call the pictures/files from the intranet with the domain of the website.

    For this I can't use mediaprotect, because there is no use of members in this umbraco-instance

    At the moment I use the following solution. And it works mostly correct:

    https://martincarlsen.com/securing-media-files-in-umbraco/

    My only problem is, that all images, which are called with ?with=xy... don't go via my route. In my opinion it just goes through the image-Cropper and thus not via my route.

    So my question is: Is there a way to get into the image-Cropper-event to block images?

    I use Umbraco 7.7.6

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Dec 27, 2017 @ 12:45
    Alex Skrypnyk
    100

    Hi Jeremias

    I think you need to create httpModule for checking access to image and place it before Umbraco modules, so you will check access before image cropper will change the image.

    What do you think about this approach?

    Thanks,

    Alex

  • Jeremias 53 posts 278 karma points
    Jan 15, 2018 @ 07:50
    Jeremias
    1

    Hi Alex,

    Yes, that's the solution! Thank you. Now I just have one question: Is there a way to get the ApplicationContext?

    public class SafeImageLoad : IHttpModule
    {
        private IMediaService mediaService;
        private IDomainService domainService;
    
        private MyEventHandler _eventHandler = null;
    
        public SafeImageLoad()
        {
            mediaService = ApplicationContext.Current.Services.MediaService;
            domainService = ApplicationContext.Current.Services.DomainService;
        }
    }
    

    That's the beginning of my HttpModule. But ApplicationContext.Current is null...

  • Jeremias 53 posts 278 karma points
    Jan 15, 2018 @ 10:25
    Jeremias
    1

    I found a solution for this :)

    I tried to get Access to ApplicationContext inside the Construct. Now I put this 2 lines in the Request-Method and there it works :)

    public void Init(HttpApplication app)
    {
        app.BeginRequest += LdProtectRequest;
    }
    

    And here my Request-Method

    public void LdProtectRequest(Object s, EventArgs e)
    {
        HttpApplication app = s as HttpApplication;
        IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
        IDomainService domainService = ApplicationContext.Current.Services.DomainService;
    }
    

    Thank you for your post - It works. Also with Image-Cropper :)

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jan 15, 2018 @ 10:28
    Alex Skrypnyk
    0

    Thanks for sharing with our community !!!

    Have a great day

  • Jeremias 53 posts 278 karma points
    Jan 15, 2018 @ 10:31
    Jeremias
    1

    Thank you, too!

    I also wish you a great day!!

Please Sign in or register to post replies

Write your reply to:

Draft