<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Cookie cunundrum</title>
	<atom:link href="http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/</link>
	<description>The personal blog of Jeffrey T. Darlington, creator of General Protection Fault</description>
	<lastBuildDate>Sat, 05 Dec 2009 02:07:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Jeff</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-169</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Wed, 05 Mar 2008 13:28:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-169</guid>
		<description>A signed (HMAC) SHA-256 hash to be precise, encoded with a modified Base64. Again, hopefully not giving too much away about the implementation, the hash is of rest of the cookie contents, scrambled in various ways, and salted with a number of unknown (to the end user) elements. The salt should prevent an attacker from trying various permutations of the raw data to fake the hash. It&#039;s a really good way of storing the data in the open and still preventing tampering. Of course, I was already using a separate constant as part of the salt, so pulling information from the &lt;code&gt;$_SERVER&lt;/code&gt; array was probably overkill and obviously introduced problems. Then again, sometimes good security is all about overkill. ;)

I&#039;ve since tested the modified code in Firefox 2, IE 6, Opera 9, and Safari 3(?), all for Windows. That should probably be enough to call it a success. I&#039;d still prefer to check it in IE 7 as well as a couple browsers in Linux, but it should be sufficient to move forward. Again, many thanks to all.</description>
		<content:encoded><![CDATA[<p>A signed (HMAC) SHA-256 hash to be precise, encoded with a modified Base64. Again, hopefully not giving too much away about the implementation, the hash is of rest of the cookie contents, scrambled in various ways, and salted with a number of unknown (to the end user) elements. The salt should prevent an attacker from trying various permutations of the raw data to fake the hash. It&#8217;s a really good way of storing the data in the open and still preventing tampering. Of course, I was already using a separate constant as part of the salt, so pulling information from the <code>$_SERVER</code> array was probably overkill and obviously introduced problems. Then again, sometimes good security is all about overkill. <img src='http://www.jeffdarlington.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I&#8217;ve since tested the modified code in Firefox 2, IE 6, Opera 9, and Safari 3(?), all for Windows. That should probably be enough to call it a success. I&#8217;d still prefer to check it in IE 7 as well as a couple browsers in Linux, but it should be sufficient to move forward. Again, many thanks to all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bugstomper</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-168</link>
		<dc:creator>bugstomper</dc:creator>
		<pubDate>Wed, 05 Mar 2008 05:35:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-168</guid>
		<description>Great news! I figured from the length and look of the field that was different that it was a SHA-256 hash of something and that it had to include a field that was sensitive to the http/https difference, but of course with no way to guess what you are hashing together there was no way to reverse engineer past that point.

Coincidentally, I&#039;m just starting a job for a client in which I&#039;m doing my first https form, and investigating this was a big help for me. Thanks Jeff! :-)</description>
		<content:encoded><![CDATA[<p>Great news! I figured from the length and look of the field that was different that it was a SHA-256 hash of something and that it had to include a field that was sensitive to the http/https difference, but of course with no way to guess what you are hashing together there was no way to reverse engineer past that point.</p>
<p>Coincidentally, I&#8217;m just starting a job for a client in which I&#8217;m doing my first https form, and investigating this was a big help for me. Thanks Jeff! <img src='http://www.jeffdarlington.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-167</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Wed, 05 Mar 2008 02:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-167</guid>
		<description>That did it, bugstomper. When I removed SERVER_SIGNATURE out of the mix, the hash became consistent across the HTTP/HTTPS barrier. I&#039;ve written a new cookie hashing algorithm that should be more stable when switching modes and was able to test it. I successfully set a cookie in HTTPS mode and then read it via HTTP, which is exactly what I wanted.

I&#039;ll need to modify my code to get this to work, which should be pretty simple as the function exists in a include file that gets called everywhere it&#039;s needed. The bad part is that this change will break all the existing Premium cookies, so subscribers will have to re-enable their browsers once it goes into effect. I&#039;ll make the changes, test them, then notify the subscribers before I make the change.

Thanks everyone for your assistance. You came up with a lot of good ideas for what went wrong and solutions to fix them. Unfortunately, my problem was somewhere between the chair and the keyboard. ;)</description>
		<content:encoded><![CDATA[<p>That did it, bugstomper. When I removed SERVER_SIGNATURE out of the mix, the hash became consistent across the HTTP/HTTPS barrier. I&#8217;ve written a new cookie hashing algorithm that should be more stable when switching modes and was able to test it. I successfully set a cookie in HTTPS mode and then read it via HTTP, which is exactly what I wanted.</p>
<p>I&#8217;ll need to modify my code to get this to work, which should be pretty simple as the function exists in a include file that gets called everywhere it&#8217;s needed. The bad part is that this change will break all the existing Premium cookies, so subscribers will have to re-enable their browsers once it goes into effect. I&#8217;ll make the changes, test them, then notify the subscribers before I make the change.</p>
<p>Thanks everyone for your assistance. You came up with a lot of good ideas for what went wrong and solutions to fix them. Unfortunately, my problem was somewhere between the chair and the keyboard. <img src='http://www.jeffdarlington.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-166</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 04 Mar 2008 21:26:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-166</guid>
		<description>Without giving away too many details, the Premium cookie contains a signed hash of several values to provide a validation check to prevent tampering or stealing of the cookie. However, the HTTP host value is part of that hash, so &quot;www.gpf-comics.com&quot; and &quot;gpf-comics.com&quot; would produce different hashes, and thus a cookie set by &quot;www.gpf-comics.com&quot; would not be valid if read by &quot;gpf-comics.com&quot;. So in that place the validation would indeed fail. It might be a short term problem to contend with, but as previously stated HTTP requests to &quot;gpf-comics.com&quot; will eventually automatically redirect to &quot;www.gpf-comics.com&quot;, so this shouldn&#039;t be an issue by the end of the month.

That, however, shouldn&#039;t be an issue with HTTP vs. HTTPS. The protocol isn&#039;t included in this host value, so it shouldn&#039;t matter whether you access it via &quot;www.gpf-comics.com&quot; or &quot;gpf-comics.com&quot;. For that matter, the SSL certificate is for &quot;www.gpf-comics.com&quot;, so you shouldn&#039;t even be able to access the site in HTTPS mode at &quot;gpf-comics.com&quot; without producing certificate errors.

&lt;strong&gt;&lt;em&gt;However,&lt;/em&gt;&lt;/strong&gt; also included in the hash as part of the &quot;hidden&quot; data (to add some entropy and salt to the value) is &lt;code&gt;$_SERVER[&#039;SERVER_SIGNATURE&#039;]&lt;/code&gt;, which &lt;em&gt;is&lt;/em&gt; different when accessed via HTTP or HTTPS (&quot;Port 80&quot; vs. &quot;Port 443&quot;). That would be just enough to throw the hash off and make it different. This &lt;em&gt;could&lt;/em&gt; be the magic bullet. I&#039;ll run a couple tests as soon as I can to see if that solves the problem and report back with the findings.</description>
		<content:encoded><![CDATA[<p>Without giving away too many details, the Premium cookie contains a signed hash of several values to provide a validation check to prevent tampering or stealing of the cookie. However, the HTTP host value is part of that hash, so &#8220;www.gpf-comics.com&#8221; and &#8220;gpf-comics.com&#8221; would produce different hashes, and thus a cookie set by &#8220;www.gpf-comics.com&#8221; would not be valid if read by &#8220;gpf-comics.com&#8221;. So in that place the validation would indeed fail. It might be a short term problem to contend with, but as previously stated HTTP requests to &#8220;gpf-comics.com&#8221; will eventually automatically redirect to &#8220;www.gpf-comics.com&#8221;, so this shouldn&#8217;t be an issue by the end of the month.</p>
<p>That, however, shouldn&#8217;t be an issue with HTTP vs. HTTPS. The protocol isn&#8217;t included in this host value, so it shouldn&#8217;t matter whether you access it via &#8220;www.gpf-comics.com&#8221; or &#8220;gpf-comics.com&#8221;. For that matter, the SSL certificate is for &#8220;www.gpf-comics.com&#8221;, so you shouldn&#8217;t even be able to access the site in HTTPS mode at &#8220;gpf-comics.com&#8221; without producing certificate errors.</p>
<p><strong><em>However,</em></strong> also included in the hash as part of the &#8220;hidden&#8221; data (to add some entropy and salt to the value) is <code>$_SERVER['SERVER_SIGNATURE']</code>, which <em>is</em> different when accessed via HTTP or HTTPS (&#8220;Port 80&#8243; vs. &#8220;Port 443&#8243;). That would be just enough to throw the hash off and make it different. This <em>could</em> be the magic bullet. I&#8217;ll run a couple tests as soon as I can to see if that solves the problem and report back with the findings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bugstomper</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-165</link>
		<dc:creator>bugstomper</dc:creator>
		<pubDate>Mon, 03 Mar 2008 18:54:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-165</guid>
		<description>I noticed the change in the GPF_NEWS cookie during my tests, and my results are with the new PHP version of the cookie. The http and https, both with and without &#039;www.&#039; all work fine and together with a single cookie for GPF_NEWS but not for Premium. So there is something you are doing differently between the two.

In Premium, the cookie domain is properly set to &#039;.gpf-comics.com&#039; and works with and without www, but the Content field of the cookie is being set differently with and without www, making the cookies different. I suspect that if you figure out why Premium&#039;s www and non-www cookie Content fields are different you will find out what the problem is with https.</description>
		<content:encoded><![CDATA[<p>I noticed the change in the GPF_NEWS cookie during my tests, and my results are with the new PHP version of the cookie. The http and https, both with and without &#8216;www.&#8217; all work fine and together with a single cookie for GPF_NEWS but not for Premium. So there is something you are doing differently between the two.</p>
<p>In Premium, the cookie domain is properly set to &#8216;.gpf-comics.com&#8217; and works with and without www, but the Content field of the cookie is being set differently with and without www, making the cookies different. I suspect that if you figure out why Premium&#8217;s www and non-www cookie Content fields are different you will find out what the problem is with https.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-164</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Mon, 03 Mar 2008 13:43:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-164</guid>
		<description>The problem with the News Notification cookie is that, depending on when it was last set, it was probably set by JavaScript (the only option available to me at Keenspot) where as Premium is being set via PHP. The News cookie is now also being set by PHP setcookie(). It looks like the News cookie properly updated with today&#039;s News update, according to a quick check of my cookies. As far as I know, there shouldn&#039;t be any difference between how the News and Premium cookies are now being set, so it might be interesting to try your test again, now that the News cookie is being set via PHP.

On &quot;gpf-comics.com&quot; vs. &quot;www.gpf-comics.com&quot;: I should point out that before long URLs at &quot;gpf-comics.com&quot; will eventually be redirected to the comparable URL at &quot;www.gpf-comics.com&quot;. This is primarily to help search engine optimization and such, and since I actually do have sub-domains the &quot;www.&quot; is still significant. Those redirects aren&#039;t in place yet because they will conflict with supporting the beta test domain, but once the beta test domain goes away and all its URLs redirect to &quot;www.gpf-comics.com&quot; URLs, the &quot;gpf-comics.com&quot; URLs will redirect as well.

That said, all the cookies should be set for &quot;.gpf-comics.com&quot;, meaning it should work for any sub-domain. Thus it &lt;em&gt;should&lt;/em&gt; work regardless of whether the &quot;www.&quot; is there or not. Unfortunately, I haven&#039;t had time to test this at all. I&#039;ll see what I can do, but now that we&#039;ve launched the site it will probably be a lower priority for a bit.</description>
		<content:encoded><![CDATA[<p>The problem with the News Notification cookie is that, depending on when it was last set, it was probably set by JavaScript (the only option available to me at Keenspot) where as Premium is being set via PHP. The News cookie is now also being set by PHP setcookie(). It looks like the News cookie properly updated with today&#8217;s News update, according to a quick check of my cookies. As far as I know, there shouldn&#8217;t be any difference between how the News and Premium cookies are now being set, so it might be interesting to try your test again, now that the News cookie is being set via PHP.</p>
<p>On &#8220;gpf-comics.com&#8221; vs. &#8220;www.gpf-comics.com&#8221;: I should point out that before long URLs at &#8220;gpf-comics.com&#8221; will eventually be redirected to the comparable URL at &#8220;www.gpf-comics.com&#8221;. This is primarily to help search engine optimization and such, and since I actually do have sub-domains the &#8220;www.&#8221; is still significant. Those redirects aren&#8217;t in place yet because they will conflict with supporting the beta test domain, but once the beta test domain goes away and all its URLs redirect to &#8220;www.gpf-comics.com&#8221; URLs, the &#8220;gpf-comics.com&#8221; URLs will redirect as well.</p>
<p>That said, all the cookies should be set for &#8220;.gpf-comics.com&#8221;, meaning it should work for any sub-domain. Thus it <em>should</em> work regardless of whether the &#8220;www.&#8221; is there or not. Unfortunately, I haven&#8217;t had time to test this at all. I&#8217;ll see what I can do, but now that we&#8217;ve launched the site it will probably be a lower priority for a bit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bugstomper</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-162</link>
		<dc:creator>bugstomper</dc:creator>
		<pubDate>Mon, 03 Mar 2008 12:26:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-162</guid>
		<description>More clues: I installed the editcookie addon in Firefox to make it easier to look at the cookies, and did the following experiment:

1. Go to http://gpf-comics.com/premium log in to my Premium account, click on the button to enable Premium in my browser, then look at and save the Content of the gpf_premium cookie.

2. Then go to http://www.gpf-comics.com/premium, notice that I am not logged in, login to my Premium account, click on the button to enable Premium in my browser, then look at and save the Content of the gpf_premium cookie. It is different than in step 1.

3. Repeat step 1. Verify that the content of the cookie is the same as in step 1.

4. Repeat step 2. Verify that the Content of the cooke is the same as in step 2.</description>
		<content:encoded><![CDATA[<p>More clues: I installed the editcookie addon in Firefox to make it easier to look at the cookies, and did the following experiment:</p>
<p>1. Go to <a href="http://gpf-comics.com/premium" rel="nofollow">http://gpf-comics.com/premium</a> log in to my Premium account, click on the button to enable Premium in my browser, then look at and save the Content of the gpf_premium cookie.</p>
<p>2. Then go to <a href="http://www.gpf-comics.com/premium" rel="nofollow">http://www.gpf-comics.com/premium</a>, notice that I am not logged in, login to my Premium account, click on the button to enable Premium in my browser, then look at and save the Content of the gpf_premium cookie. It is different than in step 1.</p>
<p>3. Repeat step 1. Verify that the content of the cookie is the same as in step 1.</p>
<p>4. Repeat step 2. Verify that the Content of the cooke is the same as in step 2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bugstomper</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-161</link>
		<dc:creator>bugstomper</dc:creator>
		<pubDate>Mon, 03 Mar 2008 11:39:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-161</guid>
		<description>I juat signed up for GPF Premium and took a look at the cookie you use. It already has path=&#039;/&#039; so my suggestion to try that won&#039;t help.

But here might be a clue. Whatever you are doing for the GPF_NEWS cookie works fine. I can go to any of http://www.gpf-comics.com http://gpf-comics.com https://www.gpf-comics.com https://gpf-comics.com and they all see my GPF_NEWS cookie.

However, with GPF Premium, not only does https not work to see the gpf_premium cookie, but here is a new clue: http://gpf-comics.com/premium does not use the cookie made by going to http://www.gpf-comic.com and vice-versa, even though the cookies look the same when I look at them in Firefox and they do overwrite each other. So maybe you can try to figure out why the premium cookie for gpf-comics.com overwrites but is not compatible with the one from www.gpf-comics.com</description>
		<content:encoded><![CDATA[<p>I juat signed up for GPF Premium and took a look at the cookie you use. It already has path=&#8217;/&#8217; so my suggestion to try that won&#8217;t help.</p>
<p>But here might be a clue. Whatever you are doing for the GPF_NEWS cookie works fine. I can go to any of <a href="http://www.gpf-comics.com" rel="nofollow">http://www.gpf-comics.com</a> <a href="http://gpf-comics.com" rel="nofollow">http://gpf-comics.com</a> <a href="https://www.gpf-comics.com" rel="nofollow">https://www.gpf-comics.com</a> <a href="https://gpf-comics.com" rel="nofollow">https://gpf-comics.com</a> and they all see my GPF_NEWS cookie.</p>
<p>However, with GPF Premium, not only does https not work to see the gpf_premium cookie, but here is a new clue: <a href="http://gpf-comics.com/premium" rel="nofollow">http://gpf-comics.com/premium</a> does not use the cookie made by going to <a href="http://www.gpf-comic.com" rel="nofollow">http://www.gpf-comic.com</a> and vice-versa, even though the cookies look the same when I look at them in Firefox and they do overwrite each other. So maybe you can try to figure out why the premium cookie for gpf-comics.com overwrites but is not compatible with the one from <a href="http://www.gpf-comics.com" rel="nofollow">http://www.gpf-comics.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bugstomper</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-160</link>
		<dc:creator>bugstomper</dc:creator>
		<pubDate>Mon, 03 Mar 2008 06:46:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-160</guid>
		<description>This is a long-shot, but try explicitly setting the cookie path to &#039;/&#039;. I seem to recall reading about a similar problem that was solved by doing that even though it wasn&#039;t clear why that worked as the URL path was supposed to be identical for the http and the https URLs.</description>
		<content:encoded><![CDATA[<p>This is a long-shot, but try explicitly setting the cookie path to &#8216;/&#8217;. I seem to recall reading about a similar problem that was solved by doing that even though it wasn&#8217;t clear why that worked as the URL path was supposed to be identical for the http and the https URLs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/comment-page-1/#comment-159</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Thu, 21 Feb 2008 13:58:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffdarlington.com/2008/02/06/cookie-cunundrum/#comment-159</guid>
		<description>Thanks for the input, guys, and sorry for taking so long to respond. Unfortunately, none of your suggestions are working. I&#039;ve tried writing the Set-Cookie header manually, checking all possible avenues for returning the cookie to PHP ($_COOKIE, $_REQUEST, $HTTP_COOKIE_VARS), setting the cookie twice (once in HTTP and again in HTTPS), using separate cookies for HTTP and HTTPS... none of which have worked. I still get the same situation: it sets it for one but won&#039;t read it for the other.

At this point, I&#039;m at a total loss. I&#039;ll be launching the site without HTTPS on the account management stuff for now. The only solution I can come up with something along GreatScott&#039;s line: when it comes to actually setting the cookie, bounce them out of secure mode, set the cookie, and bounce them back. Unfortunately, I don&#039;t have time to implement a solution that complex.</description>
		<content:encoded><![CDATA[<p>Thanks for the input, guys, and sorry for taking so long to respond. Unfortunately, none of your suggestions are working. I&#8217;ve tried writing the Set-Cookie header manually, checking all possible avenues for returning the cookie to PHP ($_COOKIE, $_REQUEST, $HTTP_COOKIE_VARS), setting the cookie twice (once in HTTP and again in HTTPS), using separate cookies for HTTP and HTTPS&#8230; none of which have worked. I still get the same situation: it sets it for one but won&#8217;t read it for the other.</p>
<p>At this point, I&#8217;m at a total loss. I&#8217;ll be launching the site without HTTPS on the account management stuff for now. The only solution I can come up with something along GreatScott&#8217;s line: when it comes to actually setting the cookie, bounce them out of secure mode, set the cookie, and bounce them back. Unfortunately, I don&#8217;t have time to implement a solution that complex.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
