During a vulnerability scan, Path-Based Vulnerability has been reported in the below-mentioned links,

www.sample.com/web/abcdefgh/ijklmnop/-/document_library_display.old www.sample.com/web/abcdefgh/ijklmnop/-/document_library_display.bak www.sample.com/web/abcdefgh/ijklmnop/-/document_library_display.inc

We do not find any .old, .bak and .inc files present anywhere in the application.how to avoid accessing these extensions.


1 Answer 1


It's a known issue that Sitecore will serve media requests regardless of the request extension. If you want to prevent media being accessed using an incorrect extension then you need to handle this yourself.

Media Request Event

One option is to add an handler for the media:request event that will check the file extension of the request against the resolved media item, and return a 404 status code if they do not match.

using System;
using System.Linq;
using System.Net;
using Sitecore.Events;
using Sitecore.IO;
using Sitecore.Resources.Media;

namespace MySite.Custom.Media.Events
    public class CheckMediaExtension
        public void OnMediaRequest(object sender, EventArgs args)
            // Safety checks
            if (Sitecore.Context.Site.Name.Equals(Sitecore.Constants.ShellSiteName, StringComparison.InvariantCultureIgnoreCase))
            var sitecoreEventArgs = (SitecoreEventArgs) args;
            if (sitecoreEventArgs == null || !sitecoreEventArgs.Parameters.Any())
            var request = (MediaRequest) sitecoreEventArgs.Parameters[0];
            if (request == null)

            // Now we've established we have a valid request
            var mediaItem = MediaManager.GetMedia(request.MediaUri).MediaData.MediaItem;
            string requestExtension = FileUtil.GetExtension(request.InnerRequest.RequestContext.HttpContext.Request.FilePath);

            if (!string.Equals(mediaItem.Extension, requestExtension, StringComparison.InvariantCultureIgnoreCase))
                var response = request.InnerRequest.RequestContext.HttpContext.Response;
                response.TrySkipIisCustomErrors = true;
                response.StatusCode = (int) HttpStatusCode.NotFound;

And then patch this event handler in:

    <event name="media:request">
      <handler type="MySite.Custom.Media.Events.MediaRequestEvent, MySite.Custom" method="OnMediaRequest"/>

If you go down this route then make sure you have set the Media.RequestExtension to empty, which will cause the media URLs to be generated with the correct file type extension.

  The extension to use in media request URLs.
  If the value is not set, the Extension field of the individual media items 
  will be used (ie. JPG, GIF, etc.)
  Default value: "ashx"
<setting name="Media.RequestExtension" set:value=""/>

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.