WordPress Admin Password can be Reset by Anyone (Fix Provided)

[Update: WordPress 2.8.4, which fixes this, has been released.]

We have a problem, folks. It turns out there is a way for anyone to reset your admin password without your permission. This exploit will not give them the new admin password. Nor will it permanently lock you out, as the new password will be mailed to your email address. Even so, it is still annoying to find yourself locked out of your own blog.

How do you do it? No, I’m not going to tell you. If you really want to know, I’m sure you can find out. Unlike some fishy programmers (read: jerks), I don’t really feel the need to propagate instructions for causing problems for other webmasters.

That said, I will happily provide the solution. I might even hack it into quick plugin tonight if I get the time, for people who don’t feel like either modifying their source code or waiting for a 2.8.4 security release.

Here’s the fix:

  1. Open wp-login.php in your text editor of choice.
  2. Go to either line 190 (2.8.*) or line 169 (earlier versions). In either case, look for a little chunk of code that looks like this:
    $key = preg_replace('/[^a-z0-9]/i', '', $key);
    
    if ( empty( $key ))
      return new WP_Error('invalid_key', __('Invalid key'));
    
    $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users ...
    
  3. Change the if line to be this:
    if ( empty( $key ) || is_array( $key ))
    
  4. Save the file and save yourself a headache.
  5. For the curious, here is the official documentation for the fix at WordPress’s trac site.

    Related Posts

    • Own Your Mistakes
      The last week has seen two major failures on the Internet. The most important difference between the two failures is not what failed or why it failed or how it failed, but how the organizations handl...
    • Anatomy of a Failed Theme Decision (and How to Avoid Making the Same Mistake!)
      This past Thursday, early afternoon, after much tweaking and adjusting and adding obscure personal touches to the style sheet, I switched HostScope over to a new theme. If you are looking around ...
    • Chapter Quotes for WordPress Posts Revisited
      A few months ago, I wrote a post about adding chapter quotes to your WordPress posts. Here I'll show you another way to add them to posts without them showing up outside of the single-post page, and ...

Leave a Reply

HostMonster for Great Unlimited Web Hosting Hundreds of template and themes from $35