<?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:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Larry Ullman&#039;s Blog &#187; security</title>
	<atom:link href="http://blog.dmcinsights.com/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dmcinsights.com</link>
	<description>flotsam and jetsam abounds</description>
	<lastBuildDate>Tue, 27 Jul 2010 16:27:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Email Validation in PHP</title>
		<link>http://blog.dmcinsights.com/2010/06/10/email-validation-in-php/</link>
		<comments>http://blog.dmcinsights.com/2010/06/10/email-validation-in-php/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 06:15:47 +0000</pubDate>
		<dc:creator>Larry</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.dmcinsights.com/?p=1094</guid>
		<description><![CDATA[A very common need in PHP-based Web applications is to validate email addresses. An email address, at its most basic contains the @ and a dot and no spaces or special characters, so it&#8217;s pretty easy coming up with a regular expression that will fit this most simple restriction. However, if you want a full-on [...]]]></description>
			<content:encoded><![CDATA[<p>A very common need in PHP-based Web applications is to validate email addresses. An email address, at its most basic contains the @ and a dot and no spaces or special characters, so it&#8217;s pretty easy coming up with a regular expression that will fit this most simple restriction. However, if you want a full-on precise regular expression, that takes an immense amount of code (the full email validation pattern takes up almost a page of code). An alternative, then is to use the <strong>EmailAddressValidation</strong> class, created by <a href="http://www.addedbytes.com/blog/email-address-validation-v2/">Added Bytes</a> and now hosted on <a href="http://code.google.com/p/php-email-address-validation/">Google Code</a>.</p>
<p>After you&#8217;ve downloaded the code and put it on your server, you use it like so:</p>
<pre>require('/path/to/EmailAddressValidator.php');
$emailValidator = new EmailAddressValidator();
if ($emailValidator-&gt;check_email_address('test@example.org')) {
    // Email address is technically valid.
} else {
    // Email not valid.
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dmcinsights.com/2010/06/10/email-validation-in-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Security is Next to Godliness</title>
		<link>http://blog.dmcinsights.com/2010/05/01/security-is-next-to-godliness/</link>
		<comments>http://blog.dmcinsights.com/2010/05/01/security-is-next-to-godliness/#comments</comments>
		<pubDate>Sun, 02 May 2010 00:33:53 +0000</pubDate>
		<dc:creator>Larry</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.dmcinsights.com/?p=1031</guid>
		<description><![CDATA[I&#8217;ve been trying to write more about Web development security lately, in part because I&#8217;m going to be writing an &#8220;E-Commerce with PHP and MySQL&#8221; book this summer, so security is at the top of my mind. , I made some suggestions as to how one develops and tests a site from a security perspective. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to write more about Web development security lately, in part because I&#8217;m going to be writing an &#8220;E-Commerce with PHP and MySQL&#8221; book this summer, so security is at the top of my mind. <a href="http://blog.dmcinsights.com/2010/04/17/a-simple-approach-to-site-security/">In a previous post</a>, I made some suggestions as to how one develops and tests a site from a security perspective. Here I want to cover security as a general philosophy, so you understand that approach I take (and, therefore, the approach I would recommend you take). When I explain things, I think in terms of analogies. I&#8217;m pretty sure they don&#8217;t always work or help, but still, it&#8217;s what I do. And the analogy I have for Web site (or application) security is: <em>Security is Next to Godliness</em>. Which is to say, think of security the way you might think about cleanliness.<span id="more-1031"></span>Say you go to eat at a restaurant&#8230;the restaurant may or may not <strong>look</strong> clean and it may or may not <strong>be</strong> clean. But if the restaurant doesn&#8217;t look clean, then it probably isn&#8217;t actually clean and you don&#8217;t want to eat there. The same goes for a Web site&#8217;s security: if it doesn&#8217;t give the appearance of being secure, it probably isn&#8217;t secure, and users won&#8217;t want to use the site (or shouldn&#8217;t). A Web site can look secure by looking professional, giving proper error messages, and by not looking obviously unsecure. This last quality is really the most important, as the common person may not really know the difference between a secure looking and unsecure looking site. But if they go to a site and get alerts from their browser due to a lack of a good certificate, or whatever, that&#8217;s like seeing a rodent go across the restaurant floor.</p>
<p>The second part of this analogy is that while it&#8217;s important for a restaurant to look clean (so people will eat there), it&#8217;s more important that it&#8217;s actually clean (so that diner&#8217;s don&#8217;t get sick, so that the inspector doesn&#8217;t shut you down, etc.). And so your Web site must actually be secure, so that nothing bad can happen to the users, your clients, the Easter bunny, and so forth.</p>
<p>The final reason I think this analogy works is that like security, like cleanliness, isn&#8217;t an absolute and the amount of effort you put into it should depend upon the situation. Your front porch doesn&#8217;t need to be that clean, but your bathrooms and kitchens sure do. And maybe you&#8217;re the kind of person that would thoroughly clean monthly, weekly, or daily. Maybe you&#8217;re the kind that will take cleaning to the disinfecting level. There&#8217;s no right answer in these situations: there&#8217;s better and there&#8217;s worse and there&#8217;s what&#8217;s right for you and your situation. The same goes for security. A site that handles no money has one level of security requirements; a site that performs online banking has a totally different level. Most importantly, just because you cleaned today, doesn&#8217;t mean your place will stay clean forever. And the Web site or application you ship today without any issues could become vulnerable tomorrow (most likely because of a found concern with underlying software or third-party applications).</p>
<p>So there&#8217;s my simple, yet overly-described, analogy for Web site or application security. Hopefully it&#8217;ll help you in the way you think about your Web site (or the next meal out!).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dmcinsights.com/2010/05/01/security-is-next-to-godliness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple Approach to Site Security</title>
		<link>http://blog.dmcinsights.com/2010/04/17/a-simple-approach-to-site-security/</link>
		<comments>http://blog.dmcinsights.com/2010/04/17/a-simple-approach-to-site-security/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 18:31:24 +0000</pubDate>
		<dc:creator>Larry</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.dmcinsights.com/?p=1009</guid>
		<description><![CDATA[There are two kinds of security that Web sites, applications, and operating systems can provide: perceived security and actual security. Perceived security is still important, because that&#8217;s what convinces users that it&#8217;s safe to, for example, provide their personal information to your Web site. But actual security is the key. Think of it as the [...]]]></description>
			<content:encoded><![CDATA[<p>There are two kinds of security that Web sites, applications, and operating systems can provide: <em>perceived</em> security and <em>actual</em> security. Perceived security is still important, because that&#8217;s what convinces users that it&#8217;s safe to, for example, provide their personal information to your Web site. But actual security is the key. Think of it as the difference between having a sign in front of your house saying it&#8217;s protected by a security system and actually having a security system. But if you&#8217;re anything like me, you&#8217;ve never tried to hack someone&#8217;s Web site and aren&#8217;t generally inclined to think like a person who would, so how do you make your sites secure? Here&#8217;s what I do&#8230;<span id="more-1009"></span></p>
<p>You really have to start thinking about security from the get-go, which means the database. Secondary column properties make a big difference to the reliability of the stored data. This means identifying columns as <strong>NOT NULL</strong>, <strong>UNSIGNED</strong>, a particular number of decimals, and applying a <strong>UNIQUE</strong> index (all of these as appropriate, of course). These settings will prevent bad data from getting into the database, such as negative quantities or duplicate email addresses (the PHP code will need to handle those MySQL rejections, though).</p>
<p>In your PHP code, you&#8217;ll want to use regular expressions to validate data when you can. And all strings should be run through an escaping function like <strong>mysqli_real_escape_string()</strong>, prior to using them in a database query. I would do this even if the data already passed a regular expression (you cannot be too careful). You can also consider applying <strong>strip_tags()</strong>, too.</p>
<p>For numeric values, I strongly recommend type-casting:</p>
<pre>$something = (int) $_POST['something'];</pre>
<p>Type-casting to numbers will make the data safe to use in queries. If you type-cast a string as an integer, the result will be zero, so you can type-cast, then check for a valid value (i.e., greater than zero). Valid numeric values will just be formally converted from a string with that value to a number with that value.</p>
<p>With variables, it&#8217;s also best to assume the values are invalid or not present at all, then prove otherwise.</p>
<p>When you get to your HTML, there&#8217;s not much you can do to <em>guarantee</em> security, but you can <em>encourage</em> it. For example, you can limit the length of a text input to whatever is the maximum size of the corresponding column in the database. Or you can use drop-down menus with preset values. Client-side validation using JavaScript is nice for the end user, but is not a real security tool as JavaScript can easily be disabled.</p>
<p>Once you&#8217;ve done all that (and hopefully you already are doing most of these things), you can run some tests to find potential security holes. To start, I think about the three kinds of people that use the site: those that use it perfectly, exactly as intended; those that use it without malicious intent, but that might cause problems; and those that are trying to hack the site. In the first category you have pretty much just me. I&#8217;m developing the site, I know what it&#8217;s supposed to do and how I think it&#8217;s to be used, and I&#8217;m not likely to break it. In the second category is almost everyone. They just want to use the site, they may make mistakes, they may have apostrophes in their names, and they just expect the site to work regardless. For these people, the goal is to provide a proper user interface, point out mistakes when they occur, and insure that clean, proper data is used at every step of the way. For the third category of user, they&#8217;ll do everything they can, include taking extraordinary steps, to try to break your site in order to get some information they deem useful.</p>
<p>There&#8217;s really no point in testing the site as <em>I&#8217;d </em>use it, so I quickly start imitating the behavior of the second group of users. First, I test my PHP scripts by submitting forms without doing anything at all. The result should be appropriate error messages to the end user, without ANY &#8220;undefined index&#8221; or similar PHP errors. The same goes for scripts that expect to receive values in the URL: test them without sending any values in the URL and see the result. Second, I fill out forms using invalid values: numbers for strings and vice versa. What is the result? Third, I fill out the forms using potentially valid, but complicated values, such as strings with apostrophes and quotation marks, possibly even with HTML.</p>
<p>As I said, I&#8217;m not maliciously-inclined (or I&#8217;d like to think I&#8217;m not), so it&#8217;s hard for me to think like a hacker. Much of what a hacker might try to do will be caught by the previous set of tests, though. If your site handles invalid data, apostrophes, quotation marks, and HTML tags properly, you&#8217;ve already done a lot to prevent bad things from happening. Hackers might take things further though, like creating their own HTML form that submits data to your PHP scripts (you can POST data without using a form at all, too). What if a hacker were to create a copy of your form, and replace your &#8220;quantity&#8221; or &#8220;states&#8221; drop-down menu with a text input, so they could use their own values? How well would the PHP script handle that contingency?</p>
<p>Hackers also like to get into places they shouldn&#8217;t, so try directly accessing scripts or directories that should be protected. Also try directly running scripts that are meant to be included, such as a configuration file. If you&#8217;re serving files to only authenticated users, can those files be viewed directly?</p>
<p>Sometimes the goal of a hacker is to find out information about your server, so you have to be extra careful that the site does not give too much away, specifically, too much about PHP, Apache (or whatever Web server), and MySQL. Towards that end, you have to make sure that MySQL errors are handled properly, without revealing anything to the end user. To do this, you may need to temporarily break your database scripts to see the result. For example, you&#8217;ve got a site working and it&#8217;s not giving away any secrets, whether or not the user behaves themselves. But what if the database server goes down or is to busy or something else happens to prevent your PHP scripts from connecting? What would the user see then? Hopefully nothing but a generic &#8220;system is done/come back later&#8221; apology.</p>
<p>With practice, developing sites to properly handle all of these situations and types of users becomes second-nature (not that you shouldn&#8217;t continue to test them). But I know that as you&#8217;re just getting going, it&#8217;s natural to feel like you haven&#8217;t done enough or tested enough. I hope that these few paragraphs provide a better feel for the process.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dmcinsights.com/2010/04/17/a-simple-approach-to-site-security/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Protecting Email Addresses Online</title>
		<link>http://blog.dmcinsights.com/2009/06/16/protecting-email-addresses-online/</link>
		<comments>http://blog.dmcinsights.com/2009/06/16/protecting-email-addresses-online/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 16:55:46 +0000</pubDate>
		<dc:creator>Larry</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://blog.dmcinsights.com/?p=463</guid>
		<description><![CDATA[If you have an email address posted on a Web site, you&#8217;re almost guaranteed to get spam. Bots scour the Internet, looking through HTML source code to find email address to harvest. Web developers, meanwhile, are constantly trying new techniques to prevent this from happening. In this post, I discuss an interesting study in spam [...]]]></description>
			<content:encoded><![CDATA[<p>If you have an email address posted on a Web site, you&#8217;re almost guaranteed to get spam. Bots scour the Internet, looking through HTML source code to find email address to harvest. Web developers, meanwhile, are constantly trying new techniques to prevent this from happening. In this post, I discuss an interesting study in spam prevention, some of the available techniques, and the route I choose to go on a recent project.<span id="more-463"></span>In 2006, a developer created nine email addresses and posted them online, each protected in different ways (or not at all). You can read about this in detail at <a href="http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/">techblog.tilllate.com</a>. I love this kind of empirical study, because it uses raw data to prove the efficacy of the approaches. Keeping the email in plain text had the worst result, as you might expect, with encoded and slightly obfuscated versions also being hit with spam. These latter techniques are things like replacing the @ symbol with something less obvious: <em>myname [AT] example -DOT- com</em>. And even if you do try this, you still need to put the actual email address in the HTML <strong>mailto</strong> link, so that won&#8217;t really work.</p>
<p>The most effective results came from using ROT13 encryption, in which the source code has the email address in an encrypted format, with JavaScript then dynamically creating a legible, and clickable, <strong>mailto</strong> link by decryption. Of course, the JavaScript method won&#8217;t work if JavaScript is disabled, but I don&#8217;t personally worry about that too much.</p>
<p>There are also two very interesting CSS techniques (this code comes from <a href="http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/">http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/</a>):</p>
<pre>&lt;style type="text/css"&gt;
span.codedirection { unicode-bidi:bidi-override; direction: rtl; }
&lt;/style&gt;
&lt;p&gt;&lt;span class="codedirection"&gt;moc.elpmaxe@emanym&lt;/span&gt;&lt;/p&gt;</pre>
<p>and</p>
<pre>&lt;style type=”text/css"&gt;
p span.displaynone { display:none; }
&lt;/style&gt;
&lt;p&gt;myname@&lt;span class=”displaynone”&gt;null&lt;/span&gt;example.com&lt;/p&gt;&lt;/p&gt;</pre>
<p>The first example says that the backwords HTML text should be displayed from right to left order. The second adds an invisible <em>null</em> to the example address. Unfortunately these two routes won&#8217;t allow for clickable links and make your site less accessible. Which leads me to a main consideration in this battle: <span style="text-decoration: underline;">There&#8217;s no perfect solution sometimes</span>!</p>
<p>One option that I like is to just use a contact form that sends an email upon submission. This only really works if you have just a single email address associated with a site and it does limit what content can be sent (e.g., no attachments without some extra form work). On my own site, I use an image representation of an email address. But like the CSS methods, a link won&#8217;t be clickable and the accessibility is degraded. You can minimize the latter concern by making the <strong>ALT</strong> tag descriptive, like <em>my first name plus my first initial at this domain</em>. But also keep in mind it&#8217;s possible for bots to read images, which is why CAPTCHA text has to be so strange. That being said, I&#8217;ve been using this technique for a couple of years now and I don&#8217;t think I&#8217;ve gotten any spam on that address yet.</p>
<p>Those are relatively simple routes. If you want a really thorough solution, <a href="http://www.alistapart.com/articles/gracefulemailobfuscation">A List Apart</a> has a detailed client- and server-side approach you can try.</p>
<p>As for what I&#8217;ve done lately, on a recent Web site I created, dozens of email addresses are listed for the different people involved with the project, so using a contact form wasn&#8217;t possible. The project itself involves people for whom accessibility is key, so the CSS techniques were out, too. In the end I went with a JavaScript solution, using <a href="http://www.jquery.com">jQuery</a> and <a href="http://www.php.net">PHP</a>, which the site is built with. This particular technique—and I have no hard data for how effictive it is—uses a <a href="http://www.leftrightdesigns.com/library/jquery/nospam/php-integration.php">PHP function</a> to create a somewhat-obsfucated HTML source of an email address, then uses a <a href="http://plugins.jquery.com/project/nospam">jQuery Plugin</a> to turn that source into a readable, and even clickable, link. For this project right now, it seems to be a reasonable compromise.</p>
<p>Of course, bots keep learning and they&#8217;ll figure out how to get around these techniques, which is why we all need to stay informed and try new things. That, and get rid of our email addresses every couple of years!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dmcinsights.com/2009/06/16/protecting-email-addresses-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Five JavaScript Tips in Five Days, continued</title>
		<link>http://blog.dmcinsights.com/2009/03/17/five-javascript-tips-in-five-days-continued/</link>
		<comments>http://blog.dmcinsights.com/2009/03/17/five-javascript-tips-in-five-days-continued/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 18:12:06 +0000</pubDate>
		<dc:creator>Larry</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.dmcinsights.com/?p=350</guid>
		<description><![CDATA[The other three posts in my Five JavaScript Tips in Five Days series for Peachpit Press have now been posted. The full set is: Handling JSON Data Securely Debugging XML/JSON Requests Choosing a JavaScript Framework Performing Cross-Domain Ajax Requests Loading JavaScript Faster]]></description>
			<content:encoded><![CDATA[<p>The other three posts in my <em>Five JavaScript Tips in Five Days</em> series for <a href="http://www.peachpit.com">Peachpit Press</a> have now been posted. The full set is:</p>
<ul>
<li><a href="http://www.peachpit.com/blogs/blog.aspx?uk=Handling-JSON-Data-Securely1">Handling JSON Data Securely</a></li>
<li><a href="http://www.peachpit.com/blogs/blog.aspx?uk=Debugging-XMLJSON-Requests">Debugging XML/JSON Requests</a></li>
<li><a href="http://www.peachpit.com/blogs/blog.aspx?uk=Choosing-a-JavaScript-Framework2">Choosing a JavaScript Framework</a></li>
<li><a href="http://www.peachpit.com/blogs/blog.aspx?uk=Performing-Cross-Domain-Ajax-Requests">Performing Cross-Domain Ajax Requests</a></li>
<li><a href="http://www.peachpit.com/blogs/blog.aspx?uk=Loading-JavaScript-Faster">Loading JavaScript Faster</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.dmcinsights.com/2009/03/17/five-javascript-tips-in-five-days-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
