<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Pádraic Brady &#187; PHP Security</title>
	<atom:link href="http://blog.astrumfutura.com/category/PHP-Security/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.astrumfutura.com</link>
	<description>PHP, Zend Framework and Other Crazy Stuff</description>
	<lastBuildDate>Wed, 25 Jan 2012 11:12:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/3.0/</creativeCommons:license>		<item>
		<title>Mockery 0.7.2 Released (And On Packagist.org!)</title>
		<link>http://blog.astrumfutura.com/2012/01/mockery-0-7-2-released-and-on-packagist-org/</link>
		<comments>http://blog.astrumfutura.com/2012/01/mockery-0-7-2-released-and-on-packagist-org/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 11:07:07 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[mockery]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=700</guid>
		<description><![CDATA[Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a framework for creating test doubles like mock objects through the use of a simple and succint API capable of clearly defining all possible object operations]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2012%2F01%2Fmockery-0-7-2-released-and-on-packagist-org%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2012%2F01%2Fmockery-0-7-2-released-and-on-packagist-org%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=mockery&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="https://github.com/padraic/mockery">Mockery</a> is a simple yet flexible PHP mock object framework for use in unit testing with <a class="zem_slink" title="PHPUnit" rel="homepage" href="http://www.phpunit.de">PHPUnit</a>, <a href="http://www.phpspec.net/">PHPSpec</a> or any other testing framework. Its core goal is to offer a framework for creating test doubles like mock objects through the use of a simple and succint API capable of clearly defining all possible object operations and interactions using a human readable <a class="zem_slink" title="Domain-specific language" rel="wikipedia" href="http://en.wikipedia.org/wiki/Domain-specific_language">Domain Specific Language</a> (DSL). Designed as a drop in alternative to PHPUnit&#8217;s <a href="https://github.com/sebastianbergmann/phpunit-mock-objects">phpunit-mock-objects</a> library, Mockery is easy to integrate with PHPUnit and can happily operate alongside phpunit-mock-objects.</p>
<p>Today, I am pleased to announce the release of Mockery 0.7.2, a maintenance release fixing a small number of bugs and annoyances. A special thanks to all those who forked the Github project at and submitted pull requests! Leaving a developer with hardly any work to do other than a quick test and merge is always appreciated! You can install or upgrade to the new version from the <a href="http://pear.survivethedeepend.com">survivethedeepend.com PEAR channel</a>.</p>
<p>Another piece of news is that Mockery is now available on <a href="http://packagist.org/packages/mockery/mockery">Packagist.org</a> for users of <a href="http://packagist.org/about-composer">Composer</a>. Composer is a tool to help you manage your own projects&#8217; or librarys&#8217; dependencies and it can handle and mix dependencies from Composer compatible repositories like <a href="http://packagist.org">Packagist.org</a>, any git repository using tags, and any PEAR channel. I do this of my own free will and not because Luis Cordova and Benjamin Eberlei are standing behind me with pitchforks <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>The more pertinant fixes include:</p>
<ol>
<li>Fixed a problem in resolving methods chains which abuse the <a title="Law of Demeter" rel="wikipedia" href="http://en.wikipedia.org/wiki/Law_of_Demeter">Law of Demeter</a> (thanks to the wizardly Robert Basic).</li>
<li>Fixed unexpected static calls to an alias mock which were causing fatal errors (thanks to Luis Cordova).</li>
<li>Fixed a crash present since PHP 5.3.6 due to a referenced $this variable entering a closure (thanks to Martin Sadovy).</li>
<li>Added support for PHP_CodeCoverage 1.1 whose filter class is no longer a singleton (thanks to Matthew Vivian).</li>
<li>Added non-halting exception handling (for Mockery exceptions) to the PHPUnit TestListener (thanks to Adrian Slade).</li>
<li>Added boolean $prepend (defaults to FALSE) parameter to  \Mockery\Loader::register() to allow for registering Mockery&#8217;s  autoloader to the top of the autoloader stack even after other  autoloaders have been registered (thanks to Hermann Kosselowski).</li>
<li>Updated documentation/tests for the release of Hamcrest 1.0.0 several  days ago (thanks to me, me, me &#8211; who finally got to do something nobody  else had a pull request for!).</li>
<li>Added new \Mockery::self() static method to make retrieving the current  mock object simpler and more readable while setting expectations without  the need to refer back to past variable assignments.</li>
</ol>
<p>Users should also note that <a href="http://code.google.com/p/hamcrest/downloads/list">Hamcrest 1.0.0</a>, which includes a small filename change (hamcrest.php was capitalised to Hamcrest.php), was released several days ago. If you use Hamcrest matchers with Mockery, you should ensure that both libraries are updated on your system.</p>
<p>As always, please report any bugs or potential improvements to the Github issue tracker using the relevant label or, even more appreciated, send me a pull request.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=bca20a55-a102-4f9e-87be-350304e0b374" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2012/01/mockery-0-7-2-released-and-on-packagist-org/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Storing Session Data In Cookies: Problems And Security Concerns To Be Aware Of</title>
		<link>http://blog.astrumfutura.com/2012/01/storing-session-data-in-cookies-problems-and-security-concerns-to-be-aware-of/</link>
		<comments>http://blog.astrumfutura.com/2012/01/storing-session-data-in-cookies-problems-and-security-concerns-to-be-aware-of/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 21:20:12 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=688</guid>
		<description><![CDATA[Back from my extended leave of absence, I&#8217;ll re-open the dusty cobwebbed depths of this blog to echo the sentiments of Paul Reinheimer in his recent article &#8220;Cookies don&#8217;t replace Sessions&#8220;. The topic is actually an old one since Ruby On Rails has adopted the strategy of storing application session data in cookies by default]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2012%2F01%2Fstoring-session-data-in-cookies-problems-and-security-concerns-to-be-aware-of%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2012%2F01%2Fstoring-session-data-in-cookies-problems-and-security-concerns-to-be-aware-of%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=php&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="wp-caption alignright" style="width: 310px"><a href="http://commons.wikipedia.org/wiki/File:ChocolateChipSmile.jpg"><img class="zemanta-img-inserted zemanta-img-configured" title="English: Peanut butter cookie with a chocolate..." src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/ChocolateChipSmile.jpg/300px-ChocolateChipSmile.jpg" alt="English: Peanut butter cookie with a chocolate..." width="300" height="301" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
<p>Back from my extended leave of absence, I&#8217;ll re-open the dusty cobwebbed depths of this blog to echo the sentiments of Paul Reinheimer in his recent article &#8220;<a href="http://blog.preinheimer.com/index.php?/archives/373-Cookies-dont-replace-Sessions.html">Cookies don&#8217;t replace Sessions</a>&#8220;. The topic is actually an old one since Ruby On Rails has adopted the strategy of storing application session data in cookies by default (take note, performance hounds). The purposes of storing sessions in userland cookies rather than the conventional &#8220;stick-it-on-the-filesystem/database&#8221; used by many apps is one of performance and a little obscuration. Cookie data can be accessed faster than hitting the filesystem/database plus it has the dubious ability to disguise the session-targeted programming language. Really though, PHP is assumed to be on all web servers so hiding its existence is a bit like trying to hide an elephant in a zoo. Hide it all you want &#8211; we still know there has to be one in there!</p>
<p>In exchange for speeding up session reading, storing session data in cookies has some fairly uncomfortable costs.</p>
<p>Now, developers are not unaware of the problems of storing potentially sensitive application data in plain text files on the user&#8217;s PC which users can manipulate, copy, and mangle to their (or the hacker&#8217;s currently fiddling with the user&#8217;s PC) heart&#8217;s content. It&#8217;s dangerous depending on just how much you rely on session data to drive other security rules or restrictions on business logic within the application. Technically, the reliance placed on sessions should be close to nothing &#8211; session data should drive the application towards other storage solutions for the really essential stuff and just stay around as a minimal identifier/stash of basic ID info. Such minimal information can be dumped, corrupted, or overwritten with the only cost being to perhaps require a user to login again when that happens. Stuffing a bank balance into a session, on the other hand, is one (very exaggerated!) example of the kind of data you should be shot for relying on a session for.</p>
<p>Programmers being programmers, it&#8217;s not rare to see sessions become a more intrinsically important storage location than it should be. In those cases, being able to manipulate the session data can become a problem and may give rise to exploitation scenarios where tampering with the stored data leads to some benefit for the manipulator. Obviously we want to make sure that that can&#8217;t happen even in scenarios where programmers may be a bit loose with where they store data. We don&#8217;t build frameworks and libraries for Gurus, we build them for all programmers &#8211; even the sometimes ignorant and under trained ones. This cookie stored session data is often coupled with the ability to encrypt that data. However&#8230;</p>
<p>As Paul Rainheimer remarks <a href="http://blog.preinheimer.com/index.php?/archives/373-Cookies-dont-replace-Sessions.html">in his article</a>, &#8220;Encryption is often viewed as a panacea for security problems, you sprinkle a little encryption dust around, and your problems dissolve&#8221;. This is an absolute truth in programming &#8211; programmers often view encryption as a solution without regard for one teeny tiny problem. If you encrypt a set of data for any purpose, even though it&#8217;s encrypted, the user (or the hacker hacking the user&#8217;s account) still has the data in some usable form!</p>
<p>With perfectly intact data, and even through it&#8217;s hidden by encryption, that data can be recycled simply by copying it to another machine. Depending on the data that is stored (which admittedly may require the hacker/user to figure out by doing actual work like finding your open source app on Github or breaking a developer&#8217;s fingers until they spill the beans), you can restore past data just by copying over a backup of a prior cookie or repeat a past transaction by continually reusing the original cookie it required. Paul offers a few trivial examples in his article.</p>
<p>Such reuse of data is known as a <a class="zem_slink" title="Replay attack" rel="wikipedia" href="http://en.wikipedia.org/wiki/Replay_attack">replay attack</a>. A scenario where even encrypted data can be constantly reused to give rise to a positive result &#8211; all without any need whatsoever to break the encryption. The antidote to this vulnerability is to ensure that all data sets are unique and can be used only once, i.e. you include a single-use nonce (some generated set of characters or bits) in the data which is updated whenever that data is used. This continually forces the update of the relevant digital HMAC signature and/or encryption result (even for the exact same data otherwise) in order to prevent any reuse of old data in a replay attack. Once a nonce is used, it&#8217;s discarded, and the old data can no longer be accepted by your application. Of course, the downside is that since the nonce must be single-use, you need to keep track of all <a class="zem_slink" title="Cryptographic nonce" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cryptographic_nonce">nonces</a> to ensure they are not accidentally used again. You will need a database, possibly using a nonce-included timestamp as a time limit so your storage requirements aren&#8217;t completed insane, which obviously means that just using the traditional database storage for sessions in the first place would have been a much better and simpler choice.</p>
<p>So, in summary, encryption prevents the reading of data but it does not prevent the reuse of existing data. For that to be prevented you need a nonce implementation. And, due to the complexity of using and tracking nonces, practically no cookie stored session solutions will actually offer nonce support because it would eliminate their speed advantage. Which means they are susceptible to replay attacks, which means they are dangerous tools to be swinging around blindly, which means that the old local session storage strategies are still far superior from a security perspective, which all means that you should avoid cookie stores like the damned plague and stick to the old, traditional but secure session storage strategies we already have unless you a) are crazy or b) trust your colleagues (and yourself) not to screw it up.</p>
<p>Even without the security concerns, there is also another less critical downside to storing sessions in cookies which is that cookies have a storage limit of around 4KB. No other storage solution for session data should have that problem but you need to be aware of it anyway as using encryption may push you there sooner than the base data size might suggest (encrypted data size is usually larger than the original data). While noting this, you should never really hit that limit unless you are storing data there that you likely shouldn&#8217;t be anyway!</p>
<p>So, cookie based session storage: It&#8217;s very fast but lethally insecure if you store the wrong type of data. If you&#8217;re going to use it, make sure you keep a tight rein on what data is being stored.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=a2ed3479-04a9-40fd-8d36-625c94f308fb" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2012/01/storing-session-data-in-cookies-problems-and-security-concerns-to-be-aware-of/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Zend Framework 2.0: Dependency Injection (Part 1)</title>
		<link>http://blog.astrumfutura.com/2011/10/zend-framework-2-0-dependency-injection-part-1/</link>
		<comments>http://blog.astrumfutura.com/2011/10/zend-framework-2-0-dependency-injection-part-1/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 14:05:17 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[di]]></category>
		<category><![CDATA[dic]]></category>
		<category><![CDATA[pimple]]></category>
		<category><![CDATA[zend\di]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=627</guid>
		<description><![CDATA[If you&#8217;ve been watching the PHP weather vane (we call it Twitter for short), you may have noticed a shift in Symfony and Zend Framework. Version 2.0 of both web application frameworks feature Dependency Injection Containers (DICs) as the primary means of creating the objects (and even Controllers) your application will use. This is an]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F10%2Fzend-framework-2-0-dependency-injection-part-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F10%2Fzend-framework-2-0-dependency-injection-part-1%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=dependency+injection,di,dic,pimple,zend%5Cdi&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 247px"><a href="http://commons.wikipedia.org/wiki/File:Codex_Gigas_devil.jpg"><img title="Illustration of the devil, page 577. Legend ha..." src="http://upload.wikimedia.org/wikipedia/commons/2/27/Codex_Gigas_devil.jpg" alt="Illustration of the devil, page 577. Legend ha..." width="237" height="398" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>If you&#8217;ve been watching the PHP weather vane (we call it Twitter for short), you may have noticed a shift in Symfony and Zend Framework. Version 2.0 of both web application frameworks feature Dependency Injection Containers (DICs) as the primary means of creating the objects (and even Controllers) your application will use. This is an interesting shift in a programming language that often stubbornly evaded adopting DICs to any great extent. In this mini-series of articles, I&#8217;ll take a look at the marvellous world of Dependency Injection as we run up to an examination of Zend Framework 2.0&#8242;s Zend\Di component in the next part.</p>
<h2>What is Dependency Injection (DI)?</h2>
<p>The short answer to this question is that Dependency Injection is a design pattern where, instead of dependent objects creating their dependencies internally, they instead define setters, constructor parameters or public properties which allow a user to &#8220;inject&#8221; dependencies from the outside into the dependent object and where such dependencies adhere to an expected interface.</p>
<p>If the definition sounds familiar, it&#8217;s because Dependency Injection is an obvious design pattern. As a programmer who knows how to use PHPUnit, you probably use the pattern every time you open an editor. So let&#8217;s quickly look at why the pattern is both obvious and ubiquitous.</p>
<p>Imagine a class implementation called Leprechaun. In writing the class, we realise we have a dependency on another class called PotOfGold. A naïve implementation would start out very simply with the Leprechaun object creating an instance of PotOfGold for use.</p>
<p>If you think this through, you may notice the problems. What if we want our Leprechaun to instead have a PotOfRareEarthElementsFromChina? What if we need to replace PotOfGold with a mock object during unit testing? What if another users locates a bug in PotOfGold and needs to replace it without editing the original class (since it&#8217;s under 3rd party version control)?</p>
<p>The answer to all these questions is to allow external parties to inject dependencies instead of relying on the object to create them internally. Based on our ridiculous example from above, we would define a setter called setPot(), and allow it to accept any object which implements a new Pot interface. Using an interface merely ensures the dependency that is set obeys some interface the dependent object is expecting.</p>
<p>That, in a nutshell, is why Dependency Injection is obvious. It&#8217;s a simple shuffling of creational responsibilities from within an object to some external agent which makes the dependent object more flexible, testable and amenable to the wisdom that Composition is preferred over Inheritance (i.e. injecting objects beats monkey patching!).</p>
<h2>Some External Agent</h2>
<p>In applying Dependency Injection, we eventually reach a state where all objects in a system are created by a mysterious external agent. What is this entity?</p>
<p>One possible candidate is whatever passes for a Controller in your framework based application. In Zend Framework, this would be an instance of Zend_Controller_Action. Our Controller, in this instance, would define an action method which would perform a necessary application task and create all the objects needed to perform that task. This makes a lot of immediate sense to programmers since allowing you to write Controllers with as little fuss as possible is a fundamental goal of any framework.</p>
<p>However, Controllers are objects! If you had a NewsletterController defining an emailAction method, you might expect that creating an instance of Zend_Mail inside that action is obvious (which it is). Think again! In Dependency Injection parlance, your Controller is a dependent object and an instance of Zend_Mail is one of its dependencies. This is no different from our Leprechaun example. If we create the Zend_Mail instance inside the Controller we get the same irritatingly stubborn question. How do we replace the Zend_Mail instance with an alternative, test double or monkey patched version containing an emergency bug fix?</p>
<p>Controllers, alas, are not the external agent we&#8217;re looking for to create objects. And yes, you really should be testing your Controllers <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>The next entity a level above Controllers can be loosely termed the Bootstrap. In Zend Framework 1, this started out as a relatively simple script to do just enough that you could start the FrontController and dispatch a request. In other words, Zend Framework traditionally did not offer a final external agent as needed for Dependency Injection. It left it to individual users to create something of their own or, as became inevitable, to just create objects in the Controllers themselves.</p>
<p>More recent Zend Framework versions offer Zend_Application, a method of bootstrapping that allowed users to define Resources, i.e. using a method or class which created an object (and injected its dependencies) and returned it on demand when it was needed by a Controller. This was the first consistent approach to handling object creation in ZF which effectively involved defining any number of Factory classes or methods in one location and passing the managing object (the Bootstrap) around the application wherever specific objects needed to be retrieved. In effect, this was a Dependency Injection Container. So, surprise, users of Zend Framework already have a DIC. An even lesser surprise: Zend Framework 2.0 will be no different.</p>
<h2>Dependency Injection Containers Are The Devil</h2>
<p>The concept of a Dependency Injection Container (DIC) is to act as a programmable object assembler. You take your DIC, tell it how to construct objects (including how to construct and inject their dependencies), pass the DIC to wherever it&#8217;s needed, and eventually ask it to create an object it knows about. This is not rocket science. DICs are simple animals to understand, however the devilish suspicion that PHP developers have for DICs is not rooted in what they do but how they do it and whether they make a developer&#8217;s life easier.</p>
<p>There&#8217;s a widely known belief that the Ruby language doesn&#8217;t need a DIC. I&#8217;ll use Ruby as an example because it has a few features PHP programmers can salivate over (like how it uses a new method for classes vs PHP&#8217;s new keyword making class subsitutions stupidly easy). One investigator of Dependency Injection from the Ruby world is Jamis Buck. For Ruby he wrote two DICs: Copland (a port of Java&#8217;s HiveMind) and Needle (it&#8217;s like Pimple on steroids which…defeats the purpose). After fighting Ruby for a few years, he finally gave up on trying to write a Ruby DIC and documented his thoughts on his blog in &#8220;<a href="http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming">LEGOs, Play-Doh, and Programming</a>&#8220;.</p>
<p>The core lesson from the article holds true even in PHP &#8211; by and large, complex DICs are a complete waste of time in most scenarios. Indeed, if you ever use a DIC and discover it requires just as many (if not more) lines of DIC code and configuration as it would to do the same thing in plain old PHP, you should start asking where the fabulous benefits have vanished to because it&#8217;s not delaying the onset of cramped finger muscles as advertised.</p>
<p>Most PHP developers understand this instinctively. Unlike Jamis, most PHP programmers probably won&#8217;t have a strong Java background. As a programming group, we&#8217;re less inclined to assume we need a special DIC blessed by the PHP Gods so we fall back to whatever strikes us as a simpler solution.</p>
<p>But here&#8217;s the rub &#8211; the simplest solution is itself a DIC.</p>
<p>In referring to Dependency Injection Containers as the devil, cursing their name, and blaming them as Java imports designed to make life more complex than needed, it&#8217;s easy to lose sight of the fact that such criticism is about the implementation of DICs and not their actual function. There is nothing wrong with having object assemblers &#8211; we use them all the time and call them Service Locators, or Factory Classes, or Zend_Application (Resources), or any of a dozen terms slightly different and probably not entirely accurate. Most of the time we&#8217;re trying to create a DIC without being aware of the term.</p>
<h2>Needles and Pimples (It&#8217;s Not What You Imagine)</h2>
<p>Jamis Buck hit the nail on the head back in 2004 with the creation of his Needle DIC Ruby. Instead of creating something inspired by Java that relied on static configuration and too many features, he realised that Ruby excelled (as does PHP to a growing degree &#8211; thank Closures) in expressing logic through a Domain Specific Language (DSL). The result was a DIC captured by a simple DSL &#8211; well, until he went and overcomplicated it (read his article).</p>
<p>You can see the exact same fundamental simplicity that a DIC is capable of in PHP. It&#8217;s a small so-tiny-you-won&#8217;t-believe-it DIC called <a href="http://pimple.sensiolabs.org/">Pimple</a>. Try calling that complex, hard, stupid or any other adjective you might instinctively think of when faced with the term &#8220;Dependency Injection&#8221;.</p>
<p>The core of Pimple is that you define object creations as closures. This immediately resolves a few traditional DIC problems. There&#8217;s no static configuration, you hand code all creation logic exactly once, and objects are named services you can recall and inject into other objects from your closure bodies. It basically takes everything you&#8217;d do in creating objects by hand and captures it all in one container. Other than the fact I hate arrays (my version uses object properties instead &#8211; it&#8217;s 50 lines; nobody was killed during its 5 minute development period), Pimple is like Dependency Injection itself &#8211; so blindingly obvious you may kick yourself.</p>
<p>Pimple proves that DICs are not the devil &#8211; they can be incredibly simple and useful tools if you can tame the urge to complicate it&#8217;s implementation.</p>
<h2>Then There Were Frameworks</h2>
<p>As you can probably see, making a strong case for DICs is not hard. Dependency Injection is obvious and omnipresent in PHP. Dependency Injection Containers can be a simple 50 line class you can write over a coffee break. The going gets tough when the simple notions we desperately want to cling to meet the complexity of PHP&#8217;s now standard tool: the application framework.</p>
<h2>Frameworks: Not Written By Monkeys</h2>
<p>As we&#8217;ve already covered, Zend Framework 1.0 covered off the external agent problem in Dependency Injection by creating Zend_Application. As Zend Framework 2.0 moves towards beta, it also needs a Dependency Injection Container to do similar heavy lifting. This time around, we called a spade a spade and the O&#8217;Phinney/Schindler hive mind wrote Zend\Di\DependencyInjector.</p>
<p>The DICs used by Symfony and Zend Framework are not like Pimple. Symfony&#8217;s DIC is driven by static configuration (preferably YAML for brevity). Zend Framework 2.0&#8242;s DIC is driven by a PHP API (no static configuration). Both have their own set of performance boosting measures to minimise any overhead in using a more complex DIC.</p>
<p>In the next part this mini series, we&#8217;ll take a deeper look at Zend\Di and see how it fares compared to Pimple or Symfony 2. In the meantime, I hope I&#8217;ve busted a few apprehensions you might have about using a DIC <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=fa9ed110-fe7b-48f2-98ea-faed2f39d902" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/10/zend-framework-2-0-dependency-injection-part-1/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Zend Framework Contributors Mailing-List Summary; Edition #2 (July 2011)</title>
		<link>http://blog.astrumfutura.com/2011/08/zend-framework-contributors-mailing-list-summary-edition-2-july-2011/</link>
		<comments>http://blog.astrumfutura.com/2011/08/zend-framework-contributors-mailing-list-summary-edition-2-july-2011/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 13:08:16 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[ZF-Summary]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=622</guid>
		<description><![CDATA[It&#8217;s been a busy month in Zend Framework land which I&#8217;ll blog about shortly so, after a few weeks of delay, here&#8217;s the July 2011 Summary of the zf-contributor&#8217;s mailing list. ZF2 Feedback Late June kicked off with this topic from Robert Basic with a set of notes on his experiences in getting started with]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F08%2Fzend-framework-contributors-mailing-list-summary-edition-2-july-2011%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F08%2Fzend-framework-contributors-mailing-list-summary-edition-2-july-2011%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=ZF-Summary&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 310px"><a href="http://commons.wikipedia.org/wiki/File:ZendFramework-Logo.png"><img title="Zend Framework logo." src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/ZendFramework-Logo.png/300px-ZendFramework-Logo.png" alt="Zend Framework logo." width="300" height="79" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>It&#8217;s been a busy month in Zend Framework land which I&#8217;ll blog about shortly so, after a few weeks of delay, here&#8217;s the July 2011 Summary of the zf-contributor&#8217;s mailing list.</p>
<h3>ZF2 Feedback</h3>
<p>Late June kicked off with this topic from Robert Basic with a set of notes on his experiences in getting started with ZF2 by migrating a ZF1 application. Adam Lundrigan noted, correctly, that a lot of &#8220;bleeding edge&#8221; code is not included in the main repository at this time and is distributed across contributor Github forks. He also raised the suggestion for a ZF2 Status Page. Derek Miranda voiced his agreement with Adam. Robert also agreed noting the difficulty in assessing the state of components.</p>
<p>Summary: ZF2 is scattered across multiple forks &#8211; be prepared to rely on notes such as Robert&#8217;s if jumping in at the deep end.</p>
<h3>Creating a 1.11.9 Hotfix Release</h3>
<p>A short note from Matthew Weier O&#8217;Phinney announced that a 1.11.9 hotfix release would be made to fix a number of backwards compatibility breaks introduced in 1.11.8. Issue tickets involved were ZF-11548, ZF-11550, ZF-10991 and ZF-10725.</p>
<p>Summary: It&#8217;s a maintenance release. It fixes stuff.</p>
<h3>Zend\Http and MVC Developments</h3>
<p>Ralph Schindler presented a document outlining a requirement list and the overall architecture of classes and interfaces for Zend\Http, noting work would commence on a prototype once any outstanding items suggested were cleared. Rob Zienart commented that the document indicated interfaces for Zend\Http Client and Server components and mentioned they needed proposals. Matthew responded that Zend\Http&#8217;s Server would deal with classes extending Zend\Service\Abstract such as SOAP and AMF but would not comprise a HTTP Server given it was covered by PHP 5.4. Anthony Shireman asked whether there were any Zend\Http Server plans or whether it was a &#8220;time will tell&#8221; situation. Matthew confirmed that that was the case given PHP 5.4 would include a HTTP Server and ZF2 could piggy back that implementation in offering a development server environment.</p>
<p>Summary: HTTP work continues. We&#8217;ll need it to communicate with all those big tubes connecting PCs.</p>
<h3>[Proposal] ActiveRecord Proposal</h3>
<p>Artur Bodera raised the proposal and offered to implement an ActiveRecord solution noting its benefits compared to Zend\Db. The proposal was published at <a href="http://framework.zend.com/wiki/display/ZFDEV2/ActiveRecord+-+Arthur+Bodera">http://framework.zend.com/wiki/display/ZFDEV2/ActiveRecord+-+Arthur+Bodera</a> with a working branch at <a href="https://github.com/Thinkscape/zf2/branches/ActiveRecord">https://github.com/Thinkscape/zf2/branches/ActiveRecord</a>.</p>
<p>Nicolas Bérard-Nault asked why it was necessary to reinvent the wheel instead of integrating with other existing and mature implementations. Artur responded that other solutions did not integrate with Zend Framework noting his proposal is built on Zend\Db from ZF2 and he wondered what was the point of Zend\Db\Table otherwise in the face of Doctrine or Propel. Peter Kokx responded to note that Zend\Db\Table implements the Table Data and <a class="zem_slink" title="Row Data Gateway" rel="wikipedia" href="http://en.wikipedia.org/wiki/Row_Data_Gateway">Row Data Gateway</a> patterns as distinct from ActiveRecord and that users shouldn&#8217;t interpret MVC as referring solely to ActiveRecord. Artur conceded that this was a good point but pressed his point that ActiveRecord was one tool which did on impose on any others available to Zend Framework using Zend\Db. Tomáš Fejfar voiced his support for adding ActiveRecord noting its value in simple use cases to get things done fast.</p>
<p>Ralph Schindler leaped to the rescue by noting that ActiveRecord is indeed planned for ZF2 and noting the significant work done to date on Zend\Db in his own feature branch. Artur Bodera welcomed the progress stating he would migrate his ActiveRecord solution over to the improved Zend\Db once complete.</p>
<p>Summary: We&#8217;re getting an ActiveRecord implementation for ZF2.</p>
<h3>ZF2 Docbook Sources Converted to <a class="zem_slink" title="DocBook" rel="wikipedia" href="http://en.wikipedia.org/wiki/DocBook">DocBook</a> 5</h3>
<p>Another short note from Matthew Weier O&#8217;Phinney informed the community that ZF2&#8242;s docbook formatted manual files had been migrated to Docbook 5. The community silently admired the completion of this task (nobody responded but I assume they silently admired all the same!). Matthew noted the README for manual generation would be updated and that Docbook 5 made certain tasks a lot easier.</p>
<p>Summary: ZF2 Manual will be written in Docbook 5, those using a visual XML editor may celebrate.</p>
<p>ZF2 Zend\Mail: To strip/validate or not to strip/validate (email adresses)</p>
<h3>Status of the Test Suite (ZF2)</h3>
<p>Keith Pope asked after the status of the Test Suite mentioning that phpunit.xml was mostly commented out, Zend\Di was not using the @group annotation for the test runner, and TestConfiguration.php was nearing 800 lines. He suggested that the configuration be spread into a conf.d setup (i.e. each configuration segment split into a separate file and all combined at runtime). Matthew responded noting the ease with which ZF2 tests could be run by passing the necessary directory to phpunit from the main /tests directory, and noted configuration may be pushed into phpunit.xml instead of the current PHP file. While expressing an interest in a conf.d setup, Matthew noted this would depend on support in PHPUnit.</p>
<p>Summary: Ignore runtests.sh and just use the stock phpunit commands for ZF2.</p>
<h3>Serious Question about Mcrypt</h3>
<p>Artur Ejsmont observed that the mcrypt filter calls srand() with a limited range of potential seeds thus suggesting it would impact on the security of the filter. Enrico Zimuel replied that the srand() is only used in limited circumstances (where a better source of randomness is not available) and that it&#8217;s not a serious problem since the encryption security is not wholly based on the initialisation vector (IV) that uses srand() on some platforms. Nevertheless, he did note that some improvements could be made.</p>
<p>Artur responded with a general query on the efficacy of using srand() and rand() to avoid collisions. Pádraic Brady responded that rand() was particularly bad noting you could create collision in a matter of minutes. Pádraic also noted that mt_rand() was far more effective but also not entirely random (as a graph of its output would prove) suggesting that it was advisable to use better random sources such as /dev/random and /dev/urandom where feasible. Enrico also noted the availability of openssl_random_pseudo_bytes().</p>
<p>Summary: Getting random bytes is a tricky business.</p>
<h3>ZF2 Zend\Code Bugfix</h3>
<p>Nick Belhomme mentioned he had been looking at Zend\Code which is used heavily by Zend\Di. He noted his first impressions that it should work well by being token based but also referred to his opinion that it was quite error prone and the unit tests were not satisfactory.</p>
<p>To explain his case, he used an example of a method signature accepting four type hinted object parameters noting this could fail to be analysed correctly due to the whitespace in the parameter list (after each comma) not being handled correct by the ParameterScanner. Nick noted he&#8217;d committed a fix using a short trim function to his own git fork.</p>
<p>Regarding the unit tests, Nick explained why the current unit tests were insufficient in testing parameters and suggested rectifying the test doubles to account for whitespace.</p>
<p>Summary: Zend\Code needs to build up a fuller test suite accounting for different coding styles.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=8e7d32eb-d621-4c1e-aa48-1b04fbf5d9ca" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/08/zend-framework-contributors-mailing-list-summary-edition-2-july-2011/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>What is Mutation Testing?</title>
		<link>http://blog.astrumfutura.com/2011/08/what-is-mutation-testing/</link>
		<comments>http://blog.astrumfutura.com/2011/08/what-is-mutation-testing/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 16:35:20 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Code Coverage]]></category>
		<category><![CDATA[Mutagenesis]]></category>
		<category><![CDATA[mutation testing]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[Test-driven development]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=618</guid>
		<description><![CDATA[Some time ago, in between working on Zend Framework, I booted up a couple of libraries that I really wanted to integrate into my workflow. Recently, I&#8217;ve been being putting these through the grindmill so they can be properly released and supported for public consumption across PEAR. Just as Mockery fell out of older work]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F08%2Fwhat-is-mutation-testing%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F08%2Fwhat-is-mutation-testing%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=Code+Coverage,Mutagenesis,mutation+testing,phpunit,Test-driven+development,unit+testing&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 310px"><a href="http://en.wikipedia.org/wiki/File:Mutant_Phase.jpg"><img title="The Mutant Phase" src="http://upload.wikimedia.org/wikipedia/en/thumb/6/64/Mutant_Phase.jpg/300px-Mutant_Phase.jpg" alt="The Mutant Phase" width="300" height="297" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>Some time ago, in between working on Zend Framework, I booted up a couple of libraries that I really wanted to integrate into my workflow. Recently, I&#8217;ve been being putting these through the grindmill so they can be properly released and supported for public consumption across PEAR. Just as Mockery fell out of older work on PHPMock, Mutagenesis will fall out of another project called MutateMe. This is a short introductory article as to what Mutagenesis will do and why. In other words, what the heck is Mutation Testing?</p>
<p>First, some background.</p>
<p>The most common means of measuring confidence in a test suite is the Code Coverage metric. Code Coverage essentially checks, on a per class basis, how many of the lines of code in the class are executed by a test suite and expresses this as a percentage. For example, a Code Coverage of 85% means 85% of the lines of code in a class was executed and 15% were not. The greater the number of lines of code executed, the more confidence one can presumably have that a test suite is doing its job, i.e. verifying class behaviour, preventing the introduction of bugs, supporting refactoring, and so on.</p>
<p>I have a huge and insurmountable problem with Code Coverage. For starters, my average Code Coverage is closer to 80% than the 90% expected of projects such as Zend Framework. The gap is explained by me not testing what I call &#8220;braindead&#8221; functions, i.e. methods which are either ridiculously simple, where a malfunction would quickly become self-evident, or which are marginalised (on the borders of deprecation). So Code Coverage actually increases the amount of work I need to do for very little gain and a lot of frustration.</p>
<p>Secondly, Code Coverage is easy to spoof or misinterpret. Since it’s a metric measuring the execution of source code, you need only…well…execute the source code. It&#8217;s a simple matter to construct a series of wonderfully useless tests to do just that and obtain a high Code Coverage result &#8211; it&#8217;s done all the time in my experience once someone&#8217;s patience in writing quality unit test runs out. It is particularly evident in cases where unit tests are written after the source code is completed &#8211; a still too common practice in PHP. The less villainous flipside is that certain nuggets of source code are fundamentally difficult to test. For example, a complex algorithm suffering from poor documentation may make composing a suitable unit test near impossible. The rollout of OAuth was filled with such examples.</p>
<p>This leads into my opinion of Code Coverage. I view the venerable Code Coverage metric as a near pointless exercise. While it may tell how much source code a test suite exercises, it tells you nothing about the actual quality of those unit tests. They could be good tests, sort-of-good tests or absolutely horrendous tests &#8211; Code Coverage will never tell you either way. I say near pointless because there are precious few alternatives. We need something to give us a reason to trust and have confidence in test suites and Code Coverage is easy to implement and has been a part of PHPUnit since forever. So, by and large, we make do. We measure Code Coverage just to make certain some kind of unit testing was performed.</p>
<p>Is there nothing better?</p>
<p>A good unit test serves a simple purpose. It verifies a behaviour of an object. In PHP, we&#8217;re more likely to verify umpteen million behaviours in a single test (count your assertions!) but we&#8217;ll let that slide. Since a test verifies behaviour, it follows that a test should fail when that behaviour is changed. If a test does not fail when class behaviour is changed, it also follows that the original behaviour was not fully tested, i.e. there is a gaping hole in our test suite whether due to a flawed or missing test that could allow bugs entry into our application. So, to really stick unit tests under a microscope to assess their quality and our confidence in them, we need to introduce changes into the source code under test and see if the unit test suite can or cannot detect them.</p>
<p>This process is known as Mutation Testing. Mutagenesis is a Mutation Testing framework for PHP 5.3+.</p>
<p>Mutation Testing, as you have probably surmised, is not a super-complex activity. You take a set of source code and compile a list of possible &#8220;mutations&#8221; that are likely to break the behaviour of the source code. Then, you apply one mutation to that source to create a &#8220;mutant&#8221;, i.e. a copy of the source code with the mutation change applied. Next, you run the source code&#8217;s test suite against the mutant and see if any tests fail. If a test fails, celebrate &#8211; the mutation was detected so your tests were, in this instance, adequate. If no test fails, curse the Gods &#8211; the mutation was not detected and you&#8217;ll need to figure out whether a new test is needed or an old one modified/corrected. Rinse and repeat the above for each mutation you&#8217;ve compiled.</p>
<p>Mutations are typically quite simple such as replacing operators, booleans, strings and other scalar values with either an opposing form or a random value. Expressions might also be reversed or driven to zero to give an opposing boolean or zero value. Making such minor changes seems like a minor irritation but behind every serious flaw in an application is one or more smaller contributing errors. If your test cases can detect the potentially contributing errors, then there&#8217;s an excellent chance it would detect the bigger ones anyway. This is known as the Coupling Effect in Mutation Testing.</p>
<p>Some of you will be vaguely aware of Mutation Testing. In terms of implementations, Ruby has heckler, Python has Pester, and Java has Jumbler, Jester and a couple of others. Those who prefer Microsoft&#8217;s technologies can use Nester. There&#8217;s a running ryhme apparent since so much is inspired by the original Jester framework for Java. To my knowledge, Mutagenesis will be the only Mutation Testing framework for PHP (though I sincerely wish I was wrong).</p>
<p>Examining those libraries, you eventually realize a few problems with Mutation Testing which explain its lack of popularity until relatively recently: performance is a concern and Mutation Testing requires a Human Brain to complete the process.</p>
<p>Performance is a concern because each mutation requires a test suite to be executed. Imagine a set of classes from which you extract 100 possible mutations, coupled with a test suite that takes 5 minutes to run. A basic Mutation Testing framework (e.g. Ruby&#8217;s heckler) would therefore take 500 minutes to complete a Mutation Testing session. That&#8217;s 8.3 hours of continuous Mutation Testing. Mutation Testing for Zend Framework would be very interesting <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>Similar to Jumbler for Java, Mutagenesis will utilise a few heuristics (shortcuts) to significantly improve performance without compromising results. We only need one single test to fail in order to rule that a mutation was detected and killed, so we can do a few things to boost performance:</p>
<p>1. Terminate the test suite on first failure/error or exception.<br />
2. Execute test cases in order of execution time ascending (fastest first; slowest last).<br />
3. Prioritise execution of last test case to detect a mutant to take advantage of same-class detection.<br />
4. Log which tests detect which mutations, and prioritise those associations in subsequent runs.</p>
<p>The effect of the above is to speed up Mutation Testing by a significant degree. The final heuristic ensures that for gradually changing source code and tests, the first Mutation Testing process might take a while but subsequent runs will be significantly faster making them far more usable in a Test-Driven Development setting. Mutation Testing is best served with a healthy dose of efficiency.</p>
<p>The second reason for its lack of popularity is that Mutation Testing can&#8217;t analyse the logic of the source code under test. For example, an expression might accept any integer less than 10 to evaluate to TRUE. If the input from another class were 7, and a mutation were generated to swap this for a 9, then the associated unit test would still pass (the mutation of switching 7 for 9 still allows the &lt;10 expression evaluate to TRUE). If you recall, if a mutant passes a test suite than we assume either the presence of a flawed test or the lack of a suitable test. Obviously, as the above suggests, this isn&#8217;t always the case. Mutation Testing can and often will report false positives.</p>
<p>Ruling out false positives, coupled with the need to improve test suites to detect more mutations, makes Mutation Testing a source of extra work. Who likes extra work least? Programmers, especially the lazy kind <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>Mutation Testing is not a far fetched idea. The principles are sound and it beats the pants off Code Coverage when it comes to measuring what confidence we can have in our testing suites. It is still hampered, as a methodology, by the lack of good implementations in other programming languages. Mutagenesis, by adopting implementation heuristics from Java&#8217;s Jumbler, should avoid that fate and offer a decent framework in PHP that performs as well as can be expected.</p>
<p>Once it&#8217;s released…of course <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . Mutagenesis is in development but should see a fresh release in a couple of weeks alongside Mockery. I&#8217;ll be looking forward to seeing how people perceive it. Mutation Testing has zero presence in PHP to date but having something to complement Code Coverage can&#8217;t do any harm!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=fa73b631-bedb-4ef0-ac5e-aa59b21aca6a" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/08/what-is-mutation-testing/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Out With The Old, In With The New: Original MySQL Extension Heading For Retirement?</title>
		<link>http://blog.astrumfutura.com/2011/07/out-with-the-old-in-with-the-new-original-mysql-extension-heading-for-retirement/</link>
		<comments>http://blog.astrumfutura.com/2011/07/out-with-the-old-in-with-the-new-original-mysql-extension-heading-for-retirement/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 12:48:05 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=596</guid>
		<description><![CDATA[When we use the term PHP, we are often silently associating it with the abbreviation LAMP (that&#8217;s Linux, Apache, MySQL and PHP just in case you don&#8217;t recall). MySQL has been our bread and butter in PHP for over a decade; an old friend, accomplice and partner in crime. This was made possible with the]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F07%2Fout-with-the-old-in-with-the-new-original-mysql-extension-heading-for-retirement%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F07%2Fout-with-the-old-in-with-the-new-original-mysql-extension-heading-for-retirement%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=MySQL&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 310px"><a href="http://en.wikipedia.org/wiki/File:MySQL.svg"><img title="MySQL" src="http://upload.wikimedia.org/wikipedia/en/thumb/6/62/MySQL.svg/300px-MySQL.svg.png" alt="MySQL" width="300" height="155" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>When we use the term PHP, we are often silently associating it with the abbreviation <a class="zem_slink" title="LAMP (software bundle)" rel="wikipedia" href="http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29">LAMP</a> (that&#8217;s Linux, Apache, <a class="zem_slink" title="MySQL" rel="homepage" href="http://www.mysql.com">MySQL</a> and PHP just in case you don&#8217;t recall). MySQL has been our bread and butter in PHP for over a decade; an old friend, accomplice and partner in crime. This was made possible with the MySQL extension. Indeed, you can scarcely find a basic nuts and bolts PHP tutorial that doesn&#8217;t use MySQL. Which is probably why it&#8217;s a good idea to give it a huge going away bash (and make sure it finds the exit afterwards and catches a cab to oblivion!). We&#8217;ve since seen replacements like the <a href="http://ie.php.net/mysqli">MySQL Improved extension</a> (mysqli) and <a class="zem_slink" title="PHP" rel="homepage" href="http://www.php.net/">PHP Data Objects</a> (PDO). These are simply better from the additional features each adds to their integration in higher level libraries such as <a class="zem_slink" title="Doctrine (PHP)" rel="homepage" href="http://www.doctrine-project.org">Doctrine</a>.</p>
<p>But, as with any basic change to a successful formula, there was bound to be some controversy at <a href="http://news.php.net/php.internals/53966">the mere suggestion of deprecating our old friend</a> (even if preceded by an extended period of educating users on the well established replacements). <a href="http://www.phpclasses.org/blog/post/153-The-Plot-to-Kill-PHP-MySQL-Extension.html">Manuel Limos</a> and <a href="http://www.prodigyproductionsllc.com/articles/programming/php/no-more-php-mysql-extension/">Lucas Darnell</a> have both written blog posts indicating what a bad idea this could be. Their issues are understandable. Once the E_DEPRECATION notices start flying applications that have existed for years (and years) will appear to implode leaving behind a long line of irritated people who may need to hire a PHP programmer to fix stuff. This obviously imposes a cash cost across thousands (probably an underestimation <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) of businesses. This may lead to hosting services deferring adoption of the PHP version carrying the deprecation by months if not years. Lucas also raised an interesting point that with so much literature, including books, carrying example after example of (often insecure in my opinion) MySQL extension use, user adoption and education may suffer a great deal.</p>
<p>In a riposte to Manual Lemos, <a href="http://neurobashing.com/2011/07/15/theres-a-reason-php-lives-in-the-past/">Gregg Thomason perhaps illustrates best</a> why even the feared disadvantages may be worth the cost. MySQL is a historical relic from a past PHP is trying to leave behind. It&#8217;s old, doesn&#8217;t do a lot to support security and it needs to go. I agree. Gregg says &#8220;&#8230;this is a forward-thinking business and our job is to invent the future.&#8221; Let&#8217;s go invent and improve that future &#8211; if nothing else it might make Anonymous&#8217; job finding SQL injections at every company they squint at a little harder <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .</p>
<p>PHP is not a weirdo stagnant programming language used by amateurs who don&#8217;t have sufficient brain cells to learn Java, Ruby or Python. That&#8217;s the common misconception based largely on two obvious factors: PHP is so amazingly popular and easy to learn that any innocently ignorant person with half a brain cell can write a fabulously insecure application (the examples just keep coming and coming) and, secondly, PHP is a bit on the ugly side and not a &#8220;true object oriented language&#8221; because it uses functions instead of methods. PHP is actually used by hardcore professionals who build great secure applications and that community has left the original MySQL extension by the wayside in favour of object oriented solutions where MySQL related functions are buried deep behind a wall of classes in their preferred database interaction solution, such as PDO or Doctrine. It&#8217;s about time we brought everyone else up to speed with that reality.</p>
<p>While &#8220;deprecation&#8221; may attract all the attention, let&#8217;s remember that pushing the alternatives by any possible means is a great idea. <a href="http://news.php.net/php.internals/53966">Philip Olson&#8217;s proposal</a> on how to encourage users to move away from the original MySQL extension has a lot of merit and is well worth persuing. We need to let go of the past eventually to keep PHP moving into the future.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=e95d0856-c5e4-4f2f-80db-9e06dba29ca9" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/07/out-with-the-old-in-with-the-new-original-mysql-extension-heading-for-retirement/feed/</wfw:commentRss>
		<slash:comments>94</slash:comments>
		</item>
		<item>
		<title>How Would You Engineer A PEAR2/Pyrus Distribution Architecture?</title>
		<link>http://blog.astrumfutura.com/2011/06/how-would-you-engineer-a-pear2pyrus-distribution-architecture/</link>
		<comments>http://blog.astrumfutura.com/2011/06/how-would-you-engineer-a-pear2pyrus-distribution-architecture/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 13:44:57 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[Pyrus]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=581</guid>
		<description><![CDATA[I was recently accused on the Zend Framework Contributors mailing list of having &#8220;strong feelings&#8221; towards Pyrus (i.e. the PEAR Group&#8217;s Installer/Packager for PEAR2) and not in a positive way. It&#8217;s a fair description. PEAR is, putting it lightly, a very old architecture which makes it very resistant to change. With the idea of PEAR2]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F06%2Fhow-would-you-engineer-a-pear2pyrus-distribution-architecture%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F06%2Fhow-would-you-engineer-a-pear2pyrus-distribution-architecture%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=pear,Pyrus&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 240px"><a href="http://commons.wikipedia.org/wiki/File:202clapps.jpg"><img title="Clapps Favorite pear, British Colombia, Canada..." src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/202clapps.jpg/300px-202clapps.jpg" alt="Clapps Favorite pear, British Colombia, Canada..." width="230" height="200" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>I was recently accused on the <a class="zem_slink" title="Zend Framework" rel="homepage" href="http://framework.zend.com/">Zend Framework</a> Contributors mailing list of having &#8220;strong feelings&#8221; towards Pyrus (i.e. the PEAR Group&#8217;s Installer/Packager for PEAR2) and not in a positive way. It&#8217;s a fair description. PEAR is, putting it lightly, a very old architecture which makes it very resistant to change. With the idea of PEAR2 and Pyrus, I had hoped to see a renewal &#8211; the advancement of a PEAR architecture for the 21st Century. Instead, and this is just my opinion, PEAR2/Pyrus were a relatively simple iteration on a very old theme.</p>
<h2>A Ranting We Shall Go</h2>
<p>Now, I may be biased since I gave up on PEAR becoming PHP&#8217;s core distribution mechanism after I found myself using alternative strategies for hosting and deployment. This is not to say PEAR is not useful for everyone. It is &#8211; just not in my specific case when developing/testing/deploying applications. It still remains a good distribution means regardless by virtue of its ubiquitous installation with PHP.</p>
<p>I surprised even myself, however, with my vehement outcry over the idea of adopting Pyrus as Zend Framework 2&#8242;s package distribution method, lambasting both it and the PEAR concept of distribution in equal measures while piling up questions on Pyrus&#8217; status (currently released in alpha) and suitability in the near term. That thread showed a fairly divided sentiment. Once I jokingly threatened to mow down my zombified colleagues with a minigun, I figured it was time to go forth and rant (miniguns are too expensive for these recessionary times).</p>
<p>If the PEAR ecosystem has a failing, it is one of staggered evolution. Over time it has picked up additional features tacked on top of a base model. The classic example is the use of Channels (to support multiple repositories) that has more recently prompted calls for the use of a Channel Aggregator to avoid the use cost in locally managing a channel registry or even hosting a Channel. This is the way of many PEAR features. They each do something incredibly useful but do it in a way that has many developers looking for a better approach &#8211; usually to discover the better approach requires breaking compatibility.</p>
<p>My vehemence in the afore mentioned mailing list was down to a simple case of disappointment. We all deal with PEAR because we have it, we know it, and have done so for years. Seeing PEAR2 and Pyrus take the incremental improvement route without apparently doing anything to change the core experience seemed…pointless. It improved a lot of what PEAR already did without actually doing very much different. All the same advantages, disadvantages, features and lack thereof were present and accounted for with a handful of nice headline changes (e.g. we now have package signing capability). What exactly was the purpose of rewriting the entire toolchain if not to seize the opportunity to answer the accusations of those who doubt PEAR is even relevant these days &#8211; by making it the single most relevant development in PHP today?</p>
<h2>One Possible Path Forward</h2>
<p>Since this is a brain dump post, as much to gather my own throughts in one place as anything else, feel free to call me bat shit crazy. There are days even I think that. Below I&#8217;ve raised what I perceive as problems in the PEAR/Pyrus system, obviously from a personal perspective, and possible solutions under the categories of Packaging, Distribution, Installation and Usage. I&#8217;ve tried to avoid getting into technical details &#8211; broad strokes will suffice for now. For your sanity, only the Packaging and Distribution areas are presented today. I will add a similar post for Installation and Usage later in the week. First one to mention &#8220;TL:DR&#8221; gets a minigun round to the head (will have to make do with throwing it at you until I can scrape more cash together for the hardware). To avoid any confusion, I use the terms PEAR and Pyrus to refer to the entire workflow from package generation to end usage for each respectively.</p>
<h2>Packaging</h2>
<p>The packaging of source code for PEAR is performed using the PEAR/Pyrus Installer coupled with a Package Definition (i.e. package.xml) to create a distributable <a class="zem_slink" title="Archive file" rel="wikipedia" href="http://en.wikipedia.org/wiki/Archive_file">archive file</a>. Pyrus utilises a slightly more friendly Package Definition by also allowing for some elements of the definition to be defined in files other than package.xml (e.g. for setting up a changelog file or version numbers). The basic goal of this Package Definition is to have at least one XML file which tells PEAR/Pyrus which files to package, while role a file has (code/docs/tests), where each file goes in a relative filesystem, optionally the file&#8217;s MD5 hash, and a set of metadata like the package name, changelog, version, dependencies, etc. Using Pyrus offers the additional feature of being able to cryptographically sign packages, use a larger number of archive formats including PHAR, and bundle certain package dependencies internally.</p>
<h3>Problems:</h3>
<p>The main problem with the current Package Definition is that it often must be generated by a separate tool since it&#8217;s XML (it&#8217;s that thing everyone used before discovering YAML/JSON), and must explicitly list every file and piece of data within that format (with the exception of Pyrus which allows specifically formatted files to carry version and changelog information among other nuggets) optionally with each file&#8217;s digest hash. Even the Pyrus improvements still require specific files using specific formatted text and/or file names. Using XML just ends up imposing extra work to maintain package details unless you are lucky enough to have a small stable enough package.xml that it can be manually maintained rather then persistently needing generation. A minor aesthetic detail is that XML is harder to read.</p>
<p>Secondly, packages are therefore bound to their archiving restraints. Since package.xml generation is tied to a secondary process, installing from source code may not be feasible whether performed on a local git clone or similarly automated from a remote source where the remote package.xml may well be out of sync with the actual source code or where it may not even exist.</p>
<h3>Possible Solutions:</h3>
<p>The one solution that keeps occuring to me is to simply make a Package Definition programmable, i.e. a small consumable low-maintenance PHP script. Using native PHP, one can create ether a generic array, or a newfangled closure, which can be executed through PHP to populate all the necessary data for a Package Definition for consumption by a package installer.</p>
<p>Since I&#8217;ve dabbled a bit, here&#8217;s what such a Package Definition could look like:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.astrumfutura.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.astrumfutura.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.astrumfutura.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.astrumfutura.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><pre class="de1"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="re0">$package</span> <span class="sy0">=</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="re0">$s</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">name</span> <span class="sy0">=</span> <span class="st_h">'Overlord'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">authors</span> <span class="sy0">=</span> <span class="st_h">'Padraic Brady, Sauron[sauron@mordor.me]'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">version</span> <span class="sy0">=</span> <span class="st_h">'0.0.1-dev'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">api_version</span> <span class="sy0">=</span> <span class="st_h">'0.0.1-dev'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">summary</span> <span class="sy0">=</span> <span class="st_h">'Monitoring library for Hobbit Detector 1.0'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">description</span> <span class="sy0">=</span> <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span>__DIR__ <span class="sy0">.</span> <span class="st_h">'/description.txt'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">homepage</span> <span class="sy0">=</span> <span class="st_h">'http://en.wikipedia.org/wiki/Sauron'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">changelog</span> <span class="sy0">=</span> <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span>__DIR__ <span class="sy0">.</span> <span class="st_h">'/changelog.txt'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">files</span><span class="br0">&#91;</span><span class="st_h">'php'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'library/**/*.php'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">files</span><span class="br0">&#91;</span><span class="st_h">'tests'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'tests/**/*.*'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">files</span><span class="br0">&#91;</span><span class="st_h">'ignore'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'*.project'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">files</span><span class="br0">&#91;</span><span class="st_h">'bin'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'scripts/overlord.bat'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">include_path</span> <span class="sy0">=</span> <span class="st_h">'Overlord/Monitor/'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">dependencies</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'PHP[&gt;=5.3.1]'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">dependencies</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'Pear[&gt;=1.6.5]'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">dependencies</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'MutateMe[0.5.0]'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">dependencies</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'ext/runkit'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">optional_dependencies</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'ext/eyeofsauron'</span><span class="sy0">;</span>
    <span class="re0">$s</span><span class="sy0">-&gt;</span><span class="me1">license</span> <span class="sy0">=</span> <span class="st_h">'New BSD'</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span></pre></div></div></div>
<p>I&#8217;ll assume PHP 5.4 will have some sort of short array notation to cut down the array size. Well, let&#8217;s hope so <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Would be nice to reduce the line count more. Yes, I did indeed borrow the idea from elsewhere <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>This has a few advantages. No XML to maintain. No need to keep an XML Package Definition synced up for every file change in a VCS. No need for secondary XML generation tools or build tool plugins. Supports downloading files from remote herarchical sources and not just archives (including any VCS source). Developers are already used to versioning build scripts from tools like Phing (just not the end products which are usually ignored whereas package.xml is not). Being plain old PHP, it can be just as complex or as minimal as you want and anyone with basic PHP knowledge can write one.</p>
<p>One can still generate signable archive files using this approach &#8211; the point is to increase the kind of installation sources that can be used rather than replace existing ones. In place of signable packages, for those requiring the security, other package files could be limited to download over <a class="zem_slink" title="HTTP Secure" rel="wikipedia" href="http://en.wikipedia.org/wiki/HTTP_Secure">HTTPS</a>. For example, Github offers git read-only access via HTTPS for all repositories as standard.</p>
<h2>Distribution</h2>
<p>In order to distribute source code using PEAR/Pyrus, you need to make use of either a PEAR Channel or a standalone archive download (i.e. a downloadable tarball). A Channel is basically a whole bunch of XML files served up for access as a REST API. Using a Channel, you can upload packages to the Channel host, update the XML files, and publicise your Channel URI so users can discover your Channel and install your packages.</p>
<h3>Problems:</h3>
<p>PEAR (PHP Extension and Application Repository) was originally founded to serve as a central package distribution channel. For various real and imagined reasons, the concept of a central repository did not succeed in PHP and instead developers insisted on using alternative means. This was aggravated even further by the arrival of frameworks like Zend Framework offering discrete components not originally served over a PEAR Channel at all. PEAR Channels were introduced to allow anyone host their own distinct PEAR Channel as one of those means.</p>
<p>The PEAR Installer has only ever shipped with the main PEAR Channels pre-registered. All other Channels needed to be manually located before use &#8211; usually by referring to the packaged library&#8217;s documentation. Since all Channels are independent entities, there is no global lookup point for querying package details, dependencies and availability. There is also no scope for true package name uniqueness (technically this is accomplished by requiring all packages (except core-PEAR ones) are prefixed with a Channel alias term, e.g. mychannel/MyPackage).</p>
<p>The generation of the REST API, which was the backbone of a Channel, was also complex (the release of Pirum by Fabien Potencier has gone a long way towards simplifying this). Obviously, Channels are also tied to the concept of archive packages and cannot operate directly with a VCS like git. There is a workaround possible for Github using Github Pages to host the REST API.</p>
<p>As alluded to, the REST API is itself a complex graph of XML files that requires a generation tool to manage initial setup and package updates.</p>
<h3>Possible Solutions:</h3>
<p>The best concept to gain early traction was that of a Channel Aggregator expressed by Stuart Herbert. Sadly, I haven&#8217;t seen much more action on that front. In commenting on that idea, I considered it a move towards a decentralised distributed Channel mechanism (mouthful of gibberish, I know!). Here&#8217;s a couple of thoughts on how this could work:</p>
<p>The players would include a Package Authority, a Channel Aggregator (any number of them), and Channels (optional).</p>
<p>The Package Authority would be a centralised location basically for reserving package names and ensuring there is a point of reference and authority to prevent package name duplication and to manage ownership of such. It&#8217;s possible this could also be developed with additional purposes but let&#8217;s keep it simple. This would help, primarily, in removing the need for Channel prefixes on package names and preventing package name confusion. For security reasons, the Package Authority would associate a package name to a specific URI representing a download source (e.g. a PEAR Channel or Git URI)</p>
<p>Channel Aggregators are the more complex beasts. They may be utilised by Channel operators to distribute Package metadata to end-users on demand. The Aggregator would track available packages at source, their basic details, their available versions, and information on the location of host Channels, version control systems, and Package URIs and so forth. In effect, the Aggregator might well replace Channels for many purposes &#8211; and potentially eliminate one more source of work in distributing source code using PEAR/Pyrus.</p>
<p>The ideal scenario here is that any PEAR/Pyrus Installer would pre-register a couple of well-maintained Aggregators saving the users and package distributors the annoyance of dealing with Channels altogether. Hence, we&#8217;re back to a core Channel of sorts but with control of package/source hosting decentralised to individual developers. Again, Aggregators could easily repurpose themselves as package hosters if they wish (such as Pearfarm are doing) though this would be entirely optional.</p>
<p>Channels, as suggested, could well be optional. Use an Aggregator instead and register either a package URI, git repository, or anything else so long as it lets you download the package files (and the PHP programmable Package Definition <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). Painless hosting? Maybe.</p>
<p>I will point out this would require at least one authentication in the system. You&#8217;d need a Package Authority account to allow for reserving a package name and perhaps transferring it between maintainers. The Aggregator may operate without authentication since it acts much like any aggregator based on your source data (and one would hope a few simple crosschecks with the Package Authority to ensure it&#8217;s not unwittingly aggregating false data from the hackers <img src='http://blog.astrumfutura.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Package/source hosters could ping the Aggregator as a hint to update its date in a more timely manner.</p>
<p>I won&#8217;t touch the issue of who gets to reserve the package name &#8220;DB&#8221;. The Package Authority may need to enforce specific rules against overly generic names on a common sense basis.</p>
<p>I think that&#8217;s enough for a Monday read (you&#8217;ll all need enough brain capacity to finish out the week!). Feedback is, as usual, welcome. If anyone has a pre-existing solution or one in planning along these or similar lines, drop a comment!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=cae7e9b5-25ab-4fba-85ae-8e7173884dbb" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/06/how-would-you-engineer-a-pear2pyrus-distribution-architecture/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>CodeIgniter 2.0.2: Cross-Site Scripting (XSS) Fixes And Recommendations</title>
		<link>http://blog.astrumfutura.com/2011/05/codeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations/</link>
		<comments>http://blog.astrumfutura.com/2011/05/codeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations/#comments</comments>
		<pubDate>Tue, 10 May 2011 11:43:02 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Cross-Site Scripting]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Vulnerability (computing)]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=562</guid>
		<description><![CDATA[As many of my readers know, I have a keen dislike for regular expression based HTML sanitisation. Regular expressions simply do not understand HTML&#8217;s nested nature and the numerous possible HTML/CSS standards it must abide by. The result is that far too many developers try to program this understanding (and unfortunately their lack of comprehensive]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F05%2Fcodeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F05%2Fcodeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=Cross-Site+Scripting,JavaScript,php,Regular+expression,Security,Vulnerability+%28computing%29&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>As many of my readers know, <a href="http://blog.astrumfutura.com/2011/03/regex-html-sanitisation-off-with-its-head/">I have a keen dislike for regular expression based HTML sanitisation</a>. Regular expressions simply do not understand HTML&#8217;s nested nature and the numerous possible HTML/CSS standards it must abide by. The result is that far too many developers try to program this understanding (and unfortunately their lack of comprehensive understanding) into home grown sanitisers using as little code and tests as possible.  It&#8217;s a horrendous and reprehensible practice that has created a large field of so-called sanitisers and XSS cleaners which are riddled with obvious vulnerabilities despite all their sincere and utterly false claims to the contrary. The perception of safety they create is almost always a fantasy. As I&#8217;ve said before, this serves only one purpose &#8211; to lend support to claims that PHP is insecure. And why disagree given PHP&#8217;s prominence on the internet and this continuing refusal by developers to just do the right thing and use a secure solution that really does work?</p>
<p>Since I&#8217;ve completed my research into a broad set of these, for now, I&#8217;ll close with a final example given its widespread usage, confusing documentation and lack of a clear disclosure to date of security vulnerabilities.</p>
<p>On April 7, EllisLab <a href="http://codeigniter.com/news/codeigniter_2.0.2_released/">released CodeIgniter 2.0.2</a> as a security maintenance release prompted by a report I sent to EllisLab shortly before St. Paddy&#8217;s Day (around mid-March). That report indicated the expected response and my own disclosure policy. This blog post is being published in accordance with those. The disclosure to date of the vulnerabilities afflicting previous CodeIgniter versions is mentioned only in <a href="http://codeigniter.com/news/codeigniter_2.0.2_released/">the CodeIgniter 2.0.2 news release</a> (from April 7) as follows:</p>
<blockquote><p>An update to both CodeIgniter Reactor and CodeIgniter Core (v 2.0.1) was released today. This is a security maintenance release and is a recommended update for all sites. The security fix patches a small vulnerability in the cross site scripting filter.</p></blockquote>
<p>EllisLab&#8217;s news release for CodeIgniter 2.0.2 makes mention of &#8220;a small vulnerability&#8221;. This small vulnerability is mentioned no where else (not even the actual changelog for 2.0.2). In reality, I reported seven distinct vulnerabilities across two classes. These vulnerabilities might allow an attacker to inject arbitrary HTML, CSS or Javascript, i.e. <a class="zem_slink" title="Cross-site scripting" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross-Site Scripting</a> (XSS) into an application&#8217;s output. It would be nice if, in the future, EllisLab aim for more accuracy in their news releases and disclosed both the number and nature of the security vulnerabilities fixed in their release changelogs.</p>
<p>Users of CodeIgniter 2.0.x and 1.7.x are strongly urged to upgrade to CodeIgniter 2.0.2 (or later) as soon as possible to avail of these critical security fixes.</p>
<p>In addition, users are urged to follow some basic steps when writing or updating CodeIgniter applications:</p>
<ol>
<li>Escape ALL data being injected into views using PHP&#8217;s htmlspecialchars()  function, remembering to pass the <a class="zem_slink" title="Character encoding" rel="wikipedia" href="http://en.wikipedia.org/wiki/Character_encoding">character encoding</a> being used as the  third parameter. A helper function may be useful to keep the typing to a  minimum.</li>
<li>Use <a href="http://htmlpurifier.org/">HTMLPurifier</a> when you need to sanitise HTML data or user input such as HTML  comments, HTML emails, or RSS/Atom content (basically any HTML you do  not explicitly generate yourself!).</li>
<li>Ensure that all HTML pages are served with a valid Content-Type HTTP  header and/or a meta tag equivalent which also declares the charset for  that page. Note that HTML5 offers a separate charset element for this  purpose. This helps prevent character encoding based XSS attacks by  informing the browser of the correct character encoding to use.</li>
<li>Ensure that all views/templates distributed by third parties are  likewise reviewed to ensure they utilise proper escaping and XSS  sanitisation.</li>
</ol>
<p>CodeIgniter is one of the most prominent &#8220;micro frameworks&#8221;, web  application frameworks that prosper by offering their users unparalleled  simplicity. It is unusual as a framework in that it does not make any  reference to standard escaping mechanisms for views/templates such as  the PHP htmlspecialchars() function anywhere in its source code,  examples or documentation. This may create the unfortunate impression  that users should instead filter input using an XSS filter function in  the CI_Security class and do nothing on output. Users taking this  approach may be particularly at risk from these security  vulnerabilities.</p>
<p>My recommendation to the CodeIgniter developers, as documented in my original report, is to deprecate and remove the CI_Security class&#8217; XSS filter. Responsible vendors should never persist in distributing and advocating the use of insecure software. I also urge them to revise their documentation to ensure that best security practice is noted in the area of writing views/templates and offer a shortcut function to an escaping mechanism for HTML output to standardise and ease its use by members.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=d5f09c5c-8aa9-4124-8657-11fda04dc9f5" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/05/codeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations/feed/</wfw:commentRss>
		<slash:comments>154</slash:comments>
		</item>
		<item>
		<title>Private vs Protected Methods: The Debate That Never Ends</title>
		<link>http://blog.astrumfutura.com/2011/03/private-vs-protected-methods-the-debate-that-never-ends/</link>
		<comments>http://blog.astrumfutura.com/2011/03/private-vs-protected-methods-the-debate-that-never-ends/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 19:14:52 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Nanny state]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=509</guid>
		<description><![CDATA[As a new generation of PHP web application frameworks start establishing beach heads in preparation for an all out war for mindshare, I&#8217;ve been contemplating some of the key changes we&#8217;re seeing emerge that may gain traction over time. Today, I just thought to share my thoughts about private methods vs protected methods. Something that]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F03%2Fprivate-vs-protected-methods-the-debate-that-never-ends%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F03%2Fprivate-vs-protected-methods-the-debate-that-never-ends%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=Nanny+state&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 174px"><a href="http://www.flickr.com/photos/62558594@N00/2709234219"><img title="Nanny State, Secret Garden Party 2008" src="http://farm4.static.flickr.com/3190/2709234219_4e425c4aa2_m.jpg" alt="Nanny State, Secret Garden Party 2008" width="164" height="240" /></a><p class="wp-caption-text">Image by chrisjohnbeckett via Flickr</p></div>
</div>
<p>As a new generation of PHP web application frameworks start establishing beach heads in preparation for an all out war for mindshare, I&#8217;ve been contemplating some of the key changes we&#8217;re seeing emerge that may gain traction over time. Today, I just thought to share my thoughts about private methods vs protected methods. Something that has impacted on Doctrine 2 and Symfony 2. And every other piece of PHP code since PHP 4 came along.</p>
<p>Doctrine and Symfony have <a href="http://groups.google.com/group/symfony-devs/browse_thread/thread/58a0d015622c13cb#">adopted a practice whereby all methods are flagged as private</a> unless there are compelling reasons to the contrary (i.e. they are necessarily part of a public API, or form part of an abstract implementation). There is an allowance for appealing that a method be switched from private to protected on a case by case basis.</p>
<p>I&#8217;m not a big fan of private methods. I&#8217;m in a state of persistent internal conflict over them, in fact. At this point in time, I am in favour of protected methods over private methods.</p>
<p>On one hand, there&#8217;s the traditional idea that private methods must never be used outside the current class to prevent interaction with and dependencies on highly unstable units of behaviour. This is a common need arising out of refactoring where non-public methods may vanish, move classes, get renamed or find themselves saddled with different behaviour. These non-public methods are inherently unstable. There is no getting away from that. While this is perfectly normal during development, it can become an irritating concept downstream if you are depending on such implementation details in your own work.</p>
<p>On the other hand, non-public methods contain the meat of any class &#8211; the implementation specifics. Using <a class="zem_slink" title="Inheritance (object-oriented programming)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Inheritance_%28object-oriented_programming%29">Inheritance</a>, you can extend classes containing this implementation code at very little cost if they are carried by protected methods. This usually tends to make life easier, promotes source code reuse, allows for bug and security fixes ahead of schedule (assuming there it&#8217;s not one of those lost bugs that will never be fixed), dependence on existing implementation facets, etc. This all does, however, carry the risk of creating a lot of brittle code that may break at the next update due to the effects of refactoring.</p>
<p>These two strands of thought have been in combat for a long time in many programming languages. It&#8217;s no different in PHP. Many developers are likely under the delusion that protected methods constitute a protected API, i.e. that there is a rule that protected methods must retain backwards compatibility across updates. There is no such rule. There is, however, a form of peer pressure to conform to these delusions. Ask any set of developers about backwards compatibility and there&#8217;s probably a fair chance that the majority will insist that it applies to protected methods. Unfortunately, this is in direct violation of the principles behind refactoring. In other words, it&#8217;s a delusional belief with no basis in software engineering. Since delusional is a strong term, I&#8217;ll refer to it as the misguided status quo. There &#8211; that&#8217;s surely less offensive.</p>
<p>In my view, this is where PHP developers seem to like throwing themselves off a cliff. Rather than perform refactoring, they would rather preserve backwards compatibility on methods that are not even unit tested. All for a group of people down the line who are unwilling to accept that they took a risk in depending on them. If that sounds a wee bit bitter, it is. I&#8217;ve seen people do some crazy weird shit to avoid refactoring or other key changes that would make my life so much easier. Some circumstances push me into creating ridiculous brittle workarounds instead.</p>
<p>So we not only have two varying views, we also have two extreme solutions: mark everything private or actively discourage refactoring even to the extent of inventing stupid mind boggling excuses according to some unwritten rule book maintained by the anonymous hivemind (that&#8217;s the PHP one, not the shit crazy hacker one). Me? I&#8217;m a fan of the middle path: use protected methods unless otherwise required by design, <a class="zem_slink" title="Code refactoring" rel="wikipedia" href="http://en.wikipedia.org/wiki/Code_refactoring">refactor</a> at will and tell anyone who complains about downstream brittleness that I don&#8217;t unit test protected methods and that it is fundamentally necessary to change them at times. Most developers are intelligent enough to understand that they took a risk. We can both have our cake and eat it without undue hostility by being a little more upfront.</p>
<p>So why did I finally decide that private methods are not worth enforcing? Like many similar beliefs, it crept up on me over time. Back in the day, when I was programming in Java as a young kid with no sense of independent thought, I would have taken my blind puritanical righteousness to extremes and pounced on anyone who questioned the party line about private methods. These days, I program in PHP, Ruby, and Python. I try to avoid Perl. None of these have enforceable private methods. Perl doesn&#8217;t have private visibility at all without hacks. Ruby and Python have easily bypassed implementations (i.e. they are more of a low fence with a &#8220;No Trespassing&#8221; sign you can hop over as needed &#8211; at the risk of being prosecuted and fined). PHP stands out due to that evil conniving Java influence that is overquoted. Too much in PHP is already &#8220;influenced&#8221; or &#8220;inspired&#8221; by a language I dropped like a hot coal over a decade ago. I can&#8217;t wait until we get over Java as the PHP deity of choice&#8230;</p>
<p>Private methods represent more than a &#8220;No Trespassing&#8221; sign in PHP/Java. In PHP, they are enforceable in theory, i.e. you just cannot call or invoke them. End of story. In reality, this is hogwash. As our colleagues in Ruby, Python, Perl, and all the other programming languages without private visibility enforcement already know &#8211; you cannot impose a practice. There will always be the vocal group that tell you to fuck off while they blissfully inherit classes and reuse private methods anyway. It&#8217;s easy to do. All you need is a text editor and the keyboard keys CTRL, C and V. Or Reflection. Or sed and grep. Or git. Private visibility enforcement is an illusion (or delusion?).</p>
<p>Once you reach into the dark corners of your mind and realise that private methods and properties are just another pointless easy-to-overcome obstacle, the real problem remains entirely unchanged and unaddressed. How to manage the expectations of downstream users who can and will extend and reuse your code in ways you never expected?</p>
<p>All the band aids in the world won&#8217;t answer that, and my response would be to be clearly honest and open. Educate downstream users about your need for refactoring and then make it clear that they proceed at their own damn risk if relying on non-public methods! Then I, you, and the rest of the PHP community can hack, inherit, and gleefully ignore best practices when it suits us without worrying about <a class="zem_slink" title="Class (computer programming)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Class_%28computer_programming%29">private method</a> blockades. Not that that would stop us anyway&#8230;</p>
<p>Anyway, there&#8217;s my train of thought for today. Private methods are nice in theory but unenforceable in practice. If they really were enforceable, those of us who keep creating excuses to fiddle around with core library and framework code might blow a gasket or three out of frustration if the Nanny State mentality really took hold.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=3d73fc76-7d65-43d0-a858-764368f3c52c" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/03/private-vs-protected-methods-the-debate-that-never-ends/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Open Letter to Gareth Heyes: Regex HTML Sanitisation Doesn&#8217;t Work</title>
		<link>http://blog.astrumfutura.com/2011/03/open-letter-to-gareth-hayes-regex-html-sanitisation-doesnt-work/</link>
		<comments>http://blog.astrumfutura.com/2011/03/open-letter-to-gareth-hayes-regex-html-sanitisation-doesnt-work/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 16:02:50 +0000</pubDate>
		<dc:creator>padraic</dc:creator>
				<category><![CDATA[PHP General]]></category>
		<category><![CDATA[PHP Security]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Cross-Site Scripting]]></category>
		<category><![CDATA[Regular expression]]></category>

		<guid isPermaLink="false">http://blog.astrumfutura.com/?p=494</guid>
		<description><![CDATA[Dear Gareth Heyes, I thank you for your response that claims Regex HTML Sanitisation can work. However, I should clarify that my article, Regex HTML Sanitisation: Off With Its Head!, was written in the context of using Perl regular expressions in PHP to both parse and filter HTML. Your challenge to test HTMLReg was unusual]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F03%2Fopen-letter-to-gareth-hayes-regex-html-sanitisation-doesnt-work%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F03%2Fopen-letter-to-gareth-hayes-regex-html-sanitisation-doesnt-work%2F&amp;source=padraicb&amp;style=normal&amp;service=bit.ly&amp;service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&amp;hashtags=Cross-Site+Scripting,Regular+expression&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 250px"><a href="http://www.flickr.com/photos/57704929@N00/3528646651"><img title="Nu wordt het wel heel simpel om XSS zwakheden ..." src="http://farm3.static.flickr.com/2194/3528646651_a16d9053e1_m.jpg" alt="Nu wordt het wel heel simpel om XSS zwakheden ..." width="240" height="139" /></a><p class="wp-caption-text">Image by bertboerland via Flickr</p></div>
</div>
<p>Dear <a href="http://www.thespanner.co.uk/">Gareth Heyes</a>,</p>
<p>I thank you for your response that claims <a href="http://www.thespanner.co.uk/2011/03/18/regex-html-sanitisation-can-work/">Regex HTML Sanitisation can work</a>.</p>
<p>However, I should clarify that my article, <a href="http://blog.astrumfutura.com/2011/03/regex-html-sanitisation-off-with-its-head/">Regex HTML Sanitisation: Off With Its Head!</a>, was written in the context of using Perl regular expressions in PHP to both parse and filter HTML. Your challenge to test HTMLReg was unusual since HTMLReg is written in Javascript, operates as a client side library, and utilises the browser DOM to bypass HTML parsing with regular expressions.</p>
<p>As such, HTMLReg and your article title falls outside the context of my original article. I do, however, applaud the concept of using the browser DOM. While I cannot comment on the efficacy of client side filtering for cross-site scripting (XSS), the use of a DOM is a reliable strategy to bypass parsing problems. A similar approach accounts for the success of <a href="http://www.htmlpurifier.org">HTMLPurifier</a>. Obviously, I do not begrudge some minimal use of regular expressions on pre-parsed normalised input.</p>
<p>This did, however, prompt me to ponder whether such an inapplicable challenge appearing on Planet-PHP undermines my argument anyway by its mere existence and blunt title in a world populated by A.D.D. sufferers. I believed it might and so I found myself determined to crack your Javascript library over a cup of coffee and a biscuit.</p>
<p>The result of this quick examination cannot be publicly reported here as this would be poor reporting practice. Therefore, I will report the resulting security vulnerability by email. You now have six weeks from today&#8217;s date in which to release a fixed version of HTMLReg and publicly disclose this vulnerability. I trust you will ensure that all similar or related potential vulnerabilities are also fixed. It would also, optionally, be interesting to see a blog post on the effectiveness of a client side Javascript filter.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=c4ac8477-b350-4e8f-b864-1e65015cb49b" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.astrumfutura.com/2011/03/open-letter-to-gareth-hayes-regex-html-sanitisation-doesnt-work/feed/</wfw:commentRss>
		<slash:comments>67</slash:comments>
		</item>
	</channel>
</rss>

