Hacks : Avoid Comment Spam 1.01 Oct 06 2003 | # | C:6

Avoid Comment Spam 1.01

October 6, 2003 - updated July 28, 2006

Important Update: A much better solution that this hack is Jay Allan’s MT-Blacklist, a CGI/plugin combo that makes fighting comment spam simple and—dare I say it?—almost fun. You should only use this hack if you are running a version of MT that is not supported by Jay’s tool.

Comment Spam

Comment Spam is a comment whose only purpose is to cause your entry to link to some third party URL. Often the comment contains no text or something unrelated to your entry. The reason someone (or their automated software) would bother with spamming your blog this way, is to increase the number of pages linking to their URL and thus cause search engines to rank their page more prominently.

Jay Allan has a good article called Killing Comment Spam Dead that discusses this problem and offers a solution that prevents spamming comments from being displayed. Jay’s approach uses a blacklist of spamming sites that he publishes on his site. It requires you to modify your templates to hide spamming comments.

This hack uses the same blacklist to prevent the submission of known spamming URLs in the first place. It’s a generalized version of Phil Ringnalda’s approach to dealing with comment spam.

Install Nonplus::URLBanList Module

This hack uses the Nonplus::URLBanList module for parsing the banned list file and filtering text for banned URLs. Download the URLBanList.pm file and place it in the extlib/Nonplus directory inside your MovableType installation.

Install the blacklist

The blacklist is a text file containing URLs that have spammed your blog. You may want to get started with the list maintained by Jay Allan. Download that file and upload it into your MovableType directory as spam_urls.txt. You can maintain this list using MovableType’s template editor if you create a (template) module and link it to the spam_urls.txt file.

If you already have a Comment Spam Banned URL List template module (from Jay’s instructions), simple link it to the spam_urls.txt file.

lib/MT/App/Comments.pm Modification

Go to your MovableType installation directory, and open the file Comments.pm in the lib/MT/App subdirectory. Find the line that says:

    $comment->text($q->param('text'));

and insert the following code after it:

    ## BEGIN HACK Avoid Comment Spam
    ## http://www.nonplus.net/software/mt/AvoidCommentSpam.htm
    require Nonplus::URLBanList;
    my $banned = Nonplus::URLBanList->new('spam_urls.txt');
    if($banned->contains_banned($comment->url) ||
        $banned->contains_banned($comment->text)) {
        return $app->handle_error("Banned URL");
    }
    ## END HACK Avoid Comment Spam

Maintaining your Blacklist

The blacklist only protects you against spamming URLs that are in it. When you get spammed by a new URL, simply add it to the spam_urls.txt file, and manually delete the spam comment. Next time someone tries to spam you with that URL, they will not succeed.

Version History

  • Version 1.01 - October 14, 2003

    This hack has been replaced by Jay Allen’s MT-Blacklist
  • Version 1.0 - October 6, 2003

    Initial Release
The site database appears to be down.