note 56788 deleted from function.mail by cmb
| From: | cmb@php.net | Date: | Sun, 21 Jul 2019 08:25:36 +0000 |
| Subject: | note 56788 deleted from function.mail by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211629@lists.php.net to get a copy of this message | ||
Note Submitter: GwarDrazul
----
The article mentioned below is quite good to understand the problem of header injection. However, it
suggests the following as a solution: look for "\n" and "\r" inside your user
input fields (especially in those used for the $header param) and, if found reject the mail.
Allthough this will probably work I still believe it is better to have a "white list" of
allowed characters instead of a "black list" with forbidden characters.
Example:
If you want a user to enter his name, then allow characters only!
If you want a user to enter his email adress, then check if the entry is a valid email adress.
Doing so might automatically solve problems which you didn't think of when you created the
"black list". For SMTP headers colons are needed. If you check for a valid email adress
the hacker won't be able to enter colons inside that form field.
I suggest using regular expressions for those checks.
For more information about regular expressions see:
http://www.regular-expressions.info/