Forum Moderators: coopster
I built a form that uses the mail() function, and we all know that they are subject to abuse from robots / spammers.
I therefore decided to make it as secure as I could, and we all know that I am not a great PHP developer :)
So here is what I did:
After all that, I am thinking that I might have missed something and wondered how you guys tested your forms as if you were attempting to spam them
cheers
[edited by: jatar_k at 12:42 pm (utc) on April 5, 2007]
[edit reason] fixed url [/edit]
# do you try to break it yourself by faking header injection? If so how?# do you have an automated programm that a spammer would use that tries to break it? If so did you build it yourself or did you find it online?
to answer both points will be a crime itself to leave sufficient information to teach one how to break openly even if he didn't know it before ;)
if you can check your server log then you can monitor the number of outgoing emails and that will give you a good idea if anything using your server resources to send their spams...
use a real captcha instead of a hardcoded question... the value should be an image, it should change randomly, take the values to the next page in sessions or cookies rather than a hidden form field...
do not allow user to mention TO field of MAIL and also I think that subject of the email should also be hard coded..
Check for well formed input:
is the email, URL, phone, ZIP etc formed as they are supposed to)
regex acceptable characters (EX: if phone #; NO Alpha Char)
Use eregi to check against terms such as DROP, UNLINK etc...
Disallow {}[] and whatever you need to
But the headaches comes when you need to filter but
need to allow for pasting from MS :)
Important is to use strlen() for defining an acceptable STR LENGTH corresponding to your DB field
minus 1 or 2 char(As per Jatar_k)
I check also for vulgar/bad words
Next I am also concerned with the user location
So I checked its IP (I disallow IP range from a few countries depending on a client specific needs) and also upon Countries well known for spam and worst.if the user is required to post its email address, I fully check it
And use also getmxrr()
If a DN is posted I modified a DN availability checker to verify if the DN exists or if it is a faked one
<edit>
Keep adding
</edit>
You can use some of these patterns to test.
mainly if you are very strict about what chars you let through and don't try to fix any user data, just spit it back at them, then you will do pretty well.
I use a custom log for most validation so that I can see what people are enteing and what passes and fails, this helps to better profile your validation routines.
>phparion - I will check to see if I have access to server logs re mail
use a real captcha instead of a hardcoded question... the value should be an image, it should change randomly, take the values to the next page in sessions or cookies rather than a hidden form field...
subject of the email should also be hard coded..
>henry0
A few years ago my forms were about a few lines long. Now they contains a few includes and are hundreds of line long happy!
I know what you mean my current checking script is 150+ lines long, but my form is very simple (a dozen fields)
Check for well formed input:
is the email, URL, phone, ZIP etc formed as they are supposed to) regex acceptable characters (EX: if phone #; NO Alpha Char)
I just mail this script at the moment but might end up with a db so thanks for the db related advices.
Disallow {}[] and whatever you need to
Next I am also concerned with the user location
So I checked its IP (I disallow IP range from a few countries depending on a client specific needs) and also upon Countries well known for spam and worst.if the user is required to post its email address, I fully check it
>jatar_k
mainly if you are very strict about what chars you let through and don't try to fix any user data, just spit it back at them, then you will do pretty well.
I use a custom log for most validation so that I can see what people are enteing and what passes and fails, this helps to better profile your validation routines.
ps. could a mod fix the url in my original post the . at the end went into the url and causes an error
just make a log file somewhere and for each failure you can log what part of your tests the data failed and what data was submitted by the user. You can log the full raw data that passed as well, though I usually only keep this on for a little while as it can create some huge logs in a hurry.
This can also help you better understand user behaviour.