Battling Comment Spam

coldfusionweb

Fighting comment spam seams like a never ending battle. I've done a lot over the last few years to try and squash it on my blog.

I started out by implementing a list of words that would trigger the comment to be blocked. I found myself updating this list on a weekly basis, never staying on top of it.

I solved that problem by implementing the Bayesian Filter CFC from fusionKit. The bayes filter has worked really well, and produced a suprisingly low number of false positives.

Now just over the weekend I was flodded with a ton of comment spams that were written well enough to get past the bayes filter. They were also all submitted within a few minutes, so there was no time to train my bayes filter.

I'm not a big fan of statically blocking IP addresses, since the owners of IP addresses can change over time. However I think temporary blocks on IP's are OK, so I wrote a little rate limiter that will block IP's that try to post more than 1 comment within a 5 minute time span or IP's that have attempted to post a large number of comments.

I'm sure some of you have probably experienced the same problem, so here you go:

<cfif IsDefined("application.rate_limiter")>
  <cfif StructKeyExists(application.rate_limiter, CGI.REMOTE_ADDR)>
    <cfif application.rate_limiter[CGI.REMOTE_ADDR].attemps GT 1 AND DateDiff("n", application.rate_limiter[CGI.REMOTE_ADDR].last_attempt, Now()) LT 5>
      <p>You are posting too many comments too fast, please slow down and wait 5 min.</p>
      <cfset application.rate_limiter[CGI.REMOTE_ADDR].attemps = application.rate_limiter[CGI.REMOTE_ADDR].attemps + 1>
      <cfset application.rate_limiter[CGI.REMOTE_ADDR].last_attempt = Now()>
      <cfabort>
    <cfelseif application.rate_limiter[CGI.REMOTE_ADDR].attemps GT 20>
      <p>You have made too many attempts to post a comment. Please try back in a few days.</p>
      <cfset application.rate_limiter[CGI.REMOTE_ADDR].attemps = application.rate_limiter[CGI.REMOTE_ADDR].attemps + 1>
      <cfset application.rate_limiter[CGI.REMOTE_ADDR].last_attempt = Now()>
      <cfabort>
    <cfelse>
      <cfset application.rate_limiter[CGI.REMOTE_ADDR].attemps = application.rate_limiter[CGI.REMOTE_ADDR].attemps + 1>
      <cfset application.rate_limiter[CGI.REMOTE_ADDR].last_attempt = Now()>
    </cfif>
  <cfelse>
    <cfset application.rate_limiter[CGI.REMOTE_ADDR] = StructNew()>
    <cfset application.rate_limiter[CGI.REMOTE_ADDR].attemps = 1>
    <cfset application.rate_limiter[CGI.REMOTE_ADDR].last_attempt = Now()>
  </cfif>
<cfelse>
  <cfset application.rate_limiter = StructNew()>
  <cfset application.rate_limiter[CGI.REMOTE_ADDR] = StructNew()>
  <cfset application.rate_limiter[CGI.REMOTE_ADDR].attemps = 1>
  <cfset application.rate_limiter[CGI.REMOTE_ADDR].last_attempt = Now()>
</cfif>


Related Entries

14 people found this page useful, what do you think?

 Download FuseGuard WAF for ColdFusion

Trackbacks

Trackback Address: 623/E52715069FFF9476B54A05F9A9715994

Comments

On 01/31/2007 at 5:10:52 PM EST Jason Troy wrote:
1
Pete, check out this project from Jake Munson cfformprotect.riaforge.org

On 01/31/2007 at 5:16:13 PM EST jonese wrote:
2
Have your tried the CFAkismet CFC?

http://devnulled.com/cfakismet

We put it on our blog (http://blog.d-p.com) and love it.

On 02/01/2007 at 9:47:30 AM EST Dan G. Switzer, II wrote:
3
@Pete:

You might want to adjust the 1 comment per 5 minutes to at least 2 commments. 1 seems a little to strict--especially in the case where someone wants to post an addendum to what they typed.

On 02/01/2007 at 10:10:35 AM EST Pete Freitag wrote:
4
Hey Dan,

Actually it does allow for two comments since it says GT 1 and the attempts are incremented after that point. I wasn't clear about that in my post however. Thanks for pointing that out.

On 05/04/2007 at 2:56:09 AM EDT idwebtemplate wrote:
5
I can understand your code. Could you give me the PHP version please

On 08/15/2007 at 12:15:14 AM EDT Bob wrote:
6
Great site!e

On 08/23/2007 at 10:49:40 PM EDT Bob wrote:
7
Good luck with your site in the future!e

On 10/12/2007 at 7:30:16 AM EDT Tim wrote:
8
Good job, here and there!k

On 01/29/2008 at 8:58:32 PM EST Hiskseifs wrote:
9
Hello heavenly worck new look senks void akaaunting Bye

On 02/23/2008 at 10:03:05 AM EST Hannes wrote:
10
Just wanted to say helloo

On 02/25/2008 at 9:43:06 PM EST jammarlibre wrote:
11
Hi our little brothers.c

On 05/27/2008 at 8:33:35 PM EDT Melissa wrote:
12
Are you a big fan of movies and all the new releases on the big screen? Do you like to watch all the latest movies as soon as they are released? If the answer is yes, and you not only love to watch movies but you also like to get loads of other movie related products as well then there is a web site that is perfectly suited to you. The web site that you should consider taking a look at is called. The Films gives its visitors the chance to down load many of the latest movie releases as well as offering loads of news about all that is going on with in the movie industry and the actors in and around Hollywood. From this web sites well designed menu system you can also access movie sound tracks, and down load wall papers of you favorite movies and movie stars.

On 10/22/2009 at 9:12:02 AM EDT Daddy49 wrote:
13
Its like trying to control the weather, at this point, mother nature is gonna do what she wants to do. ,

On 09/20/2010 at 1:56:20 AM EDT watch saw 7 online wrote:
14
Thanks for sharing this link, but unfortunately it seems to be offline... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if a staff member here at www.petefreitag.com could post it.

Thanks, John

On 09/25/2010 at 7:00:20 AM EDT watch the social network online wrote:
15
Thanks for sharing this link, but unfortunately it seems to be offline... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if a staff member here at www.petefreitag.com could post it.

Thanks, Mark

On 09/28/2010 at 2:49:44 AM EDT watch the social network online wrote:
16
Thanks for sharing the link, but unfortunately it seems to be offline... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if a staff member here at www.petefreitag.com could post it.

Thanks, Alex

On 10/03/2010 at 4:51:33 PM EDT buy kinect wrote:
17
Thanks for sharing this link, but unfortunately it seems to be down... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if a staff member here at www.petefreitag.com could post it.

Thanks, Oliver

On 10/14/2010 at 12:06:53 PM EDT buy kinect wrote:
18
Hey, This is a inquiry for the webmaster/admin here at www.petefreitag.com.

May I use part of the information from your post above if I provide a backlink back to this site?

Thanks, Jack

On 10/15/2010 at 5:39:59 AM EDT watch harry potter and the deathly hallows online wrote:
19
Thanks for sharing this link, but unfortunately it seems to be down... Does anybody have a mirror or another source? Please answer to my message if you do!

I would appreciate if someone here at www.petefreitag.com could post it.

Thanks, Harry

On 10/19/2010 at 7:49:44 PM EDT OnlineSpeedDating wrote:
20
Have you considered the fact that this might work another way? I am wondering if anyone else has come across something exactly the same in the past? Let me know your thoughts...

On 10/19/2010 at 8:06:46 PM EDT watch megamind online wrote:
21
Thanks for sharing the link, but argg it seems to be offline... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if someone here at www.petefreitag.com could post it.

Thanks, Daniel

On 10/24/2010 at 9:55:21 PM EDT buy kinect wrote:
22
Hello there, This is a message for the webmaster/admin here at www.petefreitag.com.

Can I use some of the information from your blog post right above if I provide a link back to your website?

Thanks, William

On 10/25/2010 at 4:17:54 AM EDT buy kinect wrote:
23
Hi, I have a inquiry for the webmaster/admin here at www.petefreitag.com.

Can I use some of the information from your blog post right above if I provide a link back to your site?

Thanks, William

On 11/10/2010 at 10:17:52 PM EST bidou wrote:
24
Hi, I have a question for the webmaster/admin here at www.petefreitag.com.

May I use part of the information from your post above if I provide a link back to your site?

Thanks, John

On 12/08/2010 at 5:30:56 PM EST watch Justin Bieber Never Say Never online free wrote:
25
Hello there, Thanks for sharing the link - but unfortunately it seems to be not working? Does anybody here at www.petefreitag.com have a mirror or another source?

Thanks, Thomas

On 12/27/2010 at 10:01:55 AM EST watch the green hornet online wrote:
26
Greetings, Thanks for sharing the link - but unfortunately it seems to be not working? Does anybody here at www.petefreitag.com have a mirror or another source?

Thanks, Daniel

On 01/02/2011 at 5:16:29 PM EST watch the green hornet online wrote:
27
Hello, Thanks for sharing the link - but unfortunately it seems to be not working? Does anybody here at www.petefreitag.com have a mirror or another source?

Thanks, Oliver

On 01/05/2011 at 11:38:02 PM EST watch the green hornet online wrote:
28
Hello there, Thanks for sharing this link - but unfortunately it seems to be down? Does anybody here at www.petefreitag.com have a mirror or another source?

Thanks, Daniel

On 01/17/2011 at 11:56:09 PM EST watch the green hornet online wrote:
29
Greetings, Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at www.petefreitag.com have a mirror or another source?

Cheers, Daniel

On 01/31/2011 at 4:00:07 PM EST Red Movie DVD wrote:
30
Hiya Guys Is It Possible To WATCH BLU RAY DVDs Using A REGULARE DVD PLAYER? i would you like to purchase a movie but its a blu-ray 1....i do not have a blu ray player though....can it still work?? Bless you !

On 02/24/2011 at 6:21:01 AM EST montreal canadiens tickets wrote:
31
Hello there, This is a inquiry for the webmaster/admin here at www.petefreitag.com.

Can I use part of the information from this post above if I give a link back to this site?

Thanks, Harry

On 03/02/2011 at 5:39:40 AM EST watch I am Number Four online wrote:
32
Hey, Thanks for sharing this link - but unfortunately it seems to be down? Does anybody here at www.petefreitag.com have a mirror or another source?

Cheers, James

On 03/17/2011 at 5:36:50 PM EDT watch Rio online wrote:
33
Hello there, Thanks for sharing this link - but unfortunately it seems to be down? Does anybody here at www.petefreitag.com have a mirror or another source?

Cheers, Jack

On 03/18/2011 at 4:04:17 AM EDT Ylanne S. wrote:
34
I have a blog (Fugitive Seeking Truth) and have had a number of my posts comment-spammed with the same comment that appears several times on this page:

"Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at [my blog address] have a mirror or another source?" with a name attached.

I also have the comment requesting permission to backlink. Any idea who posts these comments and why?

Thanks,

Blessings and peace, Ylanne

On 03/24/2011 at 9:19:57 PM EDT watch Rio online wrote:
35
Hello there, Thanks for sharing this link - but unfortunately it seems to be not working? Does anybody here at www.petefreitag.com have a mirror or another source?

Cheers, Peter

On 08/22/2011 at 3:32:36 PM EDT Hospital Panel wrote:
36
Hi! I know this is somewhat off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having trouble finding one? Thanks a lot!

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?