PHP E-mail Injections
First, look at the PHP code from the previous chapter:
if (isset($_REQUEST['email']))"; } ?> |
The problem with the code above is that unauthorized users can insert data into the
mail headers via the input form.
What happens if the user adds the following text to the email input field in
the form?
someone@example.com%0ACc:person2@example.com |
The mail() function puts the text above into the mail headers as usual, and now the
header has an extra Cc:, Bcc:, and To: field. When the user clicks the submit
button, the e-mail will be sent to all of the addresses above!
PHP Stopping E-mail Injections
The best way to stop e-mail injections is to validate the input.
The code below is the same as in the previous chapter, but now we have added an input validator
that checks the email field in the form:
if (isset($_REQUEST['email'])) //check if the email address is invalid"; } ?> |
In the code above we use PHP filters to validate input:
- The FILTER_SANITIZE_EMAIL filter removes all illegal e-mail characters
from a string - The FILTER_VALIDATE_EMAIL filter validates value as an e-mail address
No comments:
Post a Comment