Archives

Archive for March, 2009

Quick Tip: Forcing www. to avoid duplicate content

Google (and other search engines) treats subdomains as different websites so if you are linked / accessed both via http://www.yourdomain.com and http://yourdomain.com you may get your content classified as duplicate since will be the same on both.

To avoid this simply add a rule to a .htaccess file in your root directory:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
</IfModule>

NOTE: You need to have mod_rewrite enabled in your server in order to do this.

Quick-tip: PHP mail() header misuse “vulnerability”

When thinking about contact forms in PHP, people use to create a simple form that submits data to a simple script that calls PHP’s mail function.

This function has the following parameters:

mail($recipient, $subject, $message, $headers);

Note the $headers part. Headers are meta information about the message that contains the sender, subject, date sent, CC, BCC, the recipient name and other stuff that the mail deamons (and anti-spam software) puts and uses to track the email path from sender to recipient.

You may have noticed that I’ve put the word vulnerability between quotes. Yes, this is NOT a PHP function vulnerability but it becomes one when misused.

The fact is that as this function doesn’t have a $from parameter, people passes this information via the $header parameter as the following example.

$headers = "From: {$_POST['name']} <{$_POST['email']}>"; // "From: SomeUser <jon@doe.com>"

This is our fail-point: PHP Magic Quotes “protected” people from most XSS input attacks since it escapes quotes and stuff but as headers are separated by newlines (\n), the header can be easily spoofed by inputting:

Note that I’ve added a BCC entry and now the email is going to be sent to the email address specified under $recipient parameter at the mail function AND to my BCC entries.

“Congratulations, your e-mail form (and server) is being used now to send my spam”
(Just a quote, Heavyworks’ ethics code would never let me SPAM!)

Solution
Do not forward inputs directly to the header parameter or use a email class like Codeworx’s PHPMailer.

NOTE: Learn more about e-mail headers at Wikipedia

There is a Brazillian portuguese version of this vulnerability at Bruno’s Blog

Ubuntu is going Windows-way

Ubuntu is indeed responsible for the huge growth of Linux home-users due its simplicity of out-of-the-box use. As a brief retrospective, the emerging (in past) Linux distributions were always known to their difficulty on setting up the propper drivers and essential software. If you were installing on a laptop, things turned out to be a nightmare. At this point, only IT people used Linux because home-users were scared away (I think it coincided with the ugly GTK 1.x interfaces – under Gnome).

Ubuntu emerged to aid home-users and be more user-friendly, having and startup installation that would recognize and install all your drivers and give you a starting setup of the most common used tools like e-mail clients, IM clients, web browser and an office suite.
Read the full article