Closing the WordPress leaks nobody checks
A production WordPress site was exposing its plugin list, admin usernames and maintenance tools through default URLs. A tested .htaccess patch locked them down in one deploy, without breaking a single legitimate page or Elementor feature.
- Stack
- WordPress · Apache 2.4 · Cloudflare
- Scope
- Security audit + hardening
AT A GLANCE
THE CHALLENGE
The site already blocked the usual suspects: .env, wp-config.php, .git, xmlrpc.php, /wp-json/ and ?author=N. On paper it looked locked down.
Most WordPress attacks don't start with a bug. They start with reconnaissance through default URLs: which plugins are installed, which usernames exist, which version is running. A full audit showed several of those doors were still open through less obvious routes.
REST API bypass via path-info
/wp-json/ was blocked, but /index.php/wp-json/ returned the full REST root, listing every installed plugin's routes. It also opened the users endpoint.
Maintenance tool reachable
/wp-admin/maint/repair.php returned 200 OK and exposed the WordPress version through its asset URLs.
Sample config being executed
wp-config-sample.php ran as PHP and returned a database error, confirming the file was reachable from the web.
oEmbed endpoint slipping through
/wp-json/oembed/1.0/embed escaped the REST block, and setup and install scripts had no explicit deny rule.
THE APPROACH
- Audit 96+ URLs in 9 categoriesSecrets and config files, version-control leaks, logs, backups and DB dumps, PHP info tools, build files, version fingerprinting, directory listings, and REST API / user enumeration.
- Test the bypasses, not just the obvious pathFor every blocked endpoint, also tested its alternates: path-info (
/index.php/wp-json), query form (?rest_route=), URL-encoded variants (%2F) and trailing-slash variants. - Write an incremental patchAdded only the missing rules above the
# BEGIN WordPressblock. Nothing already working was rewritten, keeping the change small and easy to roll back. - Protect what must keep workingVerified every rule against legitimate REST routes used by Elementor and the block editor. Used separate
RewriteCond/RewriteRulepairs instead of[OR]chains for predictable matching. - Re-test after deployShipped a one-line curl check so every target path can be re-verified in seconds after any server, plugin or Cloudflare change.
THE FIX
The core of the incremental patch, placed above the WordPress block in .htaccess.
# 1. Block /index.php/wp-json path-info bypass (critical)
RedirectMatch 403 ^/index.php/wp-json(/|$)
# 2. Block oEmbed discovery endpoint
RedirectMatch 403 ^/wp-json/oembed(/|$)
# 3. Block wp-admin maintenance and setup scripts
RedirectMatch 403 ^/wp-admin/maint(/|$)
RedirectMatch 403 ^/wp-admin/setup-config.php$
RedirectMatch 403 ^/wp-admin/install.php$
# 4. Block sample and leftover config files
RedirectMatch 403 ^/wp-config-sample.php$
RedirectMatch 403 ^/wp-config.(bak|old|orig|save|swp|txt)$
RedirectMatch 403 ^/wp-config.php.(bak|old|orig|save|swp)$
# 5. Belt-and-braces for path-info variants
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index.php/wp-json - [F,L]
</IfModule>
RESULTS
The gaps found in the audit, before and after the patch:
| Path | Risk | Before | After |
|---|---|---|---|
/index.php/wp-json/ | Full plugin and route map | 200 · exposed | 403 |
/index.php/wp-json/wp/v2/users | Admin username leak | Reachable | 403 |
/wp-admin/maint/repair.php | Version fingerprinting | 200 · exposed | 403 |
/wp-config-sample.php | Executed PHP, server info | 500 · executed | 403 |
/wp-json/oembed/1.0/embed | REST block bypass | 400 · reachable | 403 |
/wp-admin/setup-config.php | Setup script exposure | No rule | 403 |
/wp-admin/install.php | Install script exposure | No rule | 403 |
Follow-up check
Months later, the full hardened set still holds:
| Category | Paths checked | Result |
|---|---|---|
| REST API & user enumeration | /wp-json/, /wp-json/wp/v2/users, /index.php/wp-json/, ?rest_route=/wp/v2/users, oEmbed | All 403 |
| Secrets & config | .env, .git/config, wp-config.php.bak, wp-config-sample.php | All 403 |
| WP core & fingerprinting | xmlrpc.php, readme.html, license.txt, repair.php, setup and install scripts | All 403 |
| Logs & directory listing | wp-content/debug.log, wp-content/uploads/ | All 403 |
KEY TAKEAWAYS
- Blocking
/wp-json/is not enough. WordPress serves the same API through/index.php/wp-json/and?rest_route=, and each route needs its own rule. - "Already hardened" sites still have gaps. The obvious paths were covered here, but the bypasses weren't. Only a systematic audit finds them.
- Small, incremental patches are safer. Adding only the missing rules and testing legitimate routes avoids the classic hardening failure of breaking the page builder.
- Make re-testing cheap. A one-line curl check turns security into something you can verify after every update, not a one-time job.
Services: WordPress security audits · .htaccess and Cloudflare hardening · technical SEO
Need WordPress Security Hardening?
We audit and harden production WordPress websites against reconnaissance and configuration leaks without breaking editors or legitimate API routes.
Discuss your project