<?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>RKWare.com &#187; Microsoft</title>
	<atom:link href="http://rkware.com/tag/microsoft/feed/" rel="self" type="application/rss+xml" />
	<link>http://rkware.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 05 Jan 2010 11:18:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Yet another example of why Microsoft sucks!</title>
		<link>http://rkware.com/2009/02/yet-another-example-of-why-microsoft-sucks/</link>
		<comments>http://rkware.com/2009/02/yet-another-example-of-why-microsoft-sucks/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 22:03:35 +0000</pubDate>
		<dc:creator>RyanK</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://rkware.com/?p=8</guid>
		<description><![CDATA[Wow&#8230; I wasted many hours today due to Microsoft and general stupidity&#8230;
Here&#8217;s the situation.. we have a legacy Classic ASP site that we are moving to more scalable and stable environment&#8230; Since we want to have multiple web servers handling the load during peak hours (it runs just fine on one right now) and be [...]]]></description>
			<content:encoded><![CDATA[<p>Wow&#8230; I wasted many hours today due to Microsoft and general stupidity&#8230;</p>
<p>Here&#8217;s the situation.. we have a legacy Classic ASP site that we are moving to more scalable and stable environment&#8230; Since we want to have multiple web servers handling the load during peak hours (it runs just fine on one right now) and be able to perform new releases along with testing during off peak times while the website continues to run on one server. This also means that we can easily throw more webservers into the mix should that be necessary later.</p>
<p>The easy (and open-source and free) solution is to use Apache as a <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html">reverse proxy</a>.  This also allows for some other neat tricks (<a href="http://www.modsecurity.org/">mod_security</a>, <a href="http://httpd.apache.org/docs/2.2/mod/mod_deflate.html">mod_deflate</a>) without having to deal with Windows and IIS configuration.. or make any code changes for that matter.</p>
<p>The problem comes in with how Classic ASP deals with cookies. Deep in the bowels of ASP, Microsoft was benevolent enough to add in HTML encoding of your cookie&#8217;s name and value. This actually isn&#8217;t a horrible thing as it prevents some poorly written code from creating an exploitable bug (<a href="http://en.wikipedia.org/wiki/HTTP_Header_Injection">HTTP Header injection</a>), but its a bit overzealous and there&#8217;s <strong>no</strong> way to alter its behavior. You&#8217;re simply stuck with it.</p>
<p>Of course, if you&#8217;re happily writing ASP code, it gets encoded and decoded for you so you never even know its going on.</p>
<p>ASP Code to set a cookie:</p>
<blockquote><p>Response.Cookies(&#8221;SERVERID&#8221;) = &#8220;balancer.www2&#8243;</p></blockquote>
<p style="text-align: left;">ASP Code to display that cookie:</p>
<blockquote style="text-align: left;">
<p style="text-align: left;">Response.Write &#8220;Cookie: &#8221; &amp; Request.Cookies(&#8221;SERVERID&#8221;)</p>
</blockquote>
<p style="text-align: left;">Outputs:</p>
<blockquote><p>SERVERID: balancer.www2</p></blockquote>
<p>The problem lies in what is actually being sent by IIS:</p>
<blockquote><p>Set-Cookie: SERVERID=balancer%2Ewww2; path=/</p></blockquote>
<p>%2E is simply an HTML Encoded period. I&#8217;ve never known a period within a string to cause a security issue&#8230; but it gets encoded anyway. Apache&#8217;s <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html">mod_proxy_balancer</a> looks at that cookie and expects to find a period within it, using the part after the period to determine which server that person should get sent back to.</p>
<p>I spent a large part of the day thinking the issue was an Apache configuration issue, as even with debug logging on, it wasn&#8217;t outputing anything. Once I looked through the code for mod_proxy_balancer, i saw that it ignores the cookie unless there&#8217;s a period in the string, and clearly there wasn&#8217;t one in my string.</p>
<p>After spending about 5 minutes trying to find a way to disable or change that behavior within ASP (there isn&#8217;t any as far as I can tell), I quickly found a solution within Apache!</p>
<p>Since Apache 2.2.4, the <a href="http://httpd.apache.org/docs/2.2/mod/mod_headers.html">mod_headers</a> module provides a method to edit a header using a regular expression. I was already using mod_headers to pass along some values through Apache (like the external IP address, or if the request was over HTTPS), so simply adding one line to the Apache configuration file fixed the issue:</p>
<blockquote><p>Header edit Set-Cookie balancer%2Ewww balancer.www</p></blockquote>
<p>Now, apache watches the response headers for when we are setting a cookie,  and if it contains &#8220;balancer%2Ewww&#8221; it gets rewritten as &#8220;balancer.www&#8221; and sure enough both Apache and IIS are perfectly happy with the cookie and everything is working well.</p>
<p>If I didn&#8217;t have access to the source code, it would have taken me weeks of trial and error to determine what the issue was or it would have been given up on for simply being incompatible. If apache wasn&#8217;t as flexible as it is, i would have been stuck writing a patch to mod_proxy_balancer and recompiling my own apache rather then relying on the distro&#8217;s packages for updates.</p>
<p>This is exactly where the closed source commercial software (Microsoft) and, to a much lessor-extent, the walled-garden open-source approach (like <a href="http://www.djangoproject.com/">Django</a>) run into issues. As long as you are only using that vendor&#8217;s software in the way that the vendor envisioned you would be using it, you&#8217;re just fine. Its also why standards are a good thing.</p>
<p>Yet another example of why <a href="http://compoundthinking.com/blog/">Mark Ramm</a> was right when he <a href="http://compoundthinking.com/blog/index.php/2009/02/04/wsgi-and-cooperation/">wrote</a> and <a href="http://www.youtube.com/watch?v=fipFKyW2FA4">talked</a> about WSGI being the right way to write tools that properly interact with one another. I&#8217;m really convinced now that the <a href="http://turbogears.com/">TurboGears</a>/<a href="http://pylonshq.com/">Pylons</a> approach is the proper way to build web applications.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Frkware.com%2F2009%2F02%2Fyet-another-example-of-why-microsoft-sucks%2F&amp;linkname=Yet%20another%20example%20of%20why%20Microsoft%20sucks%21"><img src="http://rkware.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://rkware.com/2009/02/yet-another-example-of-why-microsoft-sucks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
