<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: How do I keep sneaky website users from accessing files directly?</title>
	<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly/</link>
	<description>Comments on Ask MetaFilter post How do I keep sneaky website users from accessing files directly?</description>
	<pubDate>Mon, 06 Apr 2009 07:15:29 -0800</pubDate>
	<lastBuildDate>Mon, 06 Apr 2009 07:15:29 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: How do I keep sneaky website users from accessing files directly?</title>
		<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly</link>	
		<description>How do I keep sneaky website users from accessing files directly? &lt;br /&gt;&lt;br /&gt; I have a site (apache, php, mysql) where users can purchase podcast videos and mp3s. When the user brings up a video page, it checks (via php/mysql) to see if he/she is allowed to view that video. I&apos;ve had a problem, however, with users viewing the page source and sharing the url of the video file they find there with others. Can I (a) obscure the url using javascript or something so they can&apos;t see the actual filename or (b) do something server-side to prevent direct access of the files or (c) something else?</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2009:site.118725</guid>
		<pubDate>Mon, 06 Apr 2009 07:12:51 -0800</pubDate>
		<dc:creator>jpoulos</dc:creator>
		
			<category>apache</category>
		
			<category>php</category>
		
			<category>mysql</category>
		
	</item> <item>
		<title>By: larsks</title>
		<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly#1700566</link>	
		<description>Your problem is that you have the files inside your document root where they are accessible as static content.  You need to move them outside of your document root and mediate access to them through a CGI script or similar.  That is, the *script* needs to be responsible for reading content from the files and passing it back to the client -- this means that you can always check whether or not the user is authorized.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.118725-1700566</guid>
		<pubDate>Mon, 06 Apr 2009 07:15:29 -0800</pubDate>
		<dc:creator>larsks</dc:creator>
	</item><item>
		<title>By: le morte de bea arthur</title>
		<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly#1700578</link>	
		<description>Seconding larsks&lt;br&gt;
&lt;br&gt;
Your best best is probably to store the files outside the web root. Then write a PHP script using the &lt;strong&gt;readfile&lt;/strong&gt; function to read the file and output it.&lt;br&gt;
&lt;br&gt;
Then, rather than putting a link to your video of mp3 in your html, you can put a link to the php script instead, which can contain whatever validation you need, and can even output a different file if users are not authorised. One extra thing you&apos;ll need is ensure that you add the appropriate headers (including mime type) to the file your script is &apos;impersonating&apos;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.118725-1700578</guid>
		<pubDate>Mon, 06 Apr 2009 07:25:20 -0800</pubDate>
		<dc:creator>le morte de bea arthur</dc:creator>
	</item><item>
		<title>By: cmiller</title>
		<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly#1700617</link>	
		<description>Yep, if you&apos;re not using HTTP authentication, then you need a program to check auth and then spoon-feed them the request results.  &lt;br&gt;
&lt;br&gt;
Be sure to set the correct MIME type!  Oh, and if it&apos;s supposedly downloadable, you may have some truly terrible I-E ugliness to work around.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.118725-1700617</guid>
		<pubDate>Mon, 06 Apr 2009 07:52:52 -0800</pubDate>
		<dc:creator>cmiller</dc:creator>
	</item><item>
		<title>By: ook</title>
		<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly#1700673</link>	
		<description>&lt;i&gt;obscure the url using javascript or something so they can&apos;t see the actual filename&lt;/i&gt;&lt;br&gt;
This will only block the most casual of users; obfuscated javascript can easily be unobfuscated by just copying your script and running it against the scrambled name to see the result. (Or they could just bypass it entirely by watching their outgoing traffic to see the filename instead of viewing source.)&lt;br&gt;
&lt;br&gt;
The technique suggested by larsks, le morte, and cmiller is the best one.  Another (simpler but imperfect) strategy is to frequently randomize the filename, and/or to use a unique filename per user (which doesn&apos;t prevent sharing, but lets you know which of your users is doing it...)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.118725-1700673</guid>
		<pubDate>Mon, 06 Apr 2009 08:29:30 -0800</pubDate>
		<dc:creator>ook</dc:creator>
	</item><item>
		<title>By: jpoulos</title>
		<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly#1700872</link>	
		<description>Thanks, all. You&apos;ve pointed me in the right direction.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.118725-1700872</guid>
		<pubDate>Mon, 06 Apr 2009 10:56:42 -0800</pubDate>
		<dc:creator>jpoulos</dc:creator>
	</item><item>
		<title>By: MesoFilter</title>
		<link>http://ask.metafilter.com/118725/How-do-I-keep-sneaky-website-users-from-accessing-files-directly#1701002</link>	
		<description>Short term you can set up an .htaccess file which will require that in order to get a file from your domain, the referrer (the browser tells the site where it just came from) has to be on your domain.&lt;br&gt;
&lt;br&gt;
Google for &quot;htaccess&quot; and &quot;referrer checking.&quot;&lt;br&gt;
&lt;br&gt;
This isn&apos;t a long-term solution because it can be spoofed &amp;amp; it&apos;s not really secure, but for simple friends-passing-links-on-to-friends, it should be fine.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.118725-1701002</guid>
		<pubDate>Mon, 06 Apr 2009 11:48:21 -0800</pubDate>
		<dc:creator>MesoFilter</dc:creator>
	</item>
	</channel>
</rss>
