Preventing Comment Spam with JavaScript bot detection
Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.
I got my first comment spam on this blog the other day. It inspired me to try an idea I got a few months back. My theory was that these bots aren’t very smart – they are programmed to post as many comments as possible on as many sites as possible, hoping that a handful of these comments would get past whatever system the blogger was using to prevent spam. I hypothesized that these bots did not understand JavaScript, and that by requiring some JavaScript to run in the browser I would be able to check with reasonable accuracy weather the comment was submitted by a human or a bot.
I wrote up a simple plugin to test the theory. I checked the logs to find that I was right. In fact, most of the bots that were spamming my blog did not even include the hidden element, which indicates that they were posting to the wp-comments-post.php file directly rather than accessing the form first. The bots that did access the form did not execute the JavaScript and therefore their comments were blocked. Since the trick only involves JavaScript, most users will not even notice the difference. Users without JavaScript simply need to follow the given instructions to copy a number to a text box in order to prove they are human. This is what users without JavaScript will see:
If you want to use JSSpamBlock on your blog, check out the JSSpamBlock project page.



That’s actually quite cool. A lot of blogs use some capcha/challenge against bots, at the expense of annoying users. Having a JavaScript autofill that field is simply… brilliant.
Hey Paul,
keep up the good posts.
I use Akismet spam protection, and there’s also brian’s threated-comments plugin which allows you to change the name of your wordpress comment post file. mine is something liek “i-hate-spamming-assholes.php” or somethign like that.
I still get HUNDREDS of spam filtered through teh Akis met spam protection, and once ina while I get one slipping by.
Great job hopefully this will stop the constant spam on my site. Also noted you’re also from halifax as well :)
Cool, small world, eh?
Is there any way so that I can use this plugin to present a challenge regardless of javascript being present?
Fred, you could remove everything between < script > and < /script > and it will function as you want. The reason I do not provide this as an option is that my understanding is that there are already several scripts that do what you are looking for. If this isn’t the case, I can make an official version that works that way.
So far, I haven’t seen any bots get past it.
Thanks Paul I’ll give the full version a try 1st.
I personally use Akismet on all the blogs I run, still this looks like an interesting approach. Good job!
paul -
thanks for the plugin. elegant!
a suggestion:
it would be helpful if you included – maybe in the readme.txt – the SQL for creating the database table manually. for me it wasn´t such a big deal to extract it from the .php script, but others maybe not find it so easy.
I’ve been using Akismet for awhile, but it has always bugged me that it does might actually *encourage* spammers. After all, the post was successful as far as the bot can tell….no error messages. I’d rather the spam not get into my database to begin with. Thanks for the great script!
Glenn, I’m glad you like it. Unfortunately, based on my experience with spam bots, I doubt they even bother to check the output after attempting to post a comment, but if they do, the plugin will sere them up a nice error message.
[...] way JSSpamBlock has evolved since I first released it has reminded me why I love open-source. From day one, I had users pointing out bugs and features [...]
An amazing, an elegant and a human friendly solution! Thanks a lot! If I were a painter I would create some masterpiece where a human defeats the spam bot! :) good luck!
[...] while ago I installed Paul Butler’s JSSpamBlock on my Wordpress blog here. His original idea is simple and brilliant: Spambots don’t [...]
Well, I’m rather sceptical about this. There were so many programs against spam that seemed brilliant and all of them failed some time later. Will check this one out soon!
Not Using WordPress…does this work for FrontPage apps using JavaScript? If so, how do you install it?
RC – It could work for FrontPage, but not without modification. Others have already modified it to work with Perl and other PHP apps.
I want to test the comment
This method is good to protect spam. :)
Pharmacy Discount
<a href= Buy Generic Viagra Pharmacy
Canadian Levitra Pharmacy
Cheap Generic Levitra Pharmacy
Canadian drugs online
No prescription Pharmacy
Order Best Generic Viagra Online
Discount Pharmacy Online
Online Discount Generic Pharmacy
Discount Cialis
Online Pharmacy Online
Discount Generic Drugs Online
Buy Indian Generic Drugs Without prescription
Pharmacy Online Levitra
Discount Medications On-Line
Discount ED Pharmacy Online
discount Viagra Online
USA ED Drugs online
Cheap drugs online
Canadian Pharmacy
ED Store
Discount Pharmacy
Order Cialis Pharmacy
Indian Cheap Pharmacy
Order Generic Drugs No rescription
Generic Pharmacy Online
Discount ViagraNo prescription
, , girl bou, , , , , 22 , , , , , , , 25, , , , , , , , , , , , , , , , , , , , , , , , , , 5 , , icq, , , , , 25 3 , 3 ,