Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@
add_action( 'login_init', 'send_frame_options_header', 10, 0 );
add_action( 'login_init', 'wp_admin_headers' );

// Registration
add_filter( 'validate_username', 'wp_validate_username_spam', 10, 2 );

// Feed generator tags.
foreach ( array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) {
add_action( $action, 'the_generator' );
Expand Down
16 changes: 16 additions & 0 deletions src/wp-includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -5094,6 +5094,22 @@ function wp_validate_user_request_key(
return true;
}

/**
* Reject usernames that can be used for spamming people.
*
* @param string $username Username to check.
* @return bool Whether username given is valid.
*/
function wp_validate_username_spam( $valid, $username ) {
//username begins with "www." or has " www." in it,
// which gets auto-linked by email clients
if ( strpos( ' ' . $username, ' www.' ) !== false ) {
return false;
}

return $valid;
}

/**
* Returns the user request object for the specified request ID.
*
Expand Down
8 changes: 8 additions & 0 deletions tests/phpunit/tests/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,14 @@ public function test_validate_username_invalid() {
$this->assertFalse( validate_username( '@#&99sd' ) );
}

/**
* @ticket 63085
*/
public function test_validate_username_spam() {
$this->assertFalse( validate_username( 'www.example.com - 1.2342 BTC' ) );
$this->assertFalse( validate_username( '1.23 BTC www.spammer.example.com' ) );
}

/**
* @ticket 29880
*/
Expand Down
Loading