WordPress runs a huge share of the web, and that makes it a constant target for automated attacks. In most compromises, WordPress core is not even the problem. The attacker gets in through vulnerable plugins and themes, weak passwords, or missing updates. Since many sites are maintained without any security routine, they keep piling up abandoned plugins and old versions until they become an easy way in.
The goal here is practical: shrink the attack surface of a target that gets probed all the time. WordPress security starts with managing plugins and themes and keeping up with updates, because that is where most of the risk lives. Next come access hardening, protection of the admin dashboard, file and configuration hardening, and backups. Finally, we cover monitoring and how to respond to a compromise, in case something has already gotten through.
Plugins, themes, and updates
Plugins and themes are the biggest source of risk. Install only what you need, from trusted sources, and remove what you do not use. Note that deactivating is not enough: a deactivated plugin is still on the server and may still be exploitable. Keep everything updated, core included, and be wary of abandoned plugins, because they stop receiving security fixes. Every plugin you remove is one less piece of attack surface.
Track the known vulnerabilities in the plugins you use. When a critical flaw comes out in a popular plugin, automated attacks start quickly, and how fast you update makes a difference. Turning on automatic updates for minor core releases helps, because it shortens the window in which a security fix sits pending, waiting for someone to click update.
Access and dashboard protection
The admin dashboard (wp-admin) and the login page are targets for brute force and credential stuffing. Use strong, unique passwords, enable MFA, limit login attempts, and, when feasible, restrict dashboard access by source address. Avoid the default admin username. And give each person the minimum role they need, instead of making everyone an administrator.
One vector many people forget is user enumeration. WordPress can reveal account names through the REST API and the author parameters in the URL, which hands half the work to whoever is running the brute force: all that is left is guessing the password. Blocking or restricting these enumeration routes makes valid usernames harder to discover and makes password attacks less effective.
- Only the plugins and themes you need, from trusted sources
- Unused plugins and themes removed, including deactivated ones
- Core, plugins, and themes updated regularly
- MFA and strong passwords for access
- Limited login attempts and a protected wp-admin
- User enumeration restricted in the REST API and the author parameter
- Each user with the minimum role they need
File and configuration hardening
Much of the hardening happens in configuration and files. The wp-config.php file holds the database credentials and the security keys, so block direct access to it and set file permissions so that only the owner can read it. Also disable the theme and plugin editor in the dashboard. Without it, someone who hijacks an admin session cannot inject code directly through the browser. The authentication keys and salts must be strong values and, after a compromise, should be changed to invalidate the sessions.
// prevents editing themes and plugins from the dashboarddefine('DISALLOW_FILE_EDIT', true);// forces HTTPS in the admin dashboarddefine('FORCE_SSL_ADMIN', true);// applies minor core updates automaticallydefine('WP_AUTO_UPDATE_CORE', 'minor');On the web server, two adjustments pay off well. The first is to prevent PHP execution in the uploads directory, which cuts off one of the most common persistence paths: the attacker manages to upload a file and then tries to run it. The second is to block direct access to sensitive files and to xmlrpc.php when it is not in use. XML-RPC gets abused both to amplify brute-force attacks and for denial-of-service attacks via pingback, so closing it reduces the attack surface. The nginx rules below cover these points.
# denies PHP execution in the uploads directorylocation ~* /wp-content/uploads/.*\.php$ { deny all; }# protects wp-config.php from direct accesslocation = /wp-config.php { deny all; }# blocks xmlrpc.php when it is not usedlocation = /xmlrpc.php { deny all; }Edge protection, backups, and monitoring
A WAF in front of the site mitigates common web attacks and login abuse, so less noise reaches the application. Keep regular, tested backups stored off the server itself, so you can recover after a compromise or after a plugin corrupts the site. Monitor file changes and suspicious logins: the earlier a compromise is detected, the less damage it does. Finally, connect to the database with a least-privilege user. In day-to-day operation, the application rarely needs database administration privileges.
Responding to a compromise
Even with hardening, something can slip through, and you need to know what to do when it happens. The typical signs of a compromised WordPress site are unexpected PHP files in the uploads directory, administrator accounts nobody recognizes, redirects to third-party sites, injected spam content, and blocking warnings from the browser or the hosting provider. The sooner someone notices these signs, the smaller the damage.
Removing only the visible malicious file does not solve the problem, because backdoors tend to replicate. The safest path is to isolate the site, change every password as well as the keys and salts in wp-config (to invalidate the sessions), and restore from a backup known to be clean, taken before the compromise. Only then update core, plugins, and themes and put the site back online. Review the user list, look for suspicious scheduled tasks, and investigate the root cause, which is usually a vulnerable plugin. Without that, the incident happens again.
Practical checklist
- Install only the plugins and themes you need, from trusted sources
- Remove the plugins and themes that are not in use
- Update core, plugins, and themes regularly, with automatic updates for minor releases
- Track the known vulnerabilities in the plugins you use
- Enable MFA and require strong passwords
- Limit login attempts and protect wp-admin
- Restrict user enumeration through the REST API and the author parameter
- Drop the default admin user and give each person the smallest role possible
- Protect wp-config.php and disable the dashboard file editor
- Deny PHP execution in the uploads directory and block xmlrpc.php if it is not used
- Put a WAF in front of the site
- Connect to the database with a least-privilege user
- Keep regular, tested backups stored off the server
- Monitor file changes and suspicious logins
- Have a response plan for a compromise defined in advance
Best practices
- Keep plugins to a minimum, because each one adds attack surface
- Update quickly when a critical flaw comes out in a popular plugin
- Make wp-admin protection a priority
- Harden files and configuration, not only access
- Use a WAF to contain web attacks and login abuse
- Keep tested backups off the server
- Monitor so you detect a compromise early, and have a response plan ready
Common mistakes
- Abandoned or unnecessary plugins installed
- Vulnerabilities that will never be fixed become a way in.
- Outdated core and plugins
- Automated attacks exploit flaws that are already known.
- wp-admin without MFA or a limit on login attempts
- Accounts fall to brute force or credential stuffing.
- PHP execution allowed in the uploads directory
- Any file the attacker manages to upload can run as a backdoor.
- No backups, or backups on the server itself
- When the server is compromised, recovery fails along with it.
- Every user set as an administrator
- A single compromised account is enough to give the attacker full control of the site.
Authorship and review
Cesar Gargiulo
CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.
Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.