| Posted in Website Programming » Security - Tuesday 17th July 2007 at 5:54PM | |
|
Brad Joined April 2007 |
What are the highest measures you would take to ensure the safety of your website/web app? __________________________________ |
- Subscribe to this
- Search this thread
- Rate this thread
Security Measures
Replies (9)
| Replied - Wednesday 25th July 2007 at 6:13PM [Post Link] | |
|
Will Joined October 2005 |
I use a data handling class and undergo a standard procedure every time I take form data out and use it in a database. It takes care of security, empty fields and error checking, and it also lets you load everything into a separate array, so it sort of helps coding as well. For example, what would you rather?
$_POST['fieldname'];Of course, you're going to have to run a few things like: $f = $data->sanitize($_POST); // [bool recursive, bool error checking]]But it beats manual stuff. As for file uploads, I've only dealt with image and MP3 uploads before, and the latter isn't even considered a security threat (iirc) It helps to know how people can exploit each format before trying to address these issues. I do a series of checks - for example, checking the extension of the file against the mime type. If there's a conflict, there might be a problem. Also, running an image function like getimagesize() on an uploaded file to test if it really is an image is another check. Something like:list($x, $y) = getimagesize($imagefile);You could also be really hardcore and just convert or rewrite the data with GD in PHP. Doing this will remove any comments inside the GIF or JPEG files, perhaps by converting them to PNG. Another advantage of this is the lower filesize, even if there's a small tradeoff between CPU time and disk space.. Anyway, if I had the money, I'd definitely hire a whitehat hacker. I'd never hire grey/blackhats, like Microsoft do. __________________________________ |
| Replied - Thursday 26th July 2007 at 4:08AM [Post Link] | |
|
Ed Joined July 2007 |
The key to security is to know the vulnerabilities. It is also a good idea to keep an eye on http://www.securityfocus.com bugtraq for any vulnerabilities that are likely to effect you or the server the script would be running on.
It's paramount to never trust user input, and to handle it according to datatype, so if you want an integer, force it to be an integer, by checking if the datatype is an integer, or by type-casting it. One lesser known vulnerability that effects uploads are multiple extensions. If the mime type is not supported (in apache at least) then it falls back to the secondary extension. For example 'foo.php.rar' would parse as PHP when uploaded, so you need to watch out for that. Not sure I can see the point in verifying the MIME type against the extension as MIME types are extremely easy to spoof so it really offers no protection. I'm always aware of security for every line of code I write, so that's the only way I need protect myself. If you're writing insecure code, it mainly comes down to incompetence. __________________________________ |
| Replied - Sunday 29th July 2007 at 11:49PM [Post Link] | |
|
adam2z Joined October 2005 |
[QUOTE] Ed said (26th July @ 3:08am):
or say 'sp.php.jpg'... __________________________________ |
| Replied - Monday 30th July 2007 at 2:59AM [Post Link] | |
|
Ed Joined July 2007 |
[QUOTE] adam2z said (29th July @ 22:49pm):
No, because '.jpg' has a recognized mime type for most webservers (image/jpeg), so it would end up being an erroneous image rather than parsing php, unless the web server was explicitly told to handle .jpg in this way. __________________________________ |
| Replied - Monday 30th July 2007 at 1:50PM [Post Link] | |
|
Will Joined October 2005 |
In which case if you still wanted to do it, you'd have to figure out an odd extension like:
sp.php.pp2 __________________________________ |
| Replied - Monday 30th July 2007 at 3:09PM [Post Link] | |
|
Brad Joined April 2007 |
Wow, this Security Focus (http://www.securityfocus.com) website certainly does look useful.
/me bookmarks Thanks Ed. __________________________________ |
| Replied - Monday 30th July 2007 at 10:48PM [Post Link] | |
|
adam2z Joined October 2005 |
an attempt was made to hack www.imageho.st with a valid image-script combination called sp.php.jpg
it was rendered in the php engine (well not for imageho.st because i was running some tricksy php <3). it also ran on alec's and tubby's (hehe tubgirl). however, the html was only displayed in firefox, not ie which showed the image it was contained in. __________________________________ |
| Replied - Sunday 9th September 2007 at 5:20PM [Post Link] | |
|
Matt Joined July 2007 |
[QUOTE] (Unsourced): adam2z said (29th July @ 22:49pm): [quote=Ed;1185419334] or say 'sp.php.jpg'... ahaha, youre consided a living legend between me and tubby for that __________________________________ |
| Replied - Sunday 9th September 2007 at 6:52PM [Post Link] | |
|
Tubby Joined July 2007 |
yes that was quite a giggle.
__________________________________ |