16

Just a quick question that might help a tad bit with security. I noticed that the readme.html file has the version number listed. It reappears after each upgrade and so do the licence.txt, and wp-config-sample.php.

Is there a easy way to have WordPress auto remove these files after an upgrade?

I already block the version number from showing in the meta tags, rss feeds, atom, etc.

I know this type of security isn't exactly that much helpful, but just thought it might be a tiny start. I heard that people can simply check the version of jQuery that is included in WP-includes and cross reference which version of WP shipped it.

4 Answers 4

22

You don't really need to remove these files. It's much easier to just block access to them. If you are using pretty URL's you already have an .htaccess file. Using .htaccess to block the files is secure and you only have to add a directive once.

Blocking files is done by adding a directive to .htaccess like this:

    <files filename.file-extension>
         order allow,deny
         deny from all
    </files>

So, to block readme.html you do this:

    <files readme.html>
         order allow,deny
         deny from all
    </files>

Do the same with the license file or any other file you want to prevent anyone from accessing. Just open .htaccess in Notepad or any other basic text editor, add the directives and save, making sure that the text editor keeps the file name exactly - without any .txt on the end.

2
  • 1
    This is actually the option I ended up going with. It works perfectly. May 16, 2011 at 4:49
  • 2
    Beware, that the above Syntax is only valid up to Apache 2.2! Afterwards use Require all denied (replacing those inner 2 lines) for Apache 2.4 and above. More Details here
    – Frank N
    Mar 7, 2017 at 7:00
7

Here is my take:

RewriteRule (?:readme|license|changelog|-config|-sample)\.(?:php|md|txt|html?) - [R=404,NC,L]
  • 404 (not existing) rather than 403 (forbidden) to avoid any clue about existence.
  • also in subfolders (i.e. themes and plugins, which might offer attack opportunities)
  • case-insensitive, extension-flexible, also catches README.html, or license.html (feel free to add typical suspects like changelogs|faq|contributing)

Personally, I would also block:

RewriteRule \.(?:psd|log|cmd|exe|bat|c?sh)$ - [NC,F]

nb:

  • '?:' just declares the bracket to be non-matching (no importance).
  • requires RewriteEngine to be on (it most likely is. it would be rare, to use wordpress without... (ugly permalinks, etc...)).
  • insert before the # BEGIN WordPress section in your .htaccess
1
  • Any advantage to using a RewriteRule vs FilesMatch? Sep 27, 2023 at 19:10
3
add_action('core_upgrade_preamble','my_function_to_delete_files');

Edit : you can also try these

add_action('upgrader_pre_install','my_function_to_delete_files');
add_action('upgrader_post_install','my_function_to_delete_files');
4
  • Thanks, I figured out the php unlink feature and it works, but one issue. The hook you provided seems to execute by simply visiting the Updates section under Dashboard. Is there another hook for after the upgrade has occured? Dec 15, 2010 at 20:16
  • 1
    ill take a look and let you know
    – Atif
    Dec 16, 2010 at 10:23
  • @Sahas @atif089 Did you manage to get this to work?
    – INT
    May 12, 2011 at 10:38
  • Instead of delete (in case you want to actually read the readme!) you can use this in your function chmod("/path/to/readme.txt", 0640);
    – Bysander
    Oct 10, 2016 at 12:07
1

2023 Solution

If you use Apache, currently on 2.4.5x version, as your web server and would like to go down the ".htaccess" path, then here are some options (in addition to Frank's answer), to do so:

Returning "Forbidden" to the user:

In this case, "user"/"hacker"/"adversary"/"pentester" would figure out those files exist on your server but s/he doesn't have access to them!

<FilesMatch "(?:readme|license|changelog|-config|-sample)\.(?:php|md|txt|html?)">
      Require all denied
</FilesMatch>

Returning "404" to the user:

In this case, "user"/"hacker"/"adversary"/"pentester", theoretically, would assume those files don't even exist on your server!

<FilesMatch "(?:readme|license|changelog|-config|-sample)\.(?:php|md|txt|html?)">
      Redirect 404
</FilesMatch>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.