Hide media libraries files from public

Dcode warner asked on May 3, 2017 18:14

To prevent files in a media library from being shared via 'direct path' or permanent link' to the public, how can I disallow the general public from seeing these files and only make them viewable for specified users/roles. Basically I'm trying to deny access to the general public to files for one folder in the media library.

This question is similar to what I'm asking: https://devnet.kentico.com/questions/permission-checking-in-kentico-media-libraries-not-working however, I can replicate that it doesn't work. I can still access the files regardless if its Authenticated or Authorized.

Recent Answers


Brenden Kehren answered on May 3, 2017 18:31

Are you testing on a browser with cache cleared and you being logged out of the Admin interface with your admin account?

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on May 3, 2017 19:13

@Breden Kehren. Correct. Im in a new cleared cached and (and history for good measure) browser.

0 votesVote for this answer Mark as a Correct answer

Jake Burgy answered on May 3, 2017 22:38

In our experience securing media libraries, three things have to happen (and this may not be 100% accurate but we've found these options to work the best) -

  1. Settings > Content > Media > Use permanent URLs must be ON.
  2. Settings > Content > Media > Check files permissions must be ON.
  3. Set the appropriate permissions on the Media Library you want to secure.

Then, when accessing or linking to media in the media library, ALWAYS use the /getmedia/ABCD-...-123/File-Name URL. This will check permissions. If you use the direct file path, permissions are not checked.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on May 15, 2017 22:56

The opposite works for me. Using the Direct path checks for the permission. But the Relative/Permanent link the permission is not checked. How can I switch it around to the way you have yours.

0 votesVote for this answer Mark as a Correct answer

Jake Burgy answered on May 15, 2017 23:01

What version of Kentico are you running?

I'm not sure what would cause the opposite to happen - I would assume that the GUID / permanent URL would go through the Kentico system because it has to resolve it. Using a direct path means that IIS can serve the file directly (because it's physically located on disk on the server), so no Kentico permissions can be checked.

Do you know if you have the runAllManagedModulesForAllRequests="true" option enabled on the system.webServer/modules section in your web.config file? That may have an effect on it, as well.

1 votesVote for this answer Mark as a Correct answer

Dcode warner answered on May 16, 2017 16:44

We're using kentico 7.

Before we make these changes, Do you know what does the setting change and how does it affect the rest of the system?

0 votesVote for this answer Mark as a Correct answer

Jake Burgy answered on May 16, 2017 16:51

Oh, sorry, I'm only familiar with 8+... (K7 is 5 years old now!) I couldn't tell you what the behavior of those settings are in 7, or even if those settings exist!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 16, 2017 17:39

Dcode,

The config change Jake suggests won't break your site. It is needed in v7 for extensionless urls and a few other features. Check out the IIS Documentation on the modules node.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on May 22, 2017 19:02

@Brenden Kehren and @Jake Burgy I confirm that these settings are already set as true in K7.

Alternatively, is there a way to redirect a URL that matches a path to my login page instead of the CMSDESK (I was hoping I can do this in the Random Redirect webpart):

Example: https://www.xxx.com/site/media/gallery/folder/fileA.pdf
https://www.xxx.com/site/media/gallery/folder/fileB.pdf
https://www.xxx.com/site/media/gallery/folder/fileC.pdf

0 votesVote for this answer Mark as a Correct answer

Jake Burgy answered on May 22, 2017 19:22 (last edited on May 22, 2017 19:22)

Yes, but this is outside the scope of Kentico, you would do this at the IIS level using the URL Rewrite module.

Here is some Microsoft documentation on how you can redirect certain pages, paths, folders, etc. to a different location based on some criteria:

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.