Search
Joe Pruitt - A Software Architect's take on Network Security
You are here: DevCentral > Weblogs

posted on Wednesday, November 09, 2005 2:38 PM

So, you've got yourself some info that you want to stash in a cookie. The problem is that cookie contents are stored in HTTP headers which can be snooped on by those out there you want to keep the contents away from.

Sure, you could encrypt your session with SSL. That would stop those sniffing on the wire, but the cookie is then stored on the clients disk in clear text.

So, you may ask, how easy is it to secure the contents of a cookie? We'll, thanks to BIG-IP v9.x, it's VERY easy. With a simple iRule, you can do so with a few strokes of the keyboard.

Here's a simple iRule that will do that for you. First at rule initialization, we'll generate a unique encryption key:

when RULE_INIT {
   # Generate Unique Key
   set ::key [AES::key]
}
Next, for a HTTP Response that contains the cookie (in this example, the name of the cookie is "MyCookie"), we'll encrypt it and replace the value with the encrypted value of the original.
when HTTP_RESPONSE {
   set decrypted [HTTP::cookie "MyCookie"]
   if { "" ne $decrypted } {
      # remove the original cookie, encrypt it, and then insert the encrypted value
      HTTP::cookie remove "MyCookie"
      set encrypted [b64encode [AES::encrypt $::key $decrypted]]
      HTTP::cookie insert name "MyCookie" value $encrypted
   }
}
Now, when the client makes a subsequent request, we'll check for the encrypted version of the cookie. If it exists, then decrypt it and replace the encrypted value with it's decrypted counterpart.
when HTTP_REQUEST {
   set encrypted [HTTP::cookie "MyCookie"]
   if { "" ne $encrypted } { 
      # remove encrypted cookie, decrypt it, and insert the decrypted value.
      HTTP::cookie remove "MyCookie"
      set decrypted [AES::decrypt $::key [b64decode $encrypted]]
      HTTP::cookie insert name "MyCookie" value $decrypted
   }
}
Pretty simple huh?

-Joe

[Listening to: Be Like That - 3 Doors Down - The Better Life (04:26)]

Posted In: iRules,

Feedback

11/4/2008 6:09 AM
Gravatar OK, so the cookie is encrypted, what do you really gain from it ? is it also signed with the ip ? I may not know what the internals of the cookie are, however I can still copy de value of the cookie to another browser and use it.
Diego Cassinera
11/4/2008 10:07 AM
Gravatar You gain the protection from a man-in-the-middle attack where a 3rd party was sniffing traffic and was able to replicate your login from their system by copying your cookie. By encrypting the cookie with the IP of the client connection, the would-be hacker would have to hack his connection to make it look like the TCP connection from his system was the same as yours which is very difficult to do. You are correct that this would work on any other browser on your current system but typically if a hacker has gained access to your operating system, you have more to worry about...

-Joe
Joe Pruitt
7/30/2009 1:53 AM
Gravatar thanks for the information.
Car News
7/19/2010 6:36 PM
Gravatar With love fragrance..............
uggs sale online

Let Me Know What You Think


Please use the form below if you have any comments, questions, or suggestions.

Title:
 
Name:
 
Email: (so we can show your gravatar)
Website:
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
 
Please add 5 and 1 and type the answer here:

Blog Stats

Posts:379
Comments:1067
Stories:1
Trackbacks:301
  

Article Categories

  iRules
  

Image Galleries

  

Joe's bookshelf: read

The Lost Gate
4 of 5 stars
This one started slow but I got really got into it about 1/3 of the way through. If you are an Ender's Game fan, you'll probably like this one as well.

goodreads.com


82,243 Members in 102 Countries and Growing!

Join DevCentral Today!

About DevCentral

DevCentral has been a successful, thriving community for many years. We have always strived to bring you the best technical documentation, discussion forums, blogs, media and much more that we can.

So dive in, get familiar with DevCentral. We hope you like it, we hope it makes your job easier, and lets you get that much more power out of the community. To learn more, make sure to check out the Getting Started section. And if you have any problems, or think something could be easier to use, drop us a line to let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback       or