-
☆ A M B ☆
- 24,524 Posts
A heads-up for any snippet developers involving email:
http://securephp.damonkohler.com/index.php/Email_Injection
Totally unsuspecting script users are getting their sites shut down over this issue.
http://il.php.net/mail (at the bottom, in the user contributed notes)
Validate ALL user input!!!
Well you might want to add captcha codes to your mail forms
Less intrusive would be to test all input fields with regular expressions, to see if it doesn’t containt weird characters.
Maybe some regexp guru can aid here.
I’m no expert on email security or event PHP security but I’ll throw my two cents in.
ALWAYS hard code the recipient. Don’t ever let user input determine where the email is sent to unless you are working in a very trusted environment.
If you follow the above rule then the only other method that they can use the PHP mail function to send to unintended recipients is if it’s injected through the additional_headers paramater. So your best bet is to not use additional_headers or hard code them. If you must use additonal headers, check your input carefully. Specifically, check for @, CC:, BCC: and other header tags.
-
☆ A M B ☆
- 24,524 Posts
That’s the point of the article. You hard-code your recipient, you even maybe hardcode your subject. But a malicious user can inject more into the "your email" input field, or even the body textarea. And they have a nice regexp at the bottom to use in checking your input.
Mostly you need to check for an injection of a linefeed character into the user’s email; it’s just like sql injection, enter a valid email then %0A and whatever you want added to the message headers, including more To lines, Bcc, Cc, whatever you want, even adding boundaries and your own message content when the message is hardcoded!
The thing is, I uploaded their sample mailing app to my site, and tried the injection (I have more than one email, I just tried to "spam" myself), and it didn’t work; all I got was long From: lines with all the code. I must be missing something.
Try this article. I would love someone to be able to intergrate it with FormProcessor
http://www.alt-php-faq.org/local/115/