Reputation: 23
I want to allow my users to upload .php
files to the server, but also want to make sure the files are harmless to my application.
Any suggestions?
Thank you.
Upvotes: 2
Views: 450
Reputation: 3930
Option 1: Store them with a different filename and store the original filename as part of the metadata, e.g. in a database table.
Option 2: Disable script execution on the uploads directory.
Option 3: Rename them to .phps (an accepted extension for the display of raw PHP)
Upvotes: 1
Reputation: 22638
Make the upload directory separate, write-only and not visible from the internet (this will prevent them accessing their own script after uploading).
You can then moderate new scripts and do as you see fit.
Upvotes: 0
Reputation: 91963
A couple of solutions:
Upvotes: 1
Reputation: 149704
I recommend the ‘disable script execution in the uploads directory’ approach. This is the only solution that’s completely safe.
Just add this rule to the .htaccess
file inside the uploads directory:
php_value engine off
Upvotes: 6
Reputation: 449613
Just don't execute them, that's enough.
Make sure that your application doesn't run or include user-uploaded files at any point (e.g. by using a GET parameter to include
a file without any sanitation).
Also make sure the uploaded files are not accessible from outside with the .php
extension.
In a normal, halfway properly coded workflow, uploaded .php files do not pose a security risk no matter what code they contain.
Upvotes: 0