2

I am creating a site using ASP.NET MVC4, one of the functions on the site is for users to upload images. The images may be of a personal nature, almost definitely containing images of their children.

The images are being stored on MS Azure SQL Database along with their metadata. To save bandwidth usage on azure, once the image has been downloaded, it saves to a user directory

~/UserImages/<Username>/<Image>

When the gallery page is loaded, the controller action checks the database against what is in the users directory and just brings down any not already there.

The <Username> part of the directory is created by the controller when required, so I am unable to set IIS permission on it. However even if I was, I am unsure what IIS could do as the users are not known in advance (new registrations etc).

Due to MVC routing, it wont be possible for users to access other users directories by guessing usernames, however if you can guess a username AND imagename, then it does display. I am looking for ideas on preventing that from happening to minimise the chance of someone elses images becoming exposed to others.

I have tried an IgnoreRoute but this didn't work.

routes.IgnoreRoute("UserImages/{*pathInfo}");

Ideally I would have the UserImages directory cleared on logout but not everyone will use logout command. If they were cleared out there is a much smaller chance of something finding the combination of username and imagename before the files are removed.

4

1 回答 1

1

与其将缓存的图像作为 IIS 提供的静态内容存储在实际站点结构中,不如将图像存储在站点外部的路径中

这将确保没有未经授权的用户可以直接访问它们。

Controller然后,您可以通过(可能)操作来提供对这些图像的访问权限,该UserImagesController操作可以验证所请求的图像是当前用户可以访问的图像。

您的检查可能最终很简单,就像检查请求UserName的操作参数是否与您当前用户的UserName.

使用这种方法,您还可以控制这些图像的缓存标头、过期等。

于 2013-07-28T23:20:05.583 回答