Skip to content

Commit 33a14e4

Browse files
committed
Registration: Reject usernames that contain "www."
Wordpress registration e-mails are used to send bitcoin spam to people - by using usernames with spaces like > www.spammer.example.com - 1.2342 BTC This patch filters out usernames that begin with "www." or contain " www." - such names are auto-linked by email clients and made clickable. Documented occurences of that spamming problem: - https://cweiske.de/tagebuch/wordpress-registration-spam.htm - https://www.reddit.com/r/Wordpress/comments/1gyyhx7/spammed_with_100_fake_wordpress_login_emails_help/ Fixes #63085.
1 parent b10d2f9 commit 33a14e4

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/wp-includes/default-filters.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@
393393
add_action( 'login_init', 'send_frame_options_header', 10, 0 );
394394
add_action( 'login_init', 'wp_admin_headers' );
395395

396+
// Registration
397+
add_filter( 'validate_username', 'wp_validate_username_spam', 10, 2 );
398+
396399
// Feed generator tags.
397400
foreach ( array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) {
398401
add_action( $action, 'the_generator' );

src/wp-includes/user.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5094,6 +5094,22 @@ function wp_validate_user_request_key(
50945094
return true;
50955095
}
50965096

5097+
/**
5098+
* Reject usernames that can be used for spamming people.
5099+
*
5100+
* @param string $username Username to check.
5101+
* @return bool Whether username given is valid.
5102+
*/
5103+
function wp_validate_username_spam( $valid, $username ) {
5104+
//username begins with "www." or has " www." in it,
5105+
// which gets auto-linked by email clients
5106+
if ( strpos( ' ' . $username, ' www.' ) !== false ) {
5107+
return false;
5108+
}
5109+
5110+
return $valid;
5111+
}
5112+
50975113
/**
50985114
* Returns the user request object for the specified request ID.
50995115
*

tests/phpunit/tests/user.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,14 @@ public function test_validate_username_invalid() {
12731273
$this->assertFalse( validate_username( '@#&99sd' ) );
12741274
}
12751275

1276+
/**
1277+
* @ticket 63085
1278+
*/
1279+
public function test_validate_username_spam() {
1280+
$this->assertFalse( validate_username( 'www.example.com - 1.2342 BTC' ) );
1281+
$this->assertFalse( validate_username( '1.23 BTC www.spammer.example.com' ) );
1282+
}
1283+
12761284
/**
12771285
* @ticket 29880
12781286
*/

0 commit comments

Comments
 (0)