Archives

Articles tagged ‘email’

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

Tracking your mail views via Web Beacons

One of the most common problems of working with email communication between the companies and its clients is that there isn’t a way of proving that user has received the email without making him click on a link to the company site thus confirming the read.

As most webmail and mail applications can read HTML emails (and most companies sends HTML emails anyway), we can take advantage of this to help transparently track the view.
Read the full article