<?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: Notes on PHP Session Security</title>
	<atom:link href="http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Sat, 07 Nov 2009 23:35:20 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: YuriKolovsky</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-838463</link>
		<dc:creator>YuriKolovsky</dc:creator>
		<pubDate>Mon, 24 Nov 2008 21:16:54 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-838463</guid>
		<description>very nice post dogglebones</description>
		<content:encoded><![CDATA[<p>very nice post dogglebones</p>]]></content:encoded>
	</item>
	<item>
		<title>By: dogglebones</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-818699</link>
		<dc:creator>dogglebones</dc:creator>
		<pubDate>Fri, 31 Oct 2008 02:03:06 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-818699</guid>
		<description>hello.
php&#039;s built-in session_x() functions work well enough, but there are cases where you will want to roll your own. the first to come to mind is that you&#039;ll run into trouble when implementing a single site (domain) across multiple machines (httpd processes) as in a web server farm.
fortunately, php&#039;s header() or setcookie() functions make this an easy task.
i have monkeyed up a function called session_begin() which takes two optional arguments: session_id, and session_key.
session_id is, of course, a string which identifies a given unique session; session_key is a string which is intended to help ensure that the provided session is indeed unique. consider the following.

http client one comes along and acquires a legitimate session, abc123. along with generating this session, the server records something unique about http client one, or about the communication itself, such as http client one&#039;s remote ip address (not a good idea, keep reading). this can be anything at all, not necessarily limited to an http context, and this is stored as session_key. all subsequent requests from http client one will contain the session abc123. the idea is that session_key should be something determined by the server, on the server-side, not provided by the client (i.e., javascript or hidden form-field or whathaveyou), as this is trivial for an attacker to spoof.

now, sitting across the coffee shop, http client two has been watching http client one&#039;s tcp packets and knows exactly what that session_id is. therefore, http client two does not need to poke around for usernames or passwords. no need for a phishing site. no trojan horse, spyware, keystroke logger, fraudulent phone calls, or anything else. http client two needs only to make a request to the same domain with the same session_id, while http client one is logged in. http client two now has immediate access to anything and everything available to http client one, and nobody even knows about it. that&#039;s right, a simple, untraceable attack. this works, by my testing, with yahoo! mail, gmail, hotmail, and probably about every web site i could try it on, though ssl makes things more cumbersome - i should say, not very much more cumbersome, if the attacker can see the underlying tcp.

...however, since the server is also using session_key to store and retrieve it&#039;s sessions, http client two must appear to the server as identical to http client one. for example, say the server stores http_client_id (&quot;mozilla&quot; or &quot;ie&quot; or whathaveyou) in the session_key. now, http client two must make it&#039;s request to the server not only with the same session as http client one, but also with the same browsing software. or, say, session_key is remote_addr: now http client two must also spoof his victim&#039;s ip.

the obvious argument to this is that, in our scenario, http client two sees the whole http request made by his victim. therefore, it is entirely probable that he will spoof his request to match his victims to the greatest extent possible, in trying to make his hijack. therefore, the server would see the same http_client_id (or accept_charset or whatever else you could think of). and using the client-provided ip address or any function of the underlying ip connection as a session_key would be stupid on the server&#039;s part since the server may not know about http tunnels, proxy servers, ip-masquerading firewalls, or anything else which could (and inevitably would) obfuscate the reliability of such a method.

so, here is my post in a nutshell: what would serve as a good spoof-proof session_key? that is, what can a web server (or the system running a web server) see about a web client that is not likely (even better, not possible) to be reproduced in an attacker&#039;s hijack request? answer that, and you&#039;ll have a secure, unbreakable session management implementation. you will no longer need ssl, even when dealing out credit card numbers and social security numbers and the like.

it&#039;s not a rhetorical question. i don&#039;t expect anybody to be able to answer, or else yahoo! and hotmail, gmail at least, would not be quite so easy to break into. if you can answer, though, you would be well-advised to seek a patent.</description>
		<content:encoded><![CDATA[<p>hello.<br />
php&#8217;s built-in session_x() functions work well enough, but there are cases where you will want to roll your own. the first to come to mind is that you&#8217;ll run into trouble when implementing a single site (domain) across multiple machines (httpd processes) as in a web server farm.<br />
fortunately, php&#8217;s header() or setcookie() functions make this an easy task.<br />
i have monkeyed up a function called session_begin() which takes two optional arguments: session_id, and session_key.<br />
session_id is, of course, a string which identifies a given unique session; session_key is a string which is intended to help ensure that the provided session is indeed unique. consider the following.</p>
<p>http client one comes along and acquires a legitimate session, abc123. along with generating this session, the server records something unique about http client one, or about the communication itself, such as http client one&#8217;s remote ip address (not a good idea, keep reading). this can be anything at all, not necessarily limited to an http context, and this is stored as session_key. all subsequent requests from http client one will contain the session abc123. the idea is that session_key should be something determined by the server, on the server-side, not provided by the client (i.e., javascript or hidden form-field or whathaveyou), as this is trivial for an attacker to spoof.</p>
<p>now, sitting across the coffee shop, http client two has been watching http client one&#8217;s tcp packets and knows exactly what that session_id is. therefore, http client two does not need to poke around for usernames or passwords. no need for a phishing site. no trojan horse, spyware, keystroke logger, fraudulent phone calls, or anything else. http client two needs only to make a request to the same domain with the same session_id, while http client one is logged in. http client two now has immediate access to anything and everything available to http client one, and nobody even knows about it. that&#8217;s right, a simple, untraceable attack. this works, by my testing, with yahoo! mail, gmail, hotmail, and probably about every web site i could try it on, though ssl makes things more cumbersome &#8211; i should say, not very much more cumbersome, if the attacker can see the underlying tcp.</p>
<p>&#8230;however, since the server is also using session_key to store and retrieve it&#8217;s sessions, http client two must appear to the server as identical to http client one. for example, say the server stores http_client_id (&#8221;mozilla&#8221; or &#8220;ie&#8221; or whathaveyou) in the session_key. now, http client two must make it&#8217;s request to the server not only with the same session as http client one, but also with the same browsing software. or, say, session_key is remote_addr: now http client two must also spoof his victim&#8217;s ip.</p>
<p>the obvious argument to this is that, in our scenario, http client two sees the whole http request made by his victim. therefore, it is entirely probable that he will spoof his request to match his victims to the greatest extent possible, in trying to make his hijack. therefore, the server would see the same http_client_id (or accept_charset or whatever else you could think of). and using the client-provided ip address or any function of the underlying ip connection as a session_key would be stupid on the server&#8217;s part since the server may not know about http tunnels, proxy servers, ip-masquerading firewalls, or anything else which could (and inevitably would) obfuscate the reliability of such a method.</p>
<p>so, here is my post in a nutshell: what would serve as a good spoof-proof session_key? that is, what can a web server (or the system running a web server) see about a web client that is not likely (even better, not possible) to be reproduced in an attacker&#8217;s hijack request? answer that, and you&#8217;ll have a secure, unbreakable session management implementation. you will no longer need ssl, even when dealing out credit card numbers and social security numbers and the like.</p>
<p>it&#8217;s not a rhetorical question. i don&#8217;t expect anybody to be able to answer, or else yahoo! and hotmail, gmail at least, would not be quite so easy to break into. if you can answer, though, you would be well-advised to seek a patent.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: blogauthor</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-796493</link>
		<dc:creator>blogauthor</dc:creator>
		<pubDate>Thu, 18 Sep 2008 05:29:58 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-796493</guid>
		<description>&lt;code&gt;asasasasas&lt;/code&gt;</description>
		<content:encoded><![CDATA[<code>asasasasas</code>]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-769687</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 28 Jul 2008 14:30:45 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-769687</guid>
		<description>I am shocked that you have stated that &quot;if your only storing passwords in the session&quot;.  Why on earth would you be storing passwords in the session anyway!  You store them in the database (file, mysql, xml etc) and compare them with form values and set a flag in the session as $session-&gt;Autheticated = true;  

There is absolutely no need to carry around a password in a session.</description>
		<content:encoded><![CDATA[<p>I am shocked that you have stated that &#8220;if your only storing passwords in the session&#8221;.  Why on earth would you be storing passwords in the session anyway!  You store them in the database (file, mysql, xml etc) and compare them with form values and set a flag in the session as $session-&gt;Autheticated = true;  </p>
<p>There is absolutely no need to carry around a password in a session.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-728309</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 20 May 2008 23:35:39 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-728309</guid>
		<description>lol at &quot;encrypting&quot; with md5, preferably twice. This gave you away.. you don&#039;t know what you&#039;re talking about.</description>
		<content:encoded><![CDATA[<p>lol at &#8220;encrypting&#8221; with md5, preferably twice. This gave you away.. you don&#8217;t know what you&#8217;re talking about.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: uu</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-200144</link>
		<dc:creator>uu</dc:creator>
		<pubDate>Sun, 11 Mar 2007 11:28:39 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-200144</guid>
		<description>uuuuuuu</description>
		<content:encoded><![CDATA[<p>uuuuuuu</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-200125</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sun, 11 Mar 2007 11:08:40 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-200125</guid>
		<description>kujikuk</description>
		<content:encoded><![CDATA[<p>kujikuk</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Stop the spam</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-8285</link>
		<dc:creator>Stop the spam</dc:creator>
		<pubDate>Fri, 26 Aug 2005 00:36:13 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-8285</guid>
		<description>&lt;strong&gt;The last post is very ridiculous. I hope no one will go try that weak, and seriously not working well, firewall. There is NO way to prevent a hacker to crash your computer, software, connection or whatever would make your day more bad. Don&#039;t be fooled, Even windows XP native firewall is better than this one.

And since it a unknow firewall, and probably not professional, we can&#039;t even know it is not a virus or a trojan itself so it is not reporting as is.

Thanks for your patience and NOT TRYING armor2net... &lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p><strong>The last post is very ridiculous. I hope no one will go try that weak, and seriously not working well, firewall. There is NO way to prevent a hacker to crash your computer, software, connection or whatever would make your day more bad. Don&#8217;t be fooled, Even windows XP native firewall is better than this one.</strong></p>
<p>And since it a unknow firewall, and probably not professional, we can&#8217;t even know it is not a virus or a trojan itself so it is not reporting as is.</p>
<p>Thanks for your patience and NOT TRYING armor2net&#8230; </p>]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Shiflett</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-75</link>
		<dc:creator>Chris Shiflett</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-75</guid>
		<description>&lt;p&gt;Hi Harry. That&#039;s pretty informative for a blog entry. :-)&lt;/p&gt;

&lt;p&gt;I have some resources that might help elaborate on some of these things.&lt;/p&gt;

&lt;p&gt;Session Hijacking:&lt;br /&gt;
http://shiflett.org/articles/the-truth-about-sessions&lt;/p&gt;

&lt;p&gt;Session Fixation:&lt;br /&gt;
Security Corner in the current issue of php&#124;architect. Unforunately, this is not yet available for free.&lt;/p&gt;

&lt;p&gt;XSS:&lt;br /&gt;
http://www.phparch.com/issuedata/articles/article_66.pdf&lt;/p&gt;

&lt;p&gt;Shared Hosts:&lt;br /&gt;
I&#039;m finishing up an article about this (and safe_mode) for the next Security Corner, and here is a script that developers can use to better illustrate how open a shared server is (when safe_mode is disabled, which is common):&lt;br /&gt;
http://shiflett.org/code/browse.phps&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Hi Harry. That&#8217;s pretty informative for a blog entry. :-)</p>
<p>I have some resources that might help elaborate on some of these things.</p>
<p>Session Hijacking:<br />
<a href="http://shiflett.org/articles/the-truth-about-sessions" rel="nofollow">http://shiflett.org/articles/the-truth-about-sessions</a></p>
<p>Session Fixation:<br />
Security Corner in the current issue of php|architect. Unforunately, this is not yet available for free.</p>
<p>XSS:<br />
<a href="http://www.phparch.com/issuedata/articles/article_66.pdf" rel="nofollow">http://www.phparch.com/issuedata/articles/article_66.pdf</a></p>
<p>Shared Hosts:<br />
I&#8217;m finishing up an article about this (and safe_mode) for the next Security Corner, and here is a script that developers can use to better illustrate how open a shared server is (when safe_mode is disabled, which is common):<br />
<a href="http://shiflett.org/code/browse.phps" rel="nofollow">http://shiflett.org/code/browse.phps</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2004/03/03/notes-on-php-session-security/comment-page-1/#comment-76</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1893350807#comment-76</guid>
		<description>&lt;p&gt;Hi Chris. Thanks for some those very informative links. And thanks for all the hard work you&#039;re doing on phpcommunity.org.&lt;/p&gt;

&lt;p&gt;Perhaps one phpcommunity &quot;deliverable&quot; might be to compile the various documents on PHP Security out there and submit it to http://www.owasp.org - I notice thier Guidelines document has a blank PHP section and, in general, is almost entirely focused on J2EE and .NET.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Hi Chris. Thanks for some those very informative links. And thanks for all the hard work you&#8217;re doing on phpcommunity.org.</p>
<p>Perhaps one phpcommunity &#8220;deliverable&#8221; might be to compile the various documents on PHP Security out there and submit it to <a href="http://www.owasp.org" rel="nofollow">http://www.owasp.org</a> &#8211; I notice thier Guidelines document has a blank PHP section and, in general, is almost entirely focused on J2EE and .NET.</p>]]></content:encoded>
	</item>
</channel>
</rss>
