| 1 |
MediaWiki extension: SpamBlacklist |
| 2 |
---------------------------------- |
| 3 |
|
| 4 |
SpamBlacklist is a simple edit filter extension. When someone tries to save the |
| 5 |
page, it checks the text against a potentially very large list of "bad" |
| 6 |
hostnames. If there is a match, it displays an error message to the user and |
| 7 |
refuses to save the page. |
| 8 |
|
| 9 |
To enable it, first download a copy of the SpamBlacklist directory and put it |
| 10 |
into your extensions directory. Then put the following at the end of your |
| 11 |
LocalSettings.php: |
| 12 |
|
| 13 |
wfLoadExtension ( 'SpamBlacklist' ); |
| 14 |
|
| 15 |
The list of bad URLs can be drawn from multiple sources. These sources are |
| 16 |
configured with the $wgBlacklistSettings global variable. This global variable |
| 17 |
can be set in LocalSettings.php. |
| 18 |
|
| 19 |
$wgBlacklistSettings is an array, where first key is either spam or email and |
| 20 |
their value containing either a URL, a filename or a database location. |
| 21 |
Specifying a database location allows you to draw the |
| 22 |
blacklist from a page on your wiki. The format of the database location |
| 23 |
specifier is "DB: <db name> <title>". |
| 24 |
|
| 25 |
Example: |
| 26 |
|
| 27 |
wfLoadExtension ( 'SpamBlacklist' ); |
| 28 |
$wgBlacklistSettings = [ |
| 29 |
'spam' => [ |
| 30 |
"$IP/extensions/SpamBlacklist/wikimedia_blacklist", // Wikimedia's list |
| 31 |
"DB: wikidb My_spam_blacklist", // database (wikidb), title (My_spam_blacklist) |
| 32 |
] |
| 33 |
]; |
| 34 |
|
| 35 |
The local pages [[MediaWiki:Spam-blacklist]] and [[MediaWiki:Spam-whitelist]] |
| 36 |
will always be used, whatever additional files are listed. |
| 37 |
|
| 38 |
Compatibility |
| 39 |
----------- |
| 40 |
|
| 41 |
This extension is primarily maintained to run on the latest release version |
| 42 |
of MediaWiki (1.33.x as of this writing) and development versions. |
| 43 |
|
| 44 |
If you are using an older version of MediaWiki, you can checkout an |
| 45 |
older release branch, for example MediaWiki 1.20 would use REL1_20. |
| 46 |
|
| 47 |
File format |
| 48 |
----------- |
| 49 |
|
| 50 |
In simple terms: |
| 51 |
* Everything from a "#" character to the end of the line is a comment |
| 52 |
* Every non-blank line is a regex fragment which will only match inside URLs |
| 53 |
|
| 54 |
Internally, a regex is formed which looks like this: |
| 55 |
|
| 56 |
!http://[a-z0-9\-.]*(line 1|line 2|line 3|....)!Si |
| 57 |
|
| 58 |
A few notes about this format. It's not necessary to add www to the start of |
| 59 |
hostnames, the regex is designed to match any subdomain. Don't add patterns |
| 60 |
to your file which may run off the end of the URL, e.g. anything containing |
| 61 |
".*". Unlike in some similar systems, the line-end metacharacter "$" will not |
| 62 |
assert the end of the hostname, it'll assert the end of the page. |
| 63 |
|
| 64 |
Performance |
| 65 |
----------- |
| 66 |
|
| 67 |
This extension uses a small "loader" file, to avoid loading all the code on |
| 68 |
every page view. This means that page view performance will not be affected |
| 69 |
even if you are not running a PHP bytecode cache such as Turck MMCache. Note |
| 70 |
that a bytecode cache is strongly recommended for any MediaWiki installation. |
| 71 |
|
| 72 |
The regex match itself generally adds an insignificant overhead to page saves, |
| 73 |
on the order of 100ms in our experience. However loading the spam file from disk |
| 74 |
or the database, and constructing the regex, may take a significant amount of |
| 75 |
time depending on your hardware. If you find that enabling this extension slows |
| 76 |
down saves excessively, try installing MemCached or another supported data |
| 77 |
caching solution. The SpamBlacklist extension will cache the constructed regex |
| 78 |
if such a system is present. |
| 79 |
|
| 80 |
Caching behavior |
| 81 |
---------------- |
| 82 |
|
| 83 |
Blacklist files loaded from remote web sites are cached locally, in the cache |
| 84 |
subsystem used for MediaWiki's localization. (This usually means the objectcache |
| 85 |
table on a default install.) |
| 86 |
|
| 87 |
By default, the list is cached for 15 minutes (if successfully fetched) or |
| 88 |
10 minutes (if the network fetch failed), after which point it will be fetched |
| 89 |
again when next requested. This should be a decent balance between avoiding |
| 90 |
too-frequent fetches if your site is frequently used and staying up to date. |
| 91 |
|
| 92 |
Fully-processed blacklist data may be cached in memcached or another shared |
| 93 |
memory cache if it's been configured in MediaWiki. |
| 94 |
|
| 95 |
Stability |
| 96 |
--------- |
| 97 |
|
| 98 |
This extension has not been widely tested outside Wikimedia. Although it has |
| 99 |
been in production on Wikimedia websites since December 2004, it should be |
| 100 |
considered experimental. Its design is simple, with little input validation, so |
| 101 |
unexpected behavior due to incorrect regular expression input or non-standard |
| 102 |
configuration is entirely possible. |
| 103 |
|
| 104 |
Obtaining or making blacklists |
| 105 |
------------------------------ |
| 106 |
|
| 107 |
The primary source for a MediaWiki-compatible blacklist file is the Wikimedia |
| 108 |
spam blacklist on meta: |
| 109 |
|
| 110 |
https://meta.wikimedia.org/wiki/Spam_blacklist |
| 111 |
|
| 112 |
In the default configuration, the extension loads this list from our site |
| 113 |
once every 10-15 minutes. |
| 114 |
|
| 115 |
The Wikimedia spam blacklist can only be edited by trusted administrators. |
| 116 |
Wikimedia hosts large, diverse wikis with many thousands of external links, |
| 117 |
hence the Wikimedia blacklist is comparatively conservative in the links it |
| 118 |
blocks. You may want to add your own keyword blocks or even ccTLD blocks. |
| 119 |
You may suggest modifications to the Wikimedia blacklist at: |
| 120 |
|
| 121 |
https://meta.wikimedia.org/wiki/Talk:Spam_blacklist |
| 122 |
|
| 123 |
To make maintenance of local lists easier, you may wish to add a DB: source to |
| 124 |
$wgBlacklistSettings and hence create a blacklist on your wiki. If you do this, |
| 125 |
it is strongly recommended that you protect the page from general editing. |
| 126 |
Besides the obvious danger that someone may add a regex that matches everything, |
| 127 |
please note that an attacker with the ability to input arbitrary regular |
| 128 |
expressions may be able to generate segfaults in the PCRE library. |
| 129 |
|
| 130 |
Whitelisting |
| 131 |
------------ |
| 132 |
|
| 133 |
You may sometimes find that a site listed in a centrally-maintained blacklist |
| 134 |
contains something you nonetheless want to link to. |
| 135 |
|
| 136 |
A local whitelist can be maintained by creating a [[MediaWiki:Spam-whitelist]] |
| 137 |
page and listing hostnames in it, using the same format as the blacklists. |
| 138 |
URLs matching the whitelist will be ignored locally. |
| 139 |
|
| 140 |
Logging |
| 141 |
------- |
| 142 |
|
| 143 |
To aid with tracking which domains are being spammed, this extension has |
| 144 |
multiple logging features. By default, hits are included in the standard |
| 145 |
debug log (controlled by $wgDebugLogFile). You can grep for 'SpamBlacklistHit', |
| 146 |
which includes the IP of the user and the URL they tried to submit. This |
| 147 |
file is only availible for people with server access and includes private info. |
| 148 |
|
| 149 |
You can also enable logging to [[Special:Log]] by setting $wgLogSpamBlacklistHits to |
| 150 |
true. This will include the account which tripped the blacklist, the page title the |
| 151 |
edit was attempted on, and the specific URL. By default this log is only viewable |
| 152 |
to wiki administrators, and you can grant other groups access by giving them the |
| 153 |
"spamblacklistlog" permission. |
| 154 |
|
| 155 |
Copyright |
| 156 |
--------- |
| 157 |
This extension and this documentation was written by Tim Starling (with later |
| 158 |
contributions by others) and is available under GPLv2 or any later version. |