<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech Blog &#187; data protection</title>
	<atom:link href="http://assanka.net/content/tech/tag/data-protection/feed/" rel="self" type="application/rss+xml" />
	<link>http://assanka.net/content/tech</link>
	<description>Just another Arb-assk2009003.turmeric.assanka.com Blogs weblog</description>
	<lastBuildDate>Mon, 29 Aug 2011 19:00:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Personal data in cookies</title>
		<link>http://assanka.net/content/tech/2009/09/01/personal-data-in-cookies/</link>
		<comments>http://assanka.net/content/tech/2009/09/01/personal-data-in-cookies/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:12:40 +0000</pubDate>
		<dc:creator>Andrew Betts</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[data protection]]></category>
		<category><![CDATA[privacy]]></category>

		<guid isPermaLink="false">http://assanka.net/content/tech/?p=9</guid>
		<description><![CDATA[Personal data in cookies is bad.  I accepted this for quite some time, until I actually stopped to think about it, and realised how much simpler our scaling would be if we could store a lot more state information in cookies.]]></description>
			<content:encoded><![CDATA[<p>Personal data in cookies is bad.  I accepted this for quite some time, until I actually stopped to think about it, and realised how much simpler our scaling would be if we could store a lot more state information in cookies.</p>
<p>So&#8230; conventional wisdom.  This is bad:</p>
<pre class="brush: plain;">
myCookie=Andrew,andrew@trib.tv,123456,TE51 7NG,4,2009-05-22 17:43:06,138cb381a04dba00340ab450deea934;
</pre>
<p>This imaginary cookie contains my display name, email address, user identifier, postcode, user level, cookie generation time, and security signature.</p>
<p>In my experience the first argument people have against the data I have in my cookie is that &#8216;the user could just change it!  You&#8217;ve got their permissions level in there and everything.  Are you mad!?&#8217;.</p>
<h2>The &#8216;user could just change it&#8217; argument</h2>
<p>Yes, they could.  So in order to solve this problem you only need to make it impossible for a user to write a legitimate cookie value, or edit a cookie such that it remains legitimate.  This is trivially simple to do and validate, much more so than implementing a scalable session store at the server end.</p>
<p>All you do is include, within your cookie, two additional items &#8211; the generation time of the cookie, and a signature string.  The signature string is the result of running the rest of the cookie (excluding the signature), AND a constant value NOT included in the cookie, through a hashing algorithm, such as md5, crc32 or sha1 (use sha1 for preference).</p>
<p>Here&#8217;s an example, using the cookie above.  The constant value not included in the cookie (normally a string of gibberish) will for our purposes be &#8216;password&#8217; (obviously you should use something a lot more random than that).  Sticking all the parameters of the cookie together, and adding the super-secure, super secret constant on the end, we get:</p>
<pre class="brush: plain;">
Andrewandrew@trib.tv123456TE51 7NG42009-05-22 17:43:06password
</pre>
<p>Then we run this through our hashing algorithm of choice, and end up with:</p>
<pre class="brush: plain;">
138cb381a04dba00340ab450deea934
</pre>
<p>Which we pop on the end of the cookie before it is sent to the user in a Set-Cookie header.  When that cookie is then received in a subsequent request (to a different server), the server only needs to know the super-secret constant and recalculate the hash to be able to verify that whoever wrote the cookie ALSO knows the super secret constant.  The user doesn&#8217;t know it, so the user can&#8217;t write a cookie that we&#8217;re going to believe.  No matter how much the user wants to get to user level 10, they&#8217;re just gonna have to earn it.</p>
<p>But, wail the doubters, you can see all the data on the wire in plain text!</p>
<h2>The &#8216;you can see it on the wire&#8217; argument</h2>
<p>When you put together the web page your user has requested &#8211; your shopping cart or social network or Tom Jones fan page or whatever &#8211; you are probably going to print a nice friendly message in the top right of the page that says &#8216;Hello Andrew!&#8217; with links to exciting places such as &#8216;My Account&#8217;, &#8216;Preferences&#8217; and &#8216;Log out&#8217;.  When the user goes to the my account page, you&#8217;re going to include loads more details as well, like their email address, phone number, postcode, and so on.  And of course because your app has a ton of JavaScript making life easy for the user, you&#8217;ve probably got their email address in a JavaScript variable somewhere so you can prepopulate &#8216;email a friend&#8217; dialogue boxes and overlays.</p>
<p>So all the content that you object to including in a cookie, you are including in the HTML responses that you send back to the user.  If it&#8217;s OK in the response, why not allow it in the request?</p>
<p>There is a  possible sub argument here: using DNS cache poisoning an attacker could intercept a request more easily than they could intercept a response.  But if your site is at risk from attempts at DNS poisoning (which is a lot more difficult than it used to be), then you probably have bigger worries than just leaking some personal data.</p>
<h2>Conclusion</h2>
<p>In many cases, storing personal data in cookies is a great idea, and is not a privacy issue.  If you&#8217;re storing something that you&#8217;re not intending to use in JavaScript, and want to make it less readable (though not actually secure) you could easily obfuscate it, or make it actually secure using a cheap-to-decrypt symmetric encryption with a key known to all your servers, which still avoids the need to store the data in a server-side session store.</p>
]]></content:encoded>
			<wfw:commentRss>http://assanka.net/content/tech/2009/09/01/personal-data-in-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

