views:

274

answers:

3

I am using combination of php+jQuery for captcha validation and later sending mails and do other stuff. The pseudo code is something like this:

captcha_code = jQuery.post(.....execute captcha script and get status)
if(captcha_code == "correct"){
    send_mail_using_php_script;
}

Now I have no idea whether spammers can directly execute the "send_mail_using_php_script". Do they? If yes, then shall I move captcha validation in send_mail_using_php_script to make it more safer? Is there any other safer method?

Prashant

A: 

Important for Captcha is that validation takes place on the server. That's the most important part to keep in mind.

Sander Pham
A: 

The validation should be done server side. While security through obscurity works ok against spam bots, anything on the client is fair game.

And a captcha "validated" on the client side defeats the purpose.

I am using a custom captcha script. What do you mean by server side? I am new to web programming so please have some patience with me.
By server side I mean, in this case, the PHP handler. The script that sends the mail should not run unless a valid captcha response was submitted. The first rule of web development is: don't trust user input.If you validate on the client side, in javascript, theres not much stopping someone from tweaking the code and turning you into a spam dispenser.
On a totally unrelated note, congrats on post ID 3000000, I just noticed it went by :)
Michael Mrozek
A: 

You're validating the actual captcha at the server side, but you're validating the result and instructing to send the mail in the client side. This is wrong. JavaScript/jQuery runs at the client machine and can be modified by the enduser the way s/he like. The enduser can for instance remove the if statement or make it always evaluate true and reexecute the code.

You need to instruct to send the mail at the server side, during processing of the form submit.

BalusC
Ok, What if I move the captcha validation inside "send_mail_using_php_script". I'll pass the captcha code entered in the input and the email address to script. First script will validate captcha and if it's correct then send a mail. I think this way both the things are happening at server side. Am I correct?
Yes, that's correct.
BalusC