r51105 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51104‎ | r51105 | r51106 >
Date:10:00, 28 May 2009
Author:werdna
Status:ok
Tags:
Comment:
Prevent Tor users from emailing other users
Modified paths:
  • /trunk/extensions/TorBlock/TorBlock.class.php (modified) (history)
  • /trunk/extensions/TorBlock/TorBlock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialEmailuser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialEmailuser.php
@@ -48,6 +48,12 @@
4949 case 'mailnologin':
5050 $wgOut->showErrorPage( 'mailnologin', 'mailnologintext' );
5151 return;
 52+ default:
 53+ // It's a hook error
 54+ list( $title, $msg, $params ) = $error;
 55+ $wgOut->showErrorPage( $title, $msg, $params );
 56+ return;
 57+
5258 }
5359 }
5460
@@ -297,12 +303,17 @@
298304 return 'actionthrottledtext';
299305 }
300306
 307+ $hookErr = null;
 308+ wfRunHooks( 'EmailUserPermissionsErrors', array( $user, $editToken, &$hookErr ) );
 309+
 310+ if ($hookErr) {
 311+ return $hookErr;
 312+ }
 313+
301314 if( !$user->matchEditToken( $editToken ) ) {
302315 wfDebug( "Matching edit token failed.\n" );
303316 return 'sessionfailure';
304317 }
305 -
306 - return;
307318 }
308319
309320 static function newFromURL( $target, $text, $subject, $cc_me )
Index: trunk/extensions/TorBlock/TorBlock.php
@@ -36,6 +36,7 @@
3737 $wgHooks['ListDefinedTags'][] = 'TorBlock::onListDefinedTags';
3838 $wgHooks['AbuseFilter-filterAction'][] = 'TorBlock::onAbuseFilterFilterAction';
3939 $wgHooks['AbuseFilter-builder'][] = 'TorBlock::onAbuseFilterBuilder';
 40+$wgHooks['EmailUserPermissionsErrors'][] = 'TorBlock::onEmailUserPermissionsErrors';
4041
4142 // Define new autopromote condition
4243 define('APCOND_TOR', 'tor'); // Numbers won't work, we'll get collisions
Index: trunk/extensions/TorBlock/TorBlock.class.php
@@ -41,6 +41,42 @@
4242 return true;
4343 }
4444
 45+ public static function onEmailUserPermissionsErrors( $user, $editToken, &$hookError ) {
 46+ wfDebug( "Checking Tor status\n" );
 47+
 48+ // Just in case we're checking another user
 49+ global $wgUser;
 50+ if ( $user->getName() != $wgUser->getName() ) {
 51+ return true;
 52+ }
 53+
 54+ if (self::isExitNode()) {
 55+ wfDebug( "-User detected as editing through tor.\n" );
 56+
 57+ global $wgTorBypassPermissions;
 58+ foreach( $wgTorBypassPermissions as $perm) {
 59+ if ($user->isAllowed( $perm )) {
 60+ wfDebug( "-User has $perm permission. Exempting from Tor Blocks\n" );
 61+ return true;
 62+ }
 63+ }
 64+
 65+ if (Block::isWhitelistedFromAutoblocks( wfGetIp() )) {
 66+ wfDebug( "-IP is in autoblock whitelist. Exempting from Tor blocks.\n" );
 67+ return true;
 68+ }
 69+
 70+ $ip = wfGetIp();
 71+ wfDebug( "-User detected as editing from Tor node. Denying email.\n" );
 72+
 73+ wfLoadExtensionMessages( 'TorBlock' );
 74+ $hookError = array( 'permissionserrors', 'torblock-blocked', array( $ip ) );
 75+ return false;
 76+ }
 77+
 78+ return true;
 79+ }
 80+
4581 public static function onAbuseFilterFilterAction( &$vars, $title ) {
4682 $vars->setVar( 'tor_exit_node', self::isExitNode() ? 1 : 0 );
4783 return true;
@@ -137,6 +173,7 @@
138174 global $wgTorDisableAdminBlocks;
139175 if ($wgTorDisableAdminBlocks && self::isExitNode() && $user->mBlock && !$user->mBlock->mUser) {
140176 wfDebug( "User using Tor node. Disabling IP block as it was probably targetted at the tor node." );
 177+
141178 // Node is probably blocked for being a Tor node. Remove block.
142179 $user->mBlockedby = 0;
143180 }

Status & tagging log