views:

51

answers:

2

I am allowing people to upload their project files, I've tightened my security but I just need to get to the simple point. How can I stop execution of any files in the subdirectories they're uploading too?

I'm thinking .htaccess but I'd need to generate one for each new subdirectory (I think), would I need to scrap my current code and use a .php file to send headers to force DL on the file instead of running?

What do you think is an easy and safe solution for this? It just uploads to a subdirectory like uploads/~foo/bar.html or something, it looks nice that way so it'd be nice if it can stay like that format.

A: 

Put this in uploads/.htaccess:

RemoveType application/x-httpd-php .php

This will work for all subfolders. Also make sure you don't parse .htaccess in the users folders. This can be done by AllowOverride None in the main server config, or it can be done by not allowing uploads of .htaccess files in the first place.

Emil Vikström
Thank you alot, I thought and did disallow .htaccess from being uploaded, but the allowoverride would add the safetly I'd like.Thank you so much!
John S.
Actually, how would I allow this to not effect upload.php I got in there? lol
John S.
Actually don't worry! I got a directory back one that has nothing in it, I'll place the scripts there.
John S.
So then what if the file name is `../../backdoor.php` ? If you do this alone, it can be bypassed. You also have to check the file name, its just a variable in an HTTP request that can be any value.
Rook
A: 

If for example these uploaded files are in the directory "uploads" and subdirectories of it:

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} \.php [NC]
RewriteCond %{REQUEST_URI} \/uploads\/
RewriteRule ^(.*)$ index.php [F,L]
Radek Suski