<?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>Neural Core Dump &#187; Security Now</title>
	<atom:link href="http://www.jeffdarlington.com/tag/security-now/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeffdarlington.com</link>
	<description>The personal blog of Jeffrey T. Darlington, creator of General Protection Fault</description>
	<lastBuildDate>Sat, 28 Jan 2012 20:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Look, Ma! I&#8217;m on Security Now!</title>
		<link>http://www.jeffdarlington.com/2008/07/14/look-ma-im-on-security-now/</link>
		<comments>http://www.jeffdarlington.com/2008/07/14/look-ma-im-on-security-now/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 14:54:52 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[DoubleClick]]></category>
		<category><![CDATA[podcast]]></category>
		<category><![CDATA[Security Now]]></category>
		<category><![CDATA[Steve Gibson]]></category>
		<category><![CDATA[TWiT]]></category>

		<guid isPermaLink="false">http://www.jeffdarlington.com/?p=148</guid>
		<description><![CDATA[I hope to post more on this when there&#8217;s more data to post, but I thought I&#8217;d throw up a quick note stating that the latest episode of the Security Now! &#8220;netcast&#8221; features a question posed by yours truly. (The best part was listening to Leo Laporte stumble over my long-winded rambling. ) The high-quality [...]]]></description>
			<content:encoded><![CDATA[<p>I hope to post more on this when there&#8217;s more data to post, but I thought I&#8217;d throw up a quick note stating that the <a title="Security Now! #152 (TWiT.tv)" href="http://twit.tv/sn152">latest episode of the Security Now! &#8220;netcast&#8221;</a> features a question posed by yours truly. (The best part was listening to Leo Laporte stumble over my long-winded rambling. <img src='http://www.jeffdarlington.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) The high-quality version of the show can be found at the previous link; a low-bandwidth version as well as a text-only transcript can be found at the <a title="Security Now! #152 (GRC.com)" href="http://www.grc.com/sn/sn-152.htm">corresponding page at GRC.com</a>. A search in the transcript for &#8220;Darlington&#8221; will take you to the beginning of my question; in the netcast, it starts around 38 minutes, 22 seconds in. (Of course, I encourage everyone to read/listen to the entire thing.)</p>
<p>For the full effect, though, you&#8217;ll also need to listen to/read the previous two non-Q&amp;A episodes of the show, <a title="Security Now! #149 (TWiT.tv)" href="http://twit.tv/sn149">#149</a> and <a title="Security Now! #151 (TWiT.tv)" href="http://twit.tv/sn151">#151</a>. (Low-bandwidth and trascriptions can be found <a title="Security Now! #149 (GRC.com)" href="http://www.grc.com/sn/sn-149.htm">here</a> and <a title="Security Now! #151 (GRC.com)" href="http://www.grc.com/sn/sn-151.htm">here</a>.) The entire dialog concerns the recent trend of <a title="Internet service provider article on Wikipedia" href="http://en.wikipedia.org/wiki/Internet_service_provider">ISPs</a> selling out their customers to allow third-party advertisers to come in and install hardware at the ISP to facilitate tracking the ISPs&#8217; customers&#8217; surfing habits across sites. While the ad companies in question claim to not be recording personally identifyable information about the ISPs&#8217; customers, the capability is there and the possibilities for abuse are enormous. It brings back many shades of the <a title="DoubleClick article on Wikipedia" href="http://en.wikipedia.org/wiki/DoubleClick">DoubleClick</a> controversies of the late 1990s-early 2000s, only much more ominous. I provided a unqiue standpoint to the discussion: that of a Web developer hosting a site and encountering similiar mysterious &#8220;first party&#8221; cookies set for my domain but not set by me.</p>
<p>The full body my question is present, but I&#8217;m not completely satisfied with the answer. <img src='http://www.jeffdarlington.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Let&#8217;s just say I think Steve Gibson made an assumption about the <a title="General Protection Fault" href="http://www.gpf-comics.com/">GPF</a> site that&#8217;s not 100% true. I&#8217;ve replied to his response with additional information. I don&#8217;t necessarily expect another response (he does, after all, have his own agenda to follow on <em>his</em> show), and even if he does it will likely be in episode #154, the next scheduled Q&amp;A episode. If anyone is interested, I&#8217;ll post updates if and when this occurs. If I don&#8217;t get a response, I&#8217;ll post my response here, especially since it contains some disturbing observations about &#8220;first party&#8221; cookies that have mildly paranoid folks like me nervous. (I&#8217;d hate to see what it does to <em>really</em> paranoid people.)</p><div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.jeffdarlington.com/2008/07/14/look-ma-im-on-security-now/' addthis:title='Look, Ma! I&#8217;m on Security Now! '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.jeffdarlington.com/2008/07/14/look-ma-im-on-security-now/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Disturbing: PayPal in cahoots with DoubleClick?</title>
		<link>http://www.jeffdarlington.com/2007/11/27/disturbing-paypal-in-cahoots-with-doubleclick/</link>
		<comments>http://www.jeffdarlington.com/2007/11/27/disturbing-paypal-in-cahoots-with-doubleclick/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 16:52:57 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[DoubleClick]]></category>
		<category><![CDATA[PayPal]]></category>
		<category><![CDATA[Security Now]]></category>
		<category><![CDATA[Steve Gibson]]></category>
		<category><![CDATA[TWiT]]></category>

		<guid isPermaLink="false">http://www.jeffdarlington.com/2007/11/27/disturbing-paypal-in-cahoots-with-doubleclick/</guid>
		<description><![CDATA[I don&#8217;t usually do link-and-run posts (I prefer to have actual content in a blog), but I thought this was disturbing enough to disseminate. I&#8217;ll probably add my own blathering commentary which will make it more than a link-and-run post anyway. (After all, I know all of you who come here really come for the [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t usually do link-and-run posts (I prefer to have actual <em>content</em> in a blog), but I thought this was disturbing enough to disseminate. I&#8217;ll probably add my own blathering commentary which will make it more than a link-and-run post anyway. (After all, I know all of you who come here <em>really</em> come for the blathering. I&#8217;m just so blatherful&#8230;.)</p>
<p>I&#8217;m not sure how many of you out there follow the <a href="http://www.twit.tv/sn" title="The TWiT Netcast Network: Security Now!">Security Now!</a> podcast over at <a href="http://www.twit.tv/" title="The TWiT Netcast Network">TWiT</a>, but it&#8217;s probably obvious by now that I do, given <a href="http://www.jeffdarlington.com/2007/11/07/roaming-authentication-with-apache-mod_rewrite/" title="Roaming authentication with Apache mod_rewrite, November 7th, 2007">recent</a> <a href="http://www.jeffdarlington.com/2007/10/31/wordpress-security-tweaks/" title="WordPress security tweaks, October 31st, 2007">posts</a>. This past week&#8217;s episode, <a href="http://www.twit.tv/sn119" title="TWiT: Security Now! #119">#119</a>, exposes a rather unsettling fact that shouldn&#8217;t be ignored.  (The high quality 64kbps MP3 can be found at that link, while a 16kbps MP3, a transcript in various formats, and additional notes can be found <a href="http://www.grc.com/SecurityNow.htm#119" title="GRC | Security Now!">here</a>.) While I encourage you to download and listen/read the facts for yourself, I&#8217;ll see if I can summarize it below for the attention-span impaired.</p>
<p>For a long time, I&#8217;ve defended <a href="https://www.paypal.com/" title="PayPal">PayPal</a> as a method of monetary transfer. They&#8217;ve always been good to me personally, even during the stormy periods where some <a href="http://www.gpf-comics.com/" title="General Protection Fault">GPF</a> readers boycotted them for &#8220;questionable&#8221; practices. (See the <a href="http://en.wikipedia.org/wiki/PayPal" title="PayPal article on Wikipedia">PayPal Wikipedia entry</a> for an abbreviated history.) For that matter, many online comics wouldn&#8217;t be able to monetize themselves in <em>any</em> fashion if it weren&#8217;t for PayPal, as many webcomics use the service for donations and online stores. (PayPal has always been an acceptable form of payment in every incarnation of the <a href="https://www.jeffdarlington.com/store/" title="The Official GPF Store">GPF Store</a>.) They&#8217;ve always had issues with customer service, but they&#8217;ve also been champions in <a href="http://en.wikipedia.org/wiki/Phishing" title="Phishing article on Wikipedia">anti-phishing</a> campaigns.</p>
<p>But Steve Gibson and Leo Laporte have helped disclose a rather shady new practice: In a previous Security Now! episode, a listener mentioned problems downloading a software service from PayPal, only to discover that the download link was sending him to a server over at <a href="http://www.doubleclick.com/" title="DoubleClick.com">DoubleClick</a> rather than PayPal. Since he was locally blocking access to the domain &#8220;doubleclick.net&#8221; in his <a href="http://en.wikipedia.org/wiki/Hosts_file" title="Hosts file article on Wikipedia">hosts file</a>, the link failed and the software would not download. Gibson promised to investigate the incident and after a number of side-tracks finally presented his results.</p>
<p>DoubleClick, for the few out there unfamiliar with it, is one of the Internet&#8217;s largest online advertising agencies, serving ad banners to millions of Web sites (including, indirectly, GPF). DoubleClick has long been unpopular among netizens for its questionable policies of tracking Web surfers across multiple sites, using a trick with <a href="http://en.wikipedia.org/wiki/HTTP_cookie#Privacy_and_third-party_cookies" title="Privacy and third-party cookies section of the HTTP Cookie Wikipedia article">tracking cookies</a> to follow you from site to site. Privacy concerns were raised even further when <a href="http://www.google.com/" title="Google">Google</a>, a company that itself stores and indexes a lot of personal information about its users of GMail, Ad-Sense, and other services, recently purchased DoubleClick. DoubleClick eventually bowed to pressure from the Net at large and created an <a href="http://www.doubleclick.com/privacy/dart_adserving.aspx" title="DoubleClick.com: Privacy: Dart Ad Serving: Opt-Out">opt-out page</a> so their tracking cookie would contain &#8220;non-personally-identifiable information&#8221; and thus negate some of the tracking cookie&#8217;s effectiveness. (This opt-out page is still linked to (now indirectly, as the URL has changed) from the <a href="http://www.gpf-comics.com/privacy.html" title="GPF: Privacy Statement and Ad Info">GPF privacy policy page</a>.) Many folks these days, however, including myself, simply run <a href="http://en.wikipedia.org/wiki/Spyware" title="Spyware article on Wikipedia">spyware</a> scanners like <a href="http://www.safer-networking.org/" title="Spybot: Search &amp; Destroy">Spybot: Search &amp; Destroy</a> or<a href="http://www.lavasoftusa.com/" title="Lavasoft"> Ad-Aware</a> and periodically delete such tracking cookies, or just block the &#8220;doubleclick.net&#8221; domain and its subdomains using the hosts file trick mentioned above. (This is how, in part, Spybot&#8217;s immunization against cookies works.) This eliminates or at least minimizes the opportunity for your Web surfing habits to be linked personally to you.</p>
<p>However, PayPal&#8217;s new links bypass many of these anti-drive-by-cookie-ing techniques by sending you directly to DoubleClick&#8217;s servers, rather than inlining content like Flash or images from their site. Since these are internal PayPal URLs and not links that are expected to send you to the outside, they should be immediately suspicious. What&#8217;s even worse is that if you examine the URL closely, there appears to be some sort of &#8220;user ID&#8221; like number included that may personally identify you if you click on it. What&#8217;s even <em>more</em> disturbing is the number of these links you run across as you surf the PayPal site; while some obviously ad-like images contain the &#8220;doubleclick.net&#8221; URL, many links in the site bar that look like ordinary navigational links contain it as well. While Gibson points out&#8211;quite rightly&#8211;that there is no evidence to support any sort of conspiracy theories that many come to mind, it <em>is</em> obvious enough that <em>some</em> sort of information sharing is going on between the two companies, and that if a unique user identifier is indeed being passed along with the URL, there&#8217;s a likelihood that both companies can link your potential spending habits with PayPal to your surfing habits tracked by DoubleClick.</p>
<p>Now it&#8217;s easy to be alarmist and to say everyone should boycott PayPal. Unfortunately, so many of us in webcomics depend on PayPal for survival, so there&#8217;s no way we can easily remove ourselves from it. And there&#8217;s no competitor out there with enough critical mass to really challenge PayPal for dominance, so there aren&#8217;t many viable alternatives. Thus the only current immunization option is diligent observation.</p>
<p>The good news is that the DoubleClick URLs within PayPal&#8217;s site all contain at the end PayPal URL you will eventually be redirected to. It&#8217;s trivial to copy the URL, paste it into your address bar, crop out the DoubleClick portion, and go directly the the PayPal internal destination. Laporte even suggested that it won&#8217;t be long before someone comes up with a <a href="http://www.mozilla.com/firefox/" title="Firefox">Firefox</a> <a href="https://addons.mozilla.org/en-US/firefox/" title="Firefox Add-ons">plugin</a> that does that for you on the fly. The problem I see with this is that it won&#8217;t be long before the diabolical duo figures out savvy users are bypassing the links and they find a better way to obscure the redirection target URL so the copy/paste/edit trick will no longer work. While true encryption might be a bit too much server load for them to handle <em>en masse,</em> a simple ROT13 or Base64 encode might be enough to thwart all but the most stalwart gearheads.</p>
<p>So&#8230; should <em>you</em> avoid PayPal? That&#8217;s up to you. I <em>can&#8217;t,</em> but I&#8217;ll be a lot more careful of where I click on their site from now on.</p><div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.jeffdarlington.com/2007/11/27/disturbing-paypal-in-cahoots-with-doubleclick/' addthis:title='Disturbing: PayPal in cahoots with DoubleClick? '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.jeffdarlington.com/2007/11/27/disturbing-paypal-in-cahoots-with-doubleclick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roaming authentication with Apache mod_rewrite</title>
		<link>http://www.jeffdarlington.com/2007/11/07/roaming-authentication-with-apache-mod_rewrite/</link>
		<comments>http://www.jeffdarlington.com/2007/11/07/roaming-authentication-with-apache-mod_rewrite/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 21:25:59 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[Security Now]]></category>
		<category><![CDATA[Steve Gibson]]></category>
		<category><![CDATA[TWiT]]></category>

		<guid isPermaLink="false">http://www.jeffdarlington.com/2007/11/07/roaming-authentication-with-apache-mod_rewrite/</guid>
		<description><![CDATA[I mentioned last week that I was working on a neat Apache mod_rewrite trick for locking down access to certain administration pages, but that I wasn&#8217;t having much success with it. Well, it seems to be working now and, as promised, I wanted to share it with anyone who might be interested. Fair warning to [...]]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://www.jeffdarlington.com/2007/10/31/wordpress-security-tweaks/" title="WordPress security tweaks, October 31st, 2007">mentioned last week</a> that I was working on a neat <a href="http://httpd.apache.org/" title="Apache Web server">Apache</a> <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html" title="mod_rewrite documentation"><code>mod_rewrite</code></a> trick for locking down access to certain administration pages, but that I wasn&#8217;t having much success with it. Well, it seems to be working now and, as promised, I wanted to share it with anyone who might be interested. Fair warning to non-technical readers: extreme geekery lies ahead.</p>
<p>First and foremost, I can&#8217;t claim full credit for this idea. It borrows some from <a href="http://www.grc.com/default.htm" title="Gibson Research Corporation">Steve Gibson</a>&#8216;s roaming authentication scheme outlined in episode #113 of the <a href="http://www.grc.com/SecurityNow.htm" title="GRC | Security Now!">Security Now! podcast</a>. In that show (and subsequently continued in episode #115), Gibson outlines his method of allowing his employees to access secure portions of his site while traveling. The method described here is not quite as secure as his, as I&#8217;m forcing things to happen at the Web server software layer as opposed to the application layer and thus don&#8217;t have the same fine granularity of control he has. However, it uses many of the same ideas.</p>
<p>It&#8217;s relatively easy with <code>mod_rewrite</code> to protect certain resources of a site by restricting access to certain IP addresses. Consider the following:</p>
<blockquote><p><code>RewriteCond %{REQUEST_URI}   ^/store/admin/.*<br />
RewriteCond %{REMOTE_ADDR} !^192\.168\.13\.<br />
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$<br />
RewriteRule ^/store/admin/.* /store/ [R,L]</code></p></blockquote>
<p>This rule set essentially says: (1) if the requested URL starts with the string &#8220;/store/admin/&#8221; and (2) the IP address of the requesting client does not begins with &#8220;192.168.13.&#8221; or (3) is not exactly &#8220;127.0.0.1&#8243; then (4) redirect all requests for URLs starting with &#8220;/store/admin/&#8221; to the root URL of the store, &#8220;/store/&#8221;. Essentially, we&#8217;re only allowing access to what is apparently the administrative portions of an online store to a very limited number of IP addresses, one of which is fully qualified (the &#8220;loop-back&#8221; address of 127.0.0.1) and the rest belonging to a range (192.168.13.0 through 192.168.13.255). Anyone outside these IPs will be transparently redirected to the front page of the store. (Redirecting is much friendlier than outright forbidding access.) All of this takes place in Apache itself, before we even get to the application and any potential security flaws it might have. There are no worries about hacking the store software itself to deny access.  Of course, we can list any number of <code>REMOTE_ADDR</code> entries that we wish; each condition is a regular expression (which are negated here by the &#8220;bang&#8221; at the front) so we can filter on any octet we want and can easily specify real, outside IPs rather than private ones. For example, for this site I limit access to my various admin sections to the IP of my cable modem and our outside IP at work.</p>
<p>However, what happens when you are required to go on a trip and need to access the administrative parts of the site while on the go? Obviously, you can&#8217;t add the hotel&#8217;s outside IP to this rule set in advance (imagine asking the front desk for <em>that</em> information), and you probably won&#8217;t be able to add it easily once you get there. Sure, <a href="http://wordpress.org/" title="WordPress">WordPress</a> and the store front software have login security on their various admin interfaces, but we&#8217;re trying to protect those from hackers, right? Aside from reopening them to the entire Internet before the trip and closing them again once we get back, there aren&#8217;t very many options. How then can we identify approved &#8220;roaming&#8221; users and/or machines so they can access the admin sites without being inside a hard-coded list of IPs?</p>
<p>Gibson&#8217;s answer was to optionally set a secure cookie in the user&#8217;s browser if they access the admin site within one of the approved IPs first. Being within an approved IP, they aren&#8217;t restricted by the access rule and they are allowed to reach the login prompt. During login, they are prompted on whether or not they want to enable roaming access on this particular machine. If they agree, a secure cookie is set in the browser and set to expire at some date in the future. Later, when the user attempts to access the admin site outside of the approved IP list, the site checks to see if the cookie has been set. If present, the user is allowed to log in, just as if they were within one of the approved IPs. The cookie acts as a kind of two-factor authentication: the first factor being &#8220;something you know&#8221;, the user name and password, and the second being &#8220;something you have&#8221;, the cookie. Since the cookie is set in secure mode (HTTPS), it will only be sent back to the site over a secure connection. And since (well behaved) browsers only allow a site to read the cookies it has itself set, no other site should be able to read it.</p>
<p>This is all well and good&#8230; <em>if</em> you have access to the source of the application you&#8217;re trying to secure and you&#8217;re willing to hack it. Gibson wrote his own store front, so this was relatively easy for him to integrate. But I want to secure WordPress, a third-party store app, and a few random subdirectories that are pretty much statically built HTML. As much as I like running Open Source software, I usually prefer not to muck around with things if I can help it, lest I screw something up. Thus, I don&#8217;t particularly want to hack WP and the store to add this extra layer of functionality. Fortunately, though, <code>mod_rewrite</code> gives us a mechanism through which we can accomplish basically the same thing without modifying the underlying application. In theory, since all this occurs <em>before</em> we even reach the application, one could argue it may even be <em>more</em> secure than the application&#8217;s authentication mechanisms themselves.</p>
<p>You can actually set browser cookies via <code>mod_rewrite</code> rules. Consider what happens if we insert the following before the rules we defined above:</p>
<blockquote><p><code>RewriteCond %{REMOTE_ADDR} ^192\.168\.13\.<br />
RewriteCond %{HTTP_COOKIE} "!</code><code>(.+; )*admincookie=uniqueval(; .+)*"</code><br />
<code> RewriteRule .* - [CO=admincookie:uniqueval:.domainname.tld:43200:/store/]</code></p></blockquote>
<p>This rule set essentially says: (1) if the remote IP starts with &#8220;192.168.13.&#8221; and (2) there isn&#8217;t a cookie already set by the name &#8220;admincookie&#8221; then (3) set a cookie named &#8220;admincookie&#8221; with the value &#8220;uniqueval&#8221; for the domain &#8220;.domainname.tld&#8221; (assuming that&#8217;s our real domain name) for a period of 30 days (60 minutes x 24 hours x 30 days = 43,200 minutes) restricted to the path &#8220;/store/&#8221; and its subdirectories. Now let&#8217;s modify the rule set from before:</p>
<blockquote><p><code>RewriteCond %{REQUEST_URI}   ^/store/admin/.*<br />
RewriteCond %{REMOTE_ADDR} !^192\.168\.13\.<br />
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$<br />
RewriteCond %{HTTP_COOKIE} "!(.+; )*admincookie=uniqueval(; .+)*"<br />
RewriteRule ^/store/admin/.* /store/ [R,L]</code></p></blockquote>
<p>Note that we&#8217;ve added a new condition. In addition to checking for the approved IP list, we also check to see if the &#8220;admincookie&#8221; has been set and that its value is what we expect (&#8220;uniqueval&#8221;). Note the parenthetical parts at the beginning and end of the cookie regex; these should make sure we match the unique cookie name/value pair, regardless of how many cookies are present. (Also note the quotes around this regex; since whitespace delimits the parts of the rewrite statements, the quotes are required to include the spaces after the semicolons in the regex. Without the quotes, the regex produces a &#8220;bad flag delimiters&#8221; error when Apache parses the configuration file.) Since each approved item&#8217;s entry is negated, the rule is only applied if none of them match. So now we should be able to get into the site remotely if and only if we&#8217;re inside an approved IP or we have the secret cookie, which we know is only set if we&#8217;ve been in one of the approved IPs first. Instant roaming authentication!</p>
<p>To summarize, the primary advantages to this scheme are:</p>
<ul>
<li>Restricts access to specific requested URIs to specific IP addresses and/or ranges and to machines outside those addresses that have a special roaming authentication cookie.</li>
<li>The roaming cookie can only be set from within one or more of the authorized IPs.</li>
<li>The cookie is set and checked at the Web server level, before the request reaches application code, so this scheme can be placed on top of third-party applications as an additional layer of security. No changes to the application layer are required.</li>
</ul>
<p>There are, of course, a few caveats:</p>
<ul>
<li>Based on these rules alone, none of the information transmitted back and forth is encrypted; it&#8217;s all sent in the clear, which may potentially be sniffed by a man in the middle. Then again, you can always use <code>mod_rewrite</code> to force certain URLs to always use SSL (assuming you have a secure certificate), thereby securing the connection first. All WP admin functions, the <a href="https://www.jeffdarlington.com/store/" title="GPF Store">GPF Store</a>, and my other secured admin locales here on this site are all secured via SSL, so that helps in keeping my site secure by eliminating sniffing. (Of course, if you go this route, don&#8217;t forget to copy any necessary rules from the main Apache configuration file to the SSL config file, as the secure site will be treated as a different virtual host with its own set of rewriting rules. This little hiccup is what was keeping me from publishing this for quite a while.)</li>
<li>Forcing SSL, however, doesn&#8217;t necessarily protect the cookie itself. Gibson&#8217;s roaming authentication cookie required an SSL connection. This is called a secure mode cookie. While I&#8217;m still doing research into this, as far as I can tell so far <code>mod_rewrite</code> does not have the facility to specify secure mode in a cookie set by a rewrite rule. Thus, the above cookie is <em>not</em> secure and will be sent with each request in or below the specified path, encrypted or not. The cookie is then theoretically susceptible to sniffing attacks. Setting a secure mode cookie is easy enough to do in application code, but not apparently so in <code>mod_rewrite</code>.</li>
<li>The value of the cookie is currently hard-coded to a set value, and every browser accessing it within the approved IP will receive the same hard-coded cookie value. Ideally, the cookie should be unique to each browser and somehow obscured or, better yet, encrypted. Unfortunately, while I&#8217;ve been researching this also, so far I haven&#8217;t come up with a way to create such a unique token natively within <code>mod_rewrite</code>. (Remember, all this is occurring in Apache before we even reach application code.) Right now, <strike>I&#8217;m using a rather large hash of a unique pass phrase string</strike> I use a small command-line script to create a very long, highly random string using random numbers, several hashes, a little bit of Blowfish encryption, and some random string manipulation, but the cookie value is still technically hard coded. It may be possible to write a cron that will periodically create a new value token, update the Apache config file, and restart Apache. This will update the value every so often, but it seems quite a hassle.  (Plus, the user under which the cron runs has to be root in order to modify both the config file and to restart Apache.)</li>
<li>Similarly, there&#8217;s no way to distinguish between browsers behind the approved IP. My desktop is unlikely to roam anywhere, so it technically doesn&#8217;t need the cookie. Meanwhile, if my parents bring their laptop over and visit this site from that machine while within my network, they&#8217;d get the roaming cookie as well. Neither of these scenarios are ideal. In application code, it would be simple to set the cookie only after the user has been authenticated by the app&#8217;s internal mechanism first. But we&#8217;re not working with application code; we&#8217;re rewriting URLs in the server. Thus, this becomes a different security concern: controlling access to the approved IPs, which could be both a physical (who can patch directly in via Ethernet) and a logical issue (who can access the wireless LAN). One thing I&#8217;ve done to get around this problem is to require the browser to be authorized for roaming access to first navigate to a very large (~50 characters), randomly-generated alphanumeric subdirectory alias (generated using the same command-line script mentioned above) that is highly improbably that some might guess. This alias can only be accessed within a single authorized IP address that I directly control. It is only then that the cookie set. This eliminates the unintentional cookie setting by casual browsing of the site from other machines behind the approved IP.</li>
<li><strike>The regular expression to match the cookie should probably be more precise. For example, the expression as stated above could also match the string &#8220;myadmincookie=uniquevalnum2&#8243;, which technically isn&#8217;t what we want. Since we&#8217;re only dealing with cookies that should be set by our domain, it may not be that big of a deal, but it&#8217;s still a vulnerability nonetheless. If nothing else, there&#8217;s always the potential of colliding with cookies sent by other applications running on your site, so picking a unique cookie name and value is important. The <code>%{HTTP_COOKIE}</code> variable gets all the cookies for a given site/path as one big string, with each name/value pair delimited by a semi-colon and a space (&#8220;; &#8220;) and the name and value are glued together with an equal sign. I&#8217;m looking into a better regex to match this more precisely and I&#8217;ll update this post if I find one.</strike> I&#8217;ve updated the regex so it should match the cookie name/value pair more exactly.</li>
<li>Of course, none of this by itself can completely secure a site. In addition to this scheme, I force SSL on certain paths, deny access for all users to other paths that should never be accessed directly, and even explicitly block certain IP ranges that have attempted to hack the site. It&#8217;s not fool proof by any means, but combined with many other secure practices and mechanisms, it adds one more layer of protection, and sometimes one added layer can make all the difference.</li>
</ul>
<p>I welcome any feedback on how to improve this, especially if anyone knows how to get around the secure and unique cookie caveats.</p>
<p><em>Appendium:</em>  I should also point out that this scheme should be equally usable if you place the code in your master Apache configuration file (usually something like <code>/etc/httpd/conf/httpd.conf</code> on UNIX clones) or in per-directory <code>.htaccess</code> files. I usually prefer to put such rules in the master config file, mostly because it&#8217;s more secure (outside of the document root) and only gets parsed and loaded once while <code>.htaccess</code> files are read and parsed each time there&#8217;s a request in that directory (or any of its subdirectories). However, that only works if you have access to the master config, which most shared hosting services don&#8217;t provide. Of course, such rules placed in an <code>.htaccess</code> file will only apply to that directory and its subdirectories, so you&#8217;d have to tweak the rules (such as file paths and the cookie path) as necessary.</p>
<p><em>Update 11/20/2007:</em> Updated cookie regex to better match the exactly name/value pair; added notes about rotating cookie values.</p>
<p><em>Update 11/30/2007:</em>  Put cookie regex in quotes to correct avoid &#8220;bad flag delimiters&#8221; parsing errors; added advantage summary to better showcase the advantages of the scheme; updated my cookie value scheme; added highly-random subdirectory alias to avoid unintentional cookie-ing</p><div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.jeffdarlington.com/2007/11/07/roaming-authentication-with-apache-mod_rewrite/' addthis:title='Roaming authentication with Apache mod_rewrite '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.jeffdarlington.com/2007/11/07/roaming-authentication-with-apache-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

