WordPress Tip: Quick Hack to Block Spam for the Wordspew Shoutbox Chat Plugin

Recently, I reactivated an older version (1.16) of Jalenack’s Wordspew Shoutbox plugin for the Dead Letter Art Chat Forum. The DLa collective has been working on a new issue of their ‘zine and needed an easy online chat location for impromptu business dealz (ideas, planning, etc.). Almost immediately after reactivating the Shoutbox plugin, the chat forum was flooded with an endless wave of spam. The rate and volume of spam was so high as to render the forum utterly useless. — Ugh. Update: We now use Simple Ajax Chat for all of our chat-forum needs. It’s supa fresh.

Determined, we tried several unsuccessful techniques for blocking the relentless spam attack:

  • Enabling of the “Only allow registered users” option
  • Tweaking of the default “CENSORS” filter within the script
  • Locking things down via htaccess password restriction
  • Locking things down via PHP password restriction

Serendipitously, while tweaking the script’s “CENSORS” filter, I noticed the subsequent setting of several key variables:

  • $jal_user_text
  • $jal_user_name
  • $jal_user_url

Aha! Using PHPs stristr() function, it is possible to immediately test each of these three variables for key character strings. Based on the results of such a test, it is then possible to block any chat posts containing spam-related content. In my experience, 99.9% of chat spam contains one of the following characters:

  • href
  • http

Thus, by testing each variable for any instances of these character sequences, it is possible to block 99.9% of the spam from hitting Wordspew-powered chat rooms. This technique effectively blocks any chat posts or usernames containing links and/or complete URLs (i.e., any URL containing “http”). This requires that “legitimate” chat users refer to URLs in the following format:

domain.tld/path/blah/blah

Not as easy as clicking on a link or copy/pasting a full URL, but definitely a small price to pay for a virtually spam-free chat forum.

The Fix

For older versions of Wordspew (the DLa site uses a highly customized version 1.16), open the plugin’s wordspew.php file and locate the following chunk of code, which is located just after the “CENSORS” option:

$jal_user_text = jal_special_chars(trim($jal_user_text));
$jal_user_name = (empty($jal_user_name)) ? "Anonymous" : jal_special_chars($jal_user_name);
$jal_user_url = ($jal_user_url == "http://") ? "" : jal_special_chars($jal_user_url);

Or, for newer versions of Wordspew, locate the following code in the wordspew.php file (this example taken from version 2.4):

global $jal_table_prefix;
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);

Then, immediately after the last line of the relevant code block, insert the following anti-spam hack:

// BEGIN ANTISPAM HACK >>>>>>>>>>>>>>>

if (
	stristr($jal_user_text,'href') || 
	stristr($jal_user_text,'http') || 
	stristr($jal_user_name,'href') || 
	stristr($jal_user_name,'http') || 
	 !empty($jal_user_url) 
	) { 
		die(); 
}

// END ANTISPAM HACK >>>>>>>>>>>>>>>>>

And that’s it! Save, upload the file and refresh your chat screen. If you listen carefully, you will hear the sounds of a million spam posts bouncing off the walls. Ahhhhhh, so nice ;)

Sealing the Deal..

After implementing this hack on the Dead Letter Art website (taken offline in 2011), chat spam dropped to nearly zero, leaving us with a relaxed, peaceful, and spam-free forum that is available whenever we need it. Hopefully, future versions of the excellent Wordspew plugin will include similarly effective spam protection. For now, this “quick and dirty” hack will definitely do the job.