<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Transcending Frontiers &#187; Securing FCKEditor</title>
	<atom:link href="http://blog.thefrontiergroup.com.au/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thefrontiergroup.com.au</link>
	<description>Your peek inside the collective mind of The Frontier Group</description>
	<lastBuildDate>Tue, 03 Jan 2012 06:53:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Securing FCKEditor</title>
		<link>http://blog.thefrontiergroup.com.au/2009/04/securing-fckeditor/</link>
		<comments>http://blog.thefrontiergroup.com.au/2009/04/securing-fckeditor/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 05:45:14 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[FCKEditor]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=364</guid>
		<description><![CDATA[FCKEditor is a third party WYSIWYG editor for websites that is used in a great number of applications across the web. The problem with using third party applications is that you can never be sure of the quality of the code, or of the security model they&#8217;re enforcing. In the case of FCKEditor the default [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://fckeditor.com/">FCKEditor</a> is a third party <a href="http://en.wikipedia.org/wiki/WYSIWYG">WYSIWYG</a> editor for websites that is used in a great number of applications across the web. The problem with using third party applications is that you can never be sure of the quality of the code, or of the security model they&#8217;re enforcing. In the case of FCKEditor the default installation can be extremely insecure and information on how to secure it is pretty thin on the ground.</p>
<p>There are a few things that can be done to improve the security of FCKEditor after installation so hopefully these few pointers will help.</p>
<p><strong>Integrate Your Own Authentication</strong><br />
You can integrate some basic authentication fairly easily using an htaccess file and the php auto_prepend directive. This directive will basically tell the php engine to prepend any script with the file that you specify, it&#8217;s essentially the same as issuing a <code>require()</code> call before each page is run. We use this to run our own authentication scripts before access to any part of our application is run. There are parts of FCKEditor that are freely open to the public, so this is quite important unless you want your site to have anonymous users uploading anything to you.</p>
<p><strong>Turn Off The PHP Engine in Your Upload Directories</strong><br />
FCKEditor does have some very basic checking included to try and stop users from being able to upload any sort of executable code to your application; but none of it works very well. The best way to circumvent this is to stop PHP from functioning inside your upload directories. What this means is that although a user could circumvent your security and upload some malicious code to your server all that will happen is your web server will serve back the content as plain text.</p>
<p><strong>Remove FCKEditor&#8217;s Testing Pages</strong><br />
FCKEditor includes some basic forms that allow you to check that your configuration is correct for uploading and browsing your website. These forms if they remain publicly available provide a very handy access point for users to upload content to your site that they shouldn&#8217;t be. The file exists in <code>/editor/filemanager/connectors/test.html</code> and is there only to allow you to test the connectors, you should be deleting it. This step will not stop those progressing up to step one or two, but I see this as putting up some fake security cameras, it&#8217;ll stop some lazy criminals.</p>
<p>Hopefully these tips will help anyone that is using FCKEditor and is worrying about any holes in their security this might open up. Obviously these can be generically applied to any application that allows uploading to occur, however with FCKEditor being quite prominent in older applications it&#8217;s probably worthwhile just having a look at your app to see how secure your editor really is.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2009/04/securing-fckeditor/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2009/04/securing-fckeditor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross Domain IFrame and Cookie Issues with IE7</title>
		<link>http://blog.thefrontiergroup.com.au/2009/02/cross-domain-iframe-and-cookie-issues-with-ie7/</link>
		<comments>http://blog.thefrontiergroup.com.au/2009/02/cross-domain-iframe-and-cookie-issues-with-ie7/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 07:49:00 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[IFrame]]></category>
		<category><![CDATA[P3P]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=336</guid>
		<description><![CDATA[This morning I had to solve a problem that involved an application inside an IFrame not keeping it&#8217;s session state. I&#8217;d solved this problem many times before, a long time ago, in a galaxy far far away, but still it stumped me again! In this example we had two client websites we&#8217;ll call site-a.com and [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I had to solve a problem that involved an application inside an IFrame not keeping it&#8217;s session state. I&#8217;d solved this problem many times before, a long time ago, in a galaxy far far away, but still it stumped me again!</p>
<p>In this example we had two client websites we&#8217;ll call site-a.com and site-b.com. Site-a.com had a page that contained an IFrame which sourced it&#8217;s content from site-b.com. The page on site-b.com allowed the user to log in to the application that resides on the site-b.com domain and then click on various links that would take them to other areas in the site-b.com application. </p>
<p>This worked perfectly in Firefox and Safari, but in IE7 it failed and would not let the user log in. After setting up a test environment on my virtual machine and repeating the bug I went looking for a solution. </p>
<p>It turned out that what was required was a declaration by site-b.com that it was okay to do what I was trying to do. It seems that as long as site-b.com declares that it&#8217;s safe then the browser assumes this to be the case and it all starts to work. </p>
<p>The way this is done is through adding <a href="http://en.wikipedia.org/wiki/P3P">P3P</a> info to the header of the response. Essentially what this does is say to the browser that your application is okay with taking information from other domains. Rather than relying on external security measures, you&#8217;ve taken the steps yourself to develop a secure application. This sort of setting can also be used for single sign on situations too where your cookies need to be accessible across domains and applications. </p>
<p>Typically it&#8217;s as simple as adding : </p>
<pre class="php">
header('P3P: CP="CAO PSA OUR"');
</pre>
<p>to the page. You could also add it on the server level if required, but in this case it all takes place in an extranet module so it&#8217;s perfectly suitable to be applied only on one page. There are quite a few options that you can find on the <a href="http://www.w3.org/TR/P3P11/">P3P Specification</a>.</p>
<p>So that&#8217;s how you get cross domain cookies to work with PHP. It&#8217;s much the same in other web frameworks, you just need to work out how to modify the headers in the one you&#8217;re using.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2009/02/cross-domain-iframe-and-cookie-issues-with-ie7/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2009/02/cross-domain-iframe-and-cookie-issues-with-ie7/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making a Copy of an Object in PHP</title>
		<link>http://blog.thefrontiergroup.com.au/2009/02/making-a-copy-of-an-object-in-php/</link>
		<comments>http://blog.thefrontiergroup.com.au/2009/02/making-a-copy-of-an-object-in-php/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 02:46:35 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=326</guid>
		<description><![CDATA[In PHP4 objects were passed by value, it&#8217;s probably the intuitive way to deal with variables for a beginner and in a language where objects are not first class. However in PHP5 this has been changed and now objects are passed by reference, this stung me when writing some tests recently. public function testNameIsUnique() { [...]]]></description>
			<content:encoded><![CDATA[<p>In PHP4 objects were passed by value, it&#8217;s probably the intuitive way to deal with variables for a beginner and in a language where objects are not first class. However in PHP5 this has been changed and now objects are passed by reference, this stung me when writing some tests recently. </p>
<pre class="php">
public function testNameIsUnique() {
	$test1 = $this->BuildValidDiscountType();
	$test2 = $test1;

	$test1->Save();
	$this->assertTrue($test1->id > 0);

	$this->setExpectedException('DiscountTypeException');
	$test2->Save();
}
</pre>
<p>This code shouldn&#8217;t have worked as far as I was concerned, in fact I was expecting an exception to be raised. Instead it was working and after a little debug tour I found that my <code>$test1 = $test2</code> line was causing <code>$test2</code> to be a reference to <code>$test1</code>, not what I wanted. This caused my update method to be triggered instead and of course the name is still unique. </p>
<p>It only required a small change to that line, using the <a href="http://php.net/clone">clone</a> specifier : </p>
<pre class="php">
$test1 = clone $test2;
</pre>
<p>After that everything went as expected and I knocked off another test, and added to my PHP knowledge.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2009/02/making-a-copy-of-an-object-in-php/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2009/02/making-a-copy-of-an-object-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bench marking instead of bench warming</title>
		<link>http://blog.thefrontiergroup.com.au/2008/12/bench-marking-instead-of-bench-warming/</link>
		<comments>http://blog.thefrontiergroup.com.au/2008/12/bench-marking-instead-of-bench-warming/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 11:56:30 +0000</pubDate>
		<dc:creator>mlambie</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Websites or Tools]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[opcode]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rasmus]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=232</guid>
		<description><![CDATA[In August of this year we deployed a series of new server and storage devices which we expect will carry us through to 2011. One of the negative side effects of this deployment was that all of the sites and services we hosted on the new hardware performed significantly better than on the old configuration. [...]]]></description>
			<content:encoded><![CDATA[<p>In August of this year we deployed a series of new server and storage devices which we expect will carry us through to 2011. One of the negative side effects of this deployment was that all of the sites and services we hosted on the new hardware performed significantly better than on the old configuration.</p>
<p>I hear you ask &#8220;how is that a negative side effect?&#8221; It meant that I put off the investigation into bench marking and tuning our server platforms simply because the move to newer hardware gave us significant gains. I had planned on doing some configuration tuning and system refinement, but the sheer increase in processing power meant that I didn&#8217;t bother with it back then.</p>
<p>Today, however, I decided to investigate what the addition of a PHP opcode cache would provide, and I was very happy with the results.</p>
<p>I came across an issue with running APC, the opcode cache developed by Rasmus and other core PHP developers, alongside the Zend Optimizer. The two are incompatible so you&#8217;ll have to play favourites and pick one or the other.</p>
<p>Installation of APC is easy on Ubuntu. There&#8217;s many guides online, but <a href="http://www.blogovela.com/installing-apc-on-ubuntu-804-hardy-heron-0314.html">I found this one</a> to be the most succinct. You end up installing the following packages (note: I didn&#8217;t have <code>build-essential</code> initially and PECL couldn&#8217;t build the package because I was missing <code>make</code>):</p>
<pre>mlambie@prime:~$  sudo aptitude install php-pear php5-dev apache2-prefork-dev build-essential</pre>
<p>The installation of APC is easy via PECL:</p>
<pre>mlambie@prime:~$  sudo pecl install apc</pre>
<p>Then enable the module by creating an apc.ini file:</p>
<pre>mlambie@prime:~$ cat /etc/php5/apache2/conf.d/apc.ini
extension = apc.so
apc.enabled = 1
apc.shm_size = 48
apc.include_once_override = 1
apc.mmap_file_mask = /tmp/apc.XXXXXX</pre>
<p>I ran some benchmarks using Apache Bench. The results were very encouraging. I saw a reduction in the time per request fall from 91ms to 37ms (250% improvement). The  volume of requests per second increased from 11/sec to 27/sec (245% improvement). Lastly, 98% of all requests are served within 639ms instead of 1165ms (182% improvement).</p>
<p>Each actual apache process saw a significant memory reduction too, from 26MB down to 20MB (almost a 25% footprint saving). When you&#8217;ve got multiple processes running the reclaimed memory adds up quite quickly.</p>
<p>I found the figures staggering, and the improvements are actual, real things that are visible when interacting with the sites and applications hosted on <code>prime</code>. </p>
<p>It&#8217;s fair to say that we more then doubled our performance, from a single server, simply by adding PHP opcode cache. If you&#8217;re not running one on your server, you might want to consider why.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2008/12/bench-marking-instead-of-bench-warming/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2008/12/bench-marking-instead-of-bench-warming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically Reducing Object Sizes in PHP</title>
		<link>http://blog.thefrontiergroup.com.au/2008/11/dynamically-reducing-object-sizes-in-php/</link>
		<comments>http://blog.thefrontiergroup.com.au/2008/11/dynamically-reducing-object-sizes-in-php/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 05:51:59 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Dynamic Languages]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=178</guid>
		<description><![CDATA[After using jQuery for quite a while I&#8217;ve become quite attached to using the power of callbacks when dealing with sets of data. I&#8217;ve seen equally and perhaps better abilities in Ruby but of course had been let down in the past by PHP&#8217;s lack of abilities as a dynamic language. Today I faced an [...]]]></description>
			<content:encoded><![CDATA[<p>After using jQuery for quite a while I&#8217;ve become quite attached to using the power of callbacks when dealing with sets of data. I&#8217;ve seen equally and perhaps better abilities in Ruby but of course had been let down in the past by PHP&#8217;s lack of abilities as a dynamic language.</p>
<p>Today I faced an issue due to the size of my objects. The problem essentially came down to the fact that for the largest objects such as Contact objects the amount of data passed back to the client when doing AJAX calls was pretty sizeable. I wanted to write a function that given a set of property names all the returning objects would be stripped of all but those properties.</p>
<p>I didn&#8217;t want to write a function for each set of properties I&#8217;d return, so I wrote a generic function that given an array of property names that was all that would be returned from that object and it was surprisingly easy and I think in the end highly dynamic and useful.</p>
<p>It uses the PHP array_walk() function which I&#8217;ve never used before. It&#8217;s a lot like the Array.each() methods that many other languages have.</p>
<pre class="php" name="code">	private function GetContacts() {
		$filter = RequestQuerystring('filter');
		$properties = RequestAll('properties');

		if (isset($properties)) {
			$properties = explode(',', $properties);
		}

		if (isset($filter)) {
			$contacts = [large_objects]
		}

		if (isset($contacts) &amp;&amp; is_array($properties)) {
			array_walk($contacts, 'mod_ajax::FilterObjects', $properties);
		}

		echo json_encode($contacts);

	}

	private static function FilterObjects(&amp;$object, $key, $properties) {
		foreach (get_object_vars($object) as $k =&gt; $v) {
			if (!in_array($k, $properties)) {
				unset($object-&gt;$k);
			}
		}
	}</pre>
<p>Basically for this array of large objects on each one we call FilterObjects. That has to be a function or static method which I learned as I went. The object is passed in by reference so that any change made to it is reflected in the original array, and it just goes through the variables (properties) of the object and kills anything that isn&#8217;t in the allowable parameter list.</p>
<p>This allows me to trim large objects dynamically for any of my client side calls for data and I think is definitely going to save me time in the future. I remember when I first started using PHP I wrote a function for each object to spit out XML, then I progressed to JSON, now I&#8217;ve got a nice filter method.</p>
<p>I still feel like there must be a better way to do things, but quite possibly that would exist in another language.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2008/11/dynamically-reducing-object-sizes-in-php/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2008/11/dynamically-reducing-object-sizes-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>json_decode() Not Working in PHP?</title>
		<link>http://blog.thefrontiergroup.com.au/2008/11/json_decode_php/</link>
		<comments>http://blog.thefrontiergroup.com.au/2008/11/json_decode_php/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 06:54:28 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Magic Quotes]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=147</guid>
		<description><![CDATA[&#8211; Check out some of our more recent Ruby on Rails blog posts. If you&#8217;d like to hire our team, get in touch &#8211; This took me a few minutes today to work out and find an answer on Google so I thought I&#8217;d share it. I had a string that I was posting from a [...]]]></description>
			<content:encoded><![CDATA[<p><em>&#8211; Check out some of our more recent </em><a title="Ruby on Rails posts" href="http://thefrontiergroup.com.au/blog/category/ruby-on-rails/"><em>Ruby on Rails blog posts</em></a><em>. If you&#8217;d like to hire our team, <a title="Get in touch" href="http://thefrontiergroup.com.au/pages/contact-us">get in touch</a></em><em> &#8211;</em></p>
<p>This took me a few minutes today to work out and find an answer on Google so I thought I&#8217;d share it.</p>
<p>I had a string that I was posting from a form and while Firebug on the client said that the string was valid, on the server side PHP&#8217;s json_decode() function was returning me a <a href="http://en.wikipedia.org/wiki/Null_(computer_programming)">NULL</a> indicating invalid <a href="http://en.wikipedia.org/wiki/JSON">JSON</a>. I spit out the string using good old var_dump() and I could see straight away that I would need to strip some slashes from it, but I couldn&#8217;t figure out why.</p>
<p>I don&#8217;t like to simply know how to fix something, I like to know why it was broken in the first place! A bit of Googling gave me the answer, it turned out to be because of the magic_quotes setting in PHP.</p>
<p>Instead of just wrapping everything in a stripslashes() call I decided to write a wrapper function that will take into account whether magic_quotes is on or off. It will also allow me to do whatever I want later one if I wanted to parse a particular type of data or something.</p>
<p>Here is the code. As you can see it&#8217;s nothing fancy, but it works and hopefully it saves people some time.</p>
<pre class="php">function _json_decode($string) {
	if (get_magic_quotes_gpc()) {
		$string = stripslashes($string);
	}

	return json_decode($string);
}</pre>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2008/11/json_decode_php/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2008/11/json_decode_php/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

