Coder Profile - Show off your skills, get a coder profile.
 
 
 
How to prevent cookie stealers
Security
In this article, I will be giving a few tips on how to protect against cookie stealers.


Flash Cookie Stealers
--------
Some sites allow flash to be embedded, and if your site isn't secure, people can use javascript within the flash to steal cookies. In case you didn't know, the simple way of embedding a flash onto an html page is:

<embed src="somefile.swf" width="somewidth" height="someheight"></embed>

But, people can easily put javascript in their flash to either steal cookies, or annoy the user. So to simply not allow javascript within the flash, just add allowscriptaccess="never" to the embed tag. Example:

<embed src="somefile.swf" width="somewidth" height="someheight" allowscriptaccess="never"></embed>

And that way, all javascript within the flash will be blocked. But, if you have a site that allows users to upload .swf's directly to your site, they can still use javascript even with allowscriptaccess="never". What they could do is find the exact url to their uploaded .swf on your server, and spread the exact url around instead of the embedded flash. Well, not to fear, there is still a way to stop people from stealing cookies, but unfortunately, there is no way of stopping people from using annoying javascript in their uploaded flash. So anyways, I'm assuming you use php to create your cookies. Well, as of php version 5.2, there is a new parameter to the setcookie() function. In this parameter, you can specify whether or not the cookie can only be accessed through the HTTP protocol. If set to TRUE, all javascript attempts to access the cookie will fail. Incase you are wondering, to access a cookie with javascript, you do document.cookie.


XSS (Cross-site scripting) Cookie Stealers
--------
If you have a place on your site where people can submit or print text onto a page, make sure it is secure first. If it isn't, people can submit any kind of html or javascript to take control of the page. So, I will go over two php functions that can stop all html and javascript from being outputted on a page.

The first function is the strip_tags() function. With this function, you can strip any kind of tag that is being outputted. The only bad thing is it would strip non-html tags such as <lol>. Anyways, an example is below:

<?php
$text="Hello <b>World</b>";
echo strip_tags($text); //Outputs Hello World, without "World" being bold.
?>

So, applying that function around all user submitted text will ensure that your safe.


The second function is htmlentities(). I prefer this over the strip_tags() function, because it keeps everything, but doesn't allow html. It will simply turn all special characters in html to their entity form. An example:

<?php
$text="Hello <b>World</b>";
echo htmlentities($text); //Outputs Hello <b>World</b> because the < and > have been converted to their entity form.
?>
--------
Well, that concludes my mini tutorial on how to protect yourself from cookie stealers. I hope you learned something!


Posted By SpamBurger
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
 
Izzmo     Posted 232 Days Ago
 
 
Ya, it was brief, as people use XSS a lot. Not only htmlspecialchars, but validate
every single postback to make sure it's what you want. Doing this alone would
keep out the newbie XSS'ers.
 
VBAssassin     Posted 241 Days Ago
 
 
Hi ya,

Nice article, especially on the flash side of things explaining how it can steal
cookies. Felt it was a little brief on the PHP side of things though. For example you
missed out the use of the function htmlspecialchars() which is very useful for
escaping html tags if you do not want to remove them completely. While htmlentities
would also work it also escapes many more characters resulting in larger strings.

Overall i enjoyed reading it and look forward to your future articles.

Kind regards,
Scott
Page 1 of 1
More Articles By This Author
How to prevent cookie stealers
Recently Posted "Security" Articles
Basic Steganography
How to prevent cookie stealers
Null Byte Poison - How it works...
Secure Hashing
DIC - Sick of XOR? Here's a better idea.
True Security
Polyalphabetic substitution
Shift cipher
About Computer Viruses
Creating Secure Passwords
Recently Rated "Security" Articles
Null Byte Poison - How it works...
Basic Steganography
Creating Secure Passwords
About Computer Viruses
How to prevent cookie stealers
Secure Hashing
True Security
DIC - Sick of XOR? Here's a better idea.
Polyalphabetic substitution
Shift cipher
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Internet & Web Sites (1)
Life In General (2)
Operating Systems (3)
Other (2)
Programming (48)
Security (10)
Software Development (5)
Web Development (15)
search Search Inside
Security
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved