RobertP Posted January 29, 2012 Share Posted January 29, 2012 I have created a custom cms engine from scratch. Now i wish to add a file manager, how do you think i should go about this. Any security issues i need to look into / add? Any feedback appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/ Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2012 Share Posted January 30, 2012 In case you aren't aware, the tutorial you've linked to in your sig is about 9 years out of date. Actually, pretty much everything on that site is outdated. Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312372 Share on other sites More sharing options...
RobertP Posted January 30, 2012 Author Share Posted January 30, 2012 In case you aren't aware, the tutorial you've linked to in your sig is about 9 years out of date. Actually, pretty much everything on that site is outdated. it helped me a few years ago, and can still help othersĀ Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312410 Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2012 Share Posted January 30, 2012 Deprecated code doesn't help anyone. Well, unless your goal is to write code that will suddenly stop working the next time php is upgraded on your server. In that case it's fine. Ā Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312413 Share on other sites More sharing options...
RobertP Posted January 30, 2012 Author Share Posted January 30, 2012 lets try to get on-topic?? Ā is it possible to execute php/js code with an image extension? Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312445 Share on other sites More sharing options...
scootstah Posted January 30, 2012 Share Posted January 30, 2012 is it possible to execute php/js code with an image extension? Ā PHP: No, unless you explicitly tell Apache to parse image files as PHP. Ā JS: Possibly, in older browsers. Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312468 Share on other sites More sharing options...
thehippy Posted January 30, 2012 Share Posted January 30, 2012 The 'name' and 'type' attributes from $_FILES are provided from the client, so you'll need to treat those as user input and filter/validate them.Ā I would say that common/safe practice would be to ignore them both and use your own naming and do some detection on the type.Ā The 'name' attribute can be a bit nefarious, the client could provide '../../etc/passwd' as the name for instance and that's definitely not a file you want to write to.Ā And of course using some kind of antivirus on the server to scan incoming files is common sense.Ā Microsoft in particular has had some buffer overflow issues with their image libraries and an AV scanner should detect those, not something you want to be redistributing from your site. Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312494 Share on other sites More sharing options...
RobertP Posted January 31, 2012 Author Share Posted January 31, 2012 about scanning the file, and php application that can help, or do i need something external; and if external, cross-platform friendly? Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312829 Share on other sites More sharing options...
RobertP Posted January 31, 2012 Author Share Posted January 31, 2012 how reliable are these functions? Ā function getFileExt($file){ $vars = explode('.',$file); return $vars[count($vars)-1]; } function getFileType($file){ $handler = new finfo; return $handler->file($file,FILEINFO_MIME_TYPE); } Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312846 Share on other sites More sharing options...
scootstah Posted January 31, 2012 Share Posted January 31, 2012 You can get the file extension like this: echo pathinfo($filename, PATHINFO_EXTENSION); Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312858 Share on other sites More sharing options...
RobertP Posted January 31, 2012 Author Share Posted January 31, 2012 thank you for the tip. Ā how do i scan files for viruses and other malware? Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312866 Share on other sites More sharing options...
thehippy Posted January 31, 2012 Share Posted January 31, 2012 Invoke external command line AV scanner, clamav for instance or one of the many out there, commercial or not they usually have a command line interface.Ā There are a couple of bindings I know for PHP but those are maintained poorly/not updated, so its best just to hand it off to the CLI. Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312909 Share on other sites More sharing options...
scootstah Posted January 31, 2012 Share Posted January 31, 2012 Keep in mind that if this is a CMS to be distributed publicly, an AV scanner is probably not going to work out. Number 1 that's probably going to consume a lot of resources and shared hosts get grumpy about that, and Number 2 unless you build an AV to include with your project, you can't guarantee every hosting setup has an AV that works in the same way. Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1312997 Share on other sites More sharing options...
thehippy Posted January 31, 2012 Share Posted January 31, 2012 If you knowingly do not put any protections in place to verify the threat of the files, it would make your site a distributor of viruses and depending on your location and the location of your users can be a criminal offence, be sure to consult your lawyer to come up with a licence agreement to mitigate your liability and warn your users of the risk. Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1313145 Share on other sites More sharing options...
RobertP Posted February 1, 2012 Author Share Posted February 1, 2012 thank you all very much, i have decided to create a av-scan module via the cli configurable of course Quote Link to comment https://forums.phpfreaks.com/topic/256006-file-uploads/#findComment-1313322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.