Hi, Guest ~ Login or Register

Security Measures

Posted in Website Programming » Security - Tuesday 17th July 2007 at 5:54PM

Brad
Member

User Avatar

Joined April 2007
Posts: 85

What are the highest measures you would take to ensure the safety of your website/web app?

Some people actually hire hackers to come in and try to hack the site, and then tell the developers how it was hacked and how to prevent it. While this is risky, it's also a good method of breaking your site down to the most secure state it could possibly be.

I was just wondering what measures you web developers take?

__________________________________
Brad Purchase
Programmer, Designer, and Apple Tart.

 

Replies (9)

Replied - Wednesday 25th July 2007 at 6:13PM [Post Link]

Will
Administrator

User Avatar

Joined October 2005
Posts: 128

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'];
# or #
$f['fieldname'];

Of course, you're going to have to run a few things like:
$f = $data->sanitize($_POST); // [bool recursive, bool error checking]]
$errors = $data->checkSanitizeEmptyKeys($f); // an extra array param can be used for exceptions

if($errors == '') {
// successful form data
}
else {
echo $errors;
}


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);
if(!is_integer($x)) {
$errors[] = 'This doesn't appear to be an image.';
}


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.

__________________________________
Will Morgan
Freelance Web Developer
Next feature: How to fit 25 hours into a day!

 
Replied - Thursday 26th July 2007 at 4:08AM [Post Link]

Ed
Member

User Avatar

Joined July 2007
Posts: 14

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
Member

User Avatar

Joined October 2005
Posts: 113

[QUOTE] Ed said (26th July @ 3:08am):


One lesser known vulnerability that effects uploads are double extensions. Ff 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.



or say 'sp.php.jpg'...

__________________________________

 
Replied - Monday 30th July 2007 at 2:59AM [Post Link]

Ed
Member

User Avatar

Joined July 2007
Posts: 14

[QUOTE] adam2z said (29th July @ 22:49pm):


or say 'sp.php.jpg'...



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
Administrator

User Avatar

Joined October 2005
Posts: 128

In which case if you still wanted to do it, you'd have to figure out an odd extension like:

sp.php.pp2

__________________________________
Will Morgan
Freelance Web Developer
Next feature: How to fit 25 hours into a day!

 
Replied - Monday 30th July 2007 at 3:09PM [Post Link]

Brad
Member

User Avatar

Joined April 2007
Posts: 85

Wow, this Security Focus (http://www.securityfocus.com) website certainly does look useful.

/me bookmarks

Thanks Ed.

__________________________________
Brad Purchase
Programmer, Designer, and Apple Tart.

 
Replied - Monday 30th July 2007 at 10:48PM [Post Link]

adam2z
Member

User Avatar

Joined October 2005
Posts: 113

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
Member

User Avatar

Joined July 2007
Posts: 5

[QUOTE] (Unsourced):

adam2z said (29th July @ 22:49pm):

[quote=Ed;1185419334]
One lesser known vulnerability that effects uploads are double extensions. Ff 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.



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
Member

User Avatar

Joined July 2007
Posts: 47

yes that was quite a giggle.

__________________________________
All posts are my own opinion.