I am working for a paranoid client. The image uploader I've written must be able to 'survive' multiple penetration tests from some hired guys. Just for some background information: The images are for profile pictures only.
So, what I've got. I've got a HTML form to upload files, and the form can only be accessed by logged in users. The login system is safe, there's no worrying in that. Every user gets an unique user id, which is what I use to identify different users.
Whenever a file gets uploaded, I do the following checks on it:
- The file must be larger than 128 bytes (stop ddossing)
- The file must be smaller than 100 kb (the pictures will be displayed as 64x64 anyway)
Both of those checks are done with $_FILES["fileToUpload"]["size"]
- The file's extension has to be '.png' (done with
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
) - The mime content must be "image/png" (done with
mime_content_type($_FILES["fileToUpload"]["tmp_name"])
) - The file will be renamed to
$current_user->ID.".png"
- All profile images are stored in /resources/img/profilepic/[userid].png
- The file is moved with
move_uploaded_file
- Loading of the images is done within
<img>
tags. The code that gets the complete sentence (including the tags) isrequire
'd in another .php file later.
So in short: The files are not named after the original but after [id].png. I haven't been able to find questions which address this too.
Is this bullet proof? Or is my current system just a nice challenge for someone willing to upload a web-shell? If there's a major vulnerability, how can I protect myself against it?