473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Techniques for Making Cookies Secure

Is there a good article - or maybe a good chapter in a book - that someone
can recommend on the topic of how to make cookie handling secure?

I'm interested in common techniques for:

- encrypting the cookie

- verifying integrity of the cookie

- organization of different cookie types, and typical entities maintained in
each cookie type

- parsing the cookie on the server side to scan for any injection that a
hacker may have inserted

- attributes commonly stored in the cookie to maintain user identity and
state (e.g., public IP, private IP, machine name, login account name,
kerberos or other time-based ticket)

--
Will
Feb 3 '07 #1
3 3024
Will wrote:
Is there a good article - or maybe a good chapter in a book - that someone
can recommend on the topic of how to make cookie handling secure?

I'm interested in common techniques for:

- encrypting the cookie

- verifying integrity of the cookie

- organization of different cookie types, and typical entities maintained in
each cookie type

- parsing the cookie on the server side to scan for any injection that a
hacker may have inserted

- attributes commonly stored in the cookie to maintain user identity and
state (e.g., public IP, private IP, machine name, login account name,
kerberos or other time-based ticket)

I'll assume you've already looked up the wikipedia entry which goes on
quite nicely about security and privacy.

For encryption you can do a search on md5 javascript which at least will
point you in the right direction if you need anything more secure.

The cookie itself can have a "secure" setting and such a cookie will
only be transmitted between client and server if an encrypted connection
has been established between the web-server and the client.
Additionally, on the server side, the cookie can be designated a HTTP
cookie and will be invisible and unavailable to javascript.

NONE of these methods secures the cookie. As in on-line multi-player
games the cardinal rule is *NEVER, EVER* trust the client.

To that end, the only use of cookies you should consider is as a unique
client identifier which will let you match that client with your
server-side database record. You can encrypt the identifier or make it
as obscure as humanly possible of course and even then an HTTP cookie
would be an even better route. But storing any other data where you are
actively considering encryption and verifying integrity is a really,
really bad idea.

Here's the documentation on php's setcookie command (complete with
further instructions on http and secure: http://www.php.net/setcookie

And a public domain javascript function which will do much the same
(well except for http setting, that would be silly):

function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+'='+escape( value ) +
( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) +
//expires.toGMTString()
( ( path ) ? ';path=' + path : '' ) +
( ( domain ) ? ';domain=' + domain : '' ) +
( ( secure ) ? ';secure' : '' );
}
And finally, the rfc for cookies can be found here:
http://www.faqs.org/rfcs/rfc2109.html

Hope that helps you out a bit.

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Feb 4 '07 #2
In comp.lang.javascript message <lB***************@newssvr19.news.prodig
y.net>, Sat, 3 Feb 2007 23:57:39, pcx99 <x@x.composted:
>
And a public domain javascript function which will do much the same
(well except for http setting, that would be silly):

function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
There should be better code available.

// today.setTime( today.getTime() ); // pointless

var D = new Date()
D.setDate(D.getDate() + expires)

then use D in the write statement. That will give one civil day even
over Summer Time changes.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Feb 4 '07 #3
Dr J R Stockton wrote:
In comp.lang.javascript message <lB***************@newssvr19.news.prodig
y.net>, Sat, 3 Feb 2007 23:57:39, pcx99 <x@x.composted:
>And a public domain javascript function which will do much the same
(well except for http setting, that would be silly):

function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

There should be better code available.

// today.setTime( today.getTime() ); // pointless

Heh yea, that does seem to be more than a bit odd. I clipped this
function from: http://www.dustindiaz.com/top-ten-javascript/ an
otherwise excellent reference. My guess is Dustin just clipped this as
well because it was public domain.
>
var D = new Date()
D.setDate(D.getDate() + expires)

then use D in the write statement. That will give one civil day even
over Summer Time changes.
Much cleaner.

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Feb 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt Smith | last post by:
Please oh please oh please can someone with some P3P knowledge help me out? I'm aware that this isn't strictly an ASP or IIS issue but the SSL groups listed on my news server appear abandoned and...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
4
by: Greg Livengood | last post by:
I need to test my ASP.net web application for the case that the client browser doesn't support cookies or for the case that cookies are turned off on the client browswer. What is odd is that when...
2
by: pv_kannan | last post by:
I recently found out that my authentication cookies are not expiring even though I have set the persist property to false. As a result, users are able to access the secure websites with indifferent...
2
by: jacksu | last post by:
I have one application in two servers, two servers returns the same cookie but with some elmenet in different order, Set-cookie: a=abc; Path=/; Domain=.abc.com; Secure another one is...
4
by: oopaevah | last post by:
What are the pitfalls of passing a token in the url once a user is logged on so I can remember who they are? I can easily implement this by adding &token=abcdefghijklmnop123 to each internal...
3
by: Inny | last post by:
I want To offer a login Option, two Checkboxs, 1 labeled 'normal' the other labeled 'Forever'. I want to assign the check boxes to switch between the cookie script below (normal) and An altered...
3
by: =?Utf-8?B?QW5keQ==?= | last post by:
Hi, I'm having issues with what I'm *sure* is a simple problem. Basically having a problem passing a cookie between two sites. On Site A you sign in, and create a cookie with the users ID in it...
3
by: krg | last post by:
Hi, I started writing this blog some time back and it would be great if I could get an audience here and even better if we could have a conversation about developments possible on the techniques I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.