APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Detecting Comment Spam, Part 3

© December 2009 Anthony Lawrence

This is a continuation of Detecting Comment Spam, Part 2

In the previous posts in this series, I've said that spammers habits allow us to detect their attempts to leave inappropriate comments. I use these techniques here and am able to send most spam comments directly to the bit-bucket without ever having to examine them myself. When I suspect spam but am not sure, I just send the comment to moderation. In practice, very few spam attempts get by the automatic filters.

The code I use is a hodgepodge I developed over many years of fighting spam comments. I need to rewrite it and my thought is to move toward a scoring system similar to that used by Spamassassin for mail spam: each "bad habit" increases an overall spam score and the final judgement is made based on the total score accumulated. To that end, I have been pulling out the various tests I use now and examining them. Some always cause the comment to be treated as spam; those would add enough points to ensure that would still happen. Other habits now cause moderation, but in my new design each of those will increase the spam score. Any spam score at all is cause for moderation, but if the post accumulates enough minor points, I can skip that and just throw it away.

By the way, there is an effort to create a BlogSpamAssassin.

Seven (or more) habits of ineffective spammers

I'll be reviewing things covered in the previous two posts and will introduce some new ideas. Items covered in the previous posts are marked with a "*".

* Known spam links: Reusing links we already know are spam. This would carry enough points to always be spam.

* High link to text ratio: Sometimes nothing but links. This could be legitimate, but it's a strong indicator. In my current code, this always treats the comment as spam, but I think I will change it so that at least one other spam point is required.

* Nonsense words: The higher the ratio of nonsense to total word count, the more likely this is spam.

* Many quick posts: Legitimate commenters may post more than once per day, but there will be some time delay between comments as they read the articles they are commenting on. I simply enforce a "posting too frequently" policy.

* Direct posts: Some spammers bypass your forms and send direct POST requests. That's definite spam.

* Typed too fast: Legitimate commenters MAY use cut and paste, but moving from form load to POST too quickly needs to carry some weight.

Multiple posts to same article: Legitimate commenters almost never post more than one comment without some other comment intervening. Sure, someone may have an afterthought and add a second comment, but more usually this indicates a spammer, so we should add points.

Same comment at another article: As always, spammers are lazy. They sometimes post exactly the same text to different articles. The posts may not come from the same IP address, but the content is the same. This should probably carry enough points for flat rejection. It does mean that you need to maintain a database, but you only need to store 100 characters or so (spam comments are usually short) and you can clean it out after 24 or 48 hours.

Text and link have same word: This is a minor spam indicator, but if the word "Horrivea" appears as "Buy Horrivea: https://someaddress/horivea", it may be spam.

Failure to reload: I require clicking on a link to reload the original page after submitting a comment. A legitimate poster will almost always click, a spammer almost never will. Again, this is not an absolute indicator, but is worth a point or two.

External tests

Akismet is a popular comment checker. I have found it to be less effective than my own tests, but it can't hurt to have another opinion, can it?

Captcha tests: As this technology is annoying, you might consider adding it as a confirmation only when some other conditions have raised suspicion. Similar tests involve solving simple math or providing answers to obvious questions. Spammers are in a hurry; they are usually using bots and if not they just don't want to spend time thinking, however small that time is.

Legitimate Commenters Habits

There are a few things that spammers don't usually do. Legitimate comments almost always use punctuation, so the presence of punctuation could decrease a spam count. Legitimate posters sometimes quote text from the article or from a previous comment; spammers almost never do that, so again we might decrease a spam score if we see this.


We can control spam comments. Not all of it, but we can limit the amount that has to be checked manually and we don't need to annoy our visitors with required registration or automatic "human reader" testing.

I'd love to hear your thoughts, comments and ideas.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Detecting Comment Spam, Part 3


Inexpensive and informative Apple related e-books:

El Capitan: A Take Control Crash Course

Take Control of OS X Server

Take Control of Parallels Desktop 12

Digital Sharing Crash Course

Take Control of Pages

More Articles by © Anthony Lawrence

Thu Dec 31 00:24:49 2009: 7838   DaleReagan



As usual some good info. :)

I would suggest adding web log checks for:

a) referral links (where is the BSpammer coming from) and/or
b) search links (how is the BSpammer finding you)

I am seeing patterns which leads me to create new rules Using Apache + Mod_Security (a WAF - web application firewall.) I also do some auto-scanning of web server logs to auto-create IP bans for bots... I then aggregate abuses and ban entire subnets based on my very low threshold for any type of SPAM. I am sure that Bot-abuse will vary depending upon the size of a given web site (as well as geo-location) and IP-banning may not be a good solution for all but it works well for me since I do not typically have business concerns for the locations from which Bot/Spammers seem to be operating from (i.e. currently mostly from Europe and Asia.)

This AM I had 43 'comment posts' (Blog SPAM, of course) that managed to get by the CAPTCHA tool - the IPs are now banned. My guess is that bots reported the CAPTCHA and a human returned to create the SPAM.

There are also additional benefits from using Mod_Security - worth exploring for anyone interested in keeping a web site online and relatively secure.

Of course, your mileage should vary. :)


Thu Dec 31 01:49:13 2009: 7839   TonyLawrence


I hadn't thought of looking back for referral/search - thanks!


Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

As I said in my comments to the committee, [Fortran 90' would be a] nice language, too bad it's not Fortran. (Dan Davison)

Linux posts

Troubleshooting posts

This post tagged:




Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode