<?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>Siblog :: Web Design News &#187; PHP</title>
	<atom:link href="http://www.sibagraphics.com/wp/category/web-design/resources/code/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sibagraphics.com/wp</link>
	<description>Web development resources, articles and discussion.</description>
	<lastBuildDate>Wed, 28 Dec 2011 13:50:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP Form Script Security</title>
		<link>http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/</link>
		<comments>http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 05:29:27 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/</guid>
		<description><![CDATA[Some ideas to tighten up form script security &#8230; more specifically to counter form spoofing and cross browser attacks. (1) Check for extra _POST variables, and disallow any _GET variables. { $limit_post=count($_POST); $limit_get=count($_GET); if ($limit_post>8&#124;&#124;$limit_get>0) { include ("formhead.php"); echo "Submission &#8230; <a href="http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some ideas to tighten up form script security &#8230; more specifically to counter form spoofing and cross browser attacks.</p>
<p>(1) Check for extra _POST variables, and disallow any _GET variables.</p>
<blockquote><p><code>{<br />
$limit_post=count($_POST);<br />
$limit_get=count($_GET);<br />
if ($limit_post>8||$limit_get>0)<br />
{<br />
include ("formhead.php");<br />
echo "Submission failed.";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(2) Prevent the exceeding of maximum field length from the server side in the script &#8211; setting form field maximum length inputs is not sufficient.</p>
<blockquote><p><code>{<br />
$length = strlen($_POST['Name'] || $_POST['Email'] || $_POST['Address'] || etc);<br />
if($length>30)<br />
{<br />
include ("formhead.php");<br />
echo "Too many characters.";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(3) Check for legal use of characters (white list approach).</p>
<blockquote><p><code>{<br />
if (eregi("[^-a-z]+$", $_POST['Name']) || eregi("[^-/\.a-z0-9]+$", $_POST['Address']) || eregi("[^-a-z]+$", $_POST['City']) etc)<br />
{<br />
include ("formhead.php");<br />
echo "Invalid characters.";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(4) Check for well-formed email address.</p>
<blockquote><p><code>{<br />
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$", $_POST['Email']))<br />
{<br />
include ("formhead.php");<br />
echo "Please enter a valid email.";<br />
$_POST['Email']="";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(5) Use quotemeta to filter output (note that quotemeta doesn&#8217;t filter the pipe character &#8211; hence the productiveness of using the previous eregi function).</p>
<p>(6) Use the Session token method described at <a class="postlink" target="_blank" href="http://shiflett.org/archive/96">http://shiflett.org/archive/96</a> to further prevent XSS attacks.</p>
<p>eg.</p>
<p>In the document head:</p>
<blockquote><p><code>&lt;?php $token = md5(uniqid(rand(), true));<br />
$_SESSION['token'] = $token; ?&gt;</code></p>
</blockquote>
<p>In the form:</p>
<blockquote><p><code>&lt;input type="hidden" name="sekret" value="&lt;?php echo $token; ?&gt;" /&gt;</code></p>
</blockquote>
<p>In the script:</p>
<blockquote><p><code> {<br />
if ($_SESSION['token'] != $_POST['token'])<br />
{<br />
echo "Invalid submission.";<br />
//go to error page<br />
exit;<br />
}<br />
} </code></p>
</blockquote>
<p>References:</p>
<p><small><a class="postlink" target="_blank" href="http://phpsec.org/projects/guide/2.html">http://phpsec.org/projects/guide/2.html</a><br />
<a class="postlink" target="_blank" href="http://www.devshed.com/c/a/PHP/Reconsidering-PHP-variables/">http://www.devshed.com/c/a/PHP/Reconsidering-PHP-variables/</a><br />
<a class="postlink" target="_blank" href="http://au.php.net/manual/en/function.quotemeta.php">http://au.php.net/manual/en/function.quotemeta.php</a><br />
<a class="postlink" target="_blank" href="http://shiflett.org/">http://shiflett.org/</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Countering form spam bot attacks</title>
		<link>http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/</link>
		<comments>http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 04:56:32 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/</guid>
		<description><![CDATA[Spammers, the dregs of the internet, are now using automated bots to explore form security. The bot completes the form to test for possible usage as a spam relay, attempting to inject extra headers which, if successful, will send the &#8230; <a href="http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Spammers, the dregs of the internet, are now using automated bots to explore form security.</p>
<p>The bot completes the form to test for possible usage as a spam relay, attempting to inject extra headers which, if successful, will send the response to the bot owner.</p>
<p>To counter their tactics, fields like the mailto, from and subject fields can be checked server side (all user input should be checked server side).</p>
<p>eg.</p>
<p>mailto:</p>
<blockquote><p><code>$to=$mailTo;<br />
if ($to !== "youraddy@yourdomain.com")<br />
{<br />
die("Getawoollyoneupyah, spammer!");<br />
}</code></p>
</blockquote>
<p>from and subject fields:</p>
<blockquote><p><code>if ((preg_match(' /[\r\n,;\'"]/ ', $_POST['Email'])) ||  (preg_match(' /[\r\n,;\'"]/ ', $mailSubject)))<br />
{<br />
die("Go away, spammer!");<br />
}</code></p>
</blockquote>
<p>Then, to prevent the bot filling in the form at all, the contact name field for example, can be checked as the bot attempts to fill in all fields with an email address.</p>
<blockquote><p><code>elseif (eregi("[^-a-z ]", $_POST[Name]))<br />
{<br />
echo "Characters in name field are invalid.";<br />
$_POST[Name] ="";<br />
} </code></p>
</blockquote>
<p>More information about the relevant email injection exploit can be found here:</p>
<p><a target="_blank" href="http://computerbookshelf.com/email_injection/">http://computerbookshelf.com/email_injection/</a><br />
<a target="_blank" href="http://securephp.damonkohler.com/index.php/Email_Injection">http://securephp.damonkohler.com/index.php/Email_Injection</a></p>
<p>There&#8217;s a form testing script linked here as well as an explanation re asp scripts:</p>
<p><a target="_blank" href="http://www.twologs.com/en/services/test/spamrelay.asp">http://www.twologs.com/en/services/test/spamrelay.asp</a></p>
<p>and a script to ban known spam bots here:</p>
<p><a target="_blank" href="http://www.foto50.com/spammercheck.phps">http://www.foto50.com/spammercheck.phps</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

