3

Many php files in a WordPress installation are only used through require() or include(). Leaving them exposed to direct web access may increase security risks. Files such as wp-config.php has no need to be called directly from the web. For this reason it is ok to add a RewriteRule to the .htaccess file, redirecting requests for wp-config.php to a 404 page, for example: RewriteRule ^wp-config.php /error404.htm [L,R=301,NE]

My question, for those of you that have already checked and tested which files have no reason to be accessed directly form the web, is: is there a list of php files that is safe to "protect" with a RewriteRule? By your experience, are there downside doing so?

I did search StackExchange and the web, and found very little about it. This question asked 12 years ago, has not a good answer yet: Which of WordPress's .php files need to be directly accessible via HTTP?

2
  • In what way is accessing wp-config.php a security risk? It's entirely PHP, exposes nothing on the front-end, and accepts no query strings or posted data.
    – vancoder
    May 5, 2023 at 21:29
  • @vancoder you are right, should not be a direct security risk, until it is tho. Many bots scan IP addresses/domains to get a list of wordpress sites, in case a vulnerability comes up and they can attack them, so giving 404 to files that in other cases would be exposed, can help mitigare attacks, or at least attacks attempts.
    – capodieci
    May 7, 2023 at 22:35

1 Answer 1

4

Rather than asking which ones don't need direct access (a blocklist), I think it's better to ask which ones do need it (a safelist). That way everything is blocked by default, so new files aren't accessible until you manually unblock them.

I've seen a site use this safelist for a long time with no problems:

# wp-admin
/wp-admin/about.php
/wp-admin/admin-ajax.php
/wp-admin/admin-post.php
/wp-admin/admin.php
/wp-admin/async-upload.php
/wp-admin/comment.php
/wp-admin/credits.php
/wp-admin/customize.php
/wp-admin/edit-comments.php
/wp-admin/edit-tags.php
/wp-admin/edit.php
/wp-admin/export.php
/wp-admin/freedoms.php
/wp-admin/import.php
/wp-admin/index.php
/wp-admin/js/revisions-js.php
/wp-admin/link-add.php
/wp-admin/link-manager.php
/wp-admin/link.php
/wp-admin/load-scripts.php
/wp-admin/load-styles.php
/wp-admin/maint/repair.php
/wp-admin/media-new.php
/wp-admin/media-upload.php
/wp-admin/media.php
/wp-admin/moderation.php
/wp-admin/my-sites.php
/wp-admin/nav-menus.php
/wp-admin/network/about.php
/wp-admin/network/admin.php
/wp-admin/network/credits.php
/wp-admin/network/edit.php
/wp-admin/network/freedoms.php
/wp-admin/network/index.php
/wp-admin/network/plugins.php
/wp-admin/network/profile.php
/wp-admin/network/settings.php
/wp-admin/network/site-info.php
/wp-admin/network/site-new.php
/wp-admin/network/site-settings.php
/wp-admin/network/site-themes.php
/wp-admin/network/site-users.php
/wp-admin/network/sites.php
/wp-admin/network/themes.php
/wp-admin/network/update-core.php
/wp-admin/network/upgrade.php
/wp-admin/network/user-edit.php
/wp-admin/network/user-new.php
/wp-admin/network/users.php
/wp-admin/network.php
/wp-admin/options-discussion.php
/wp-admin/options-general.php
/wp-admin/options-media.php
/wp-admin/options-permalink.php
/wp-admin/options-privacy.php
/wp-admin/options-reading.php
/wp-admin/options-writing.php
/wp-admin/options.php
/wp-admin/plugins.php
/wp-admin/post-new.php
/wp-admin/post.php
/wp-admin/press-this.php
/wp-admin/profile.php
/wp-admin/revision.php
/wp-admin/site-editor.php
/wp-admin/term.php
/wp-admin/themes.php
/wp-admin/tools.php
/wp-admin/upgrade.php
/wp-admin/upload.php
/wp-admin/user/about.php
/wp-admin/user/admin.php
/wp-admin/user/index.php
/wp-admin/user/credits.php
/wp-admin/user/freedoms.php
/wp-admin/user/menu.php
/wp-admin/user/profile.php
/wp-admin/user/user-edit.php
/wp-admin/user-edit.php
/wp-admin/user-new.php
/wp-admin/users.php
/wp-admin/widgets.php
/wp-admin/site-health.php

# wp-includes
/wp-includes/ms-files.php
/wp-includes/js/tinymce/wp-tinymce.php

# root
/index.php
/wp-activate.php
/wp-app.php
/wp-comments-post.php
/wp-cron.php
/wp-login.php
/wp-mail.php
/wp-signup.php
/wp-trackback.php
/xmlrpc.php

You'll need to add any plugins/theme files that need direct access, but that should be pretty rare. Every once in awhile Core adds a new file like site-health.php that needs to be added, but that'll be obvious because users will report that a link in wp-admin isn't working.

FWIW, I don't think this has a ton of security benefit, and there are many things you should do long before it. It doesn't hurt, though.

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.