views:

308

answers:

5

I am using asp.net and my users need to upload private pictures to my server. This pictures cannot in anyway get spread so I need to protect them in some way. What is the easiest way to protect them from public use so only the authorized user can reach them?

Thanks!

+4  A: 

Use an asp.net handler instead of serving the images directly. This way you can have a granular control over authorization when serving the image.

Also, keep the images out of public folders, so users can't download them i.e. store them outside the folder for the web site or on a database.

Check this for a bit more info on handlers: http://www.wrox.com/WileyCDA/Section/id-291916.html. Both samples serve images, but they are focused on pretty specific scenarios. As you can see in those, you have complete control over the logic you implement in there, so you could check if the user requesting the image is authorized to download the specified image.

eglasius
A: 

Handler, I'm a newbie.. Whats that?

Look for "ASP.Net handler" or IHttpHandler on the net. That's what Freddy is referring to. http://www.agileprogrammer.com/dotnetguy/articles/IntroToHandlers.aspx
f3lix
Welcome martin, please use comments to ask for details.
Canavar
For comments he needs at least 50 Rep.
Burkhard
@martin added a link with 2 image handler implementations - they handle specific scenarios, but you can understand the concept from there and roll your own.
eglasius
@Burkhard I think anyone can leave comments to answers on their own question. At any rate, Martin, creating an 'answer' should not be used to ask for further info. Perhaps edit your original question?
thomasrutter
+8  A: 
  • Would you like the public to be able to view the images, but make it a tiny bit harder to download them?

    If so, you could look into the way Flickr does it, for anybody that opts out of allowing downloads. They lay a transparent GIF image over the top of the real image, to prevent downloading the image by right-clicking it.

    It is still pretty easy to download them, because as a rule of thumb anything the public can view, they can save to their hard disk. I therefore see attempts to prevent downloads of publicly viewable material as fairly futile; and mostly just a violation of usability. Perhaps you should think about legal avenues rather than obfuscation; state your copyright notice and any license you want clearly and be prepared to pursue anyone who steals them.

  • Would you like to allow people to view and download images from your site, but not to hotlink them from other sites?

    If so, the key is to detect the referer (sic) header sent, and deny the image if the referer is not a match. Note that if the referer is blank, you have to trust it by default, as a lot of people's browsers legitmately don't send a referer even when viewing on your own page.

    This is usually done in a server directive; if you were using Apache, you would do it in an .htaccess file using mod_rewrite directives. If you are on IIS, however, then I'm less clear, though these instructions may or may not help.

  • Or, do you want to prevent the public from being able to view them at all? If so, you would just need to use access control on whatever server you are using - here's access control instructions for IIS.

thomasrutter
@thomasrutter I agree that you can't do much to prevent an authorized user from saving the image and spreading it outside your system. This doesn't mean you are free to let anyone unauthorized to download the user's images directly from the system.
eglasius
@Freddy Rios, if blocking unauthorized people is what is desired, then that's an access control issue - you need to make it so unauthorized people cannot access the pictures at all. But to allow people to view them, there's no physical way to prevent them saving or copying them, only legal ways.
thomasrutter
@thomasrutter agreed, re-read the question :) --- I think it is exactly about that (authorization), note that you can perfectly authorize images on a per user/group basis
eglasius
A: 

Hi again!

Thanks for your answers, what I want to do is make sure that just the user that uploaded the photos will be able to reach them. The user that uploaded the photos should be able to download them or whatever he wants. Can I just put the photos in a directory over the actual website, will this be enough so noone can browse the photos?

+1  A: 

You might want to look at this question for some ideas: secure images against static requests

MikeJ