# Wp Hardening Best Practices > Úsalo al configurar o endurecer un sitio WordPress: wp-config.php, reglas .htaccess/nginx, permisos de archivos y revisión de seguridad del despliegue. Fuente: https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/wp-hardening-best-practices Markdown: https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/wp-hardening-best-practices.md Repositorio: https://github.com/wpultimatesecurity/WordPress-Security-Skills Autor: wpultimatesecurity Licencia: MIT Actualizado: hace 2 meses Coste de contexto: 106 tok instalada, 2.5k tok al activarse, 4.4k tok con todos los archivos del bundle Bundle: 5 archivos, 17 KB Permisos que pide: ninguno declarado ## Instalación Un skill son archivos markdown: los mismos archivos valen para cualquier agente y lo único que cambia es el directorio de destino, es decir la bandera `--agent`. Añade `-g` para instalarlo en todos los proyectos de la máquina. ```bash # Claude Code npx -y skills add wpultimatesecurity/WordPress-Security-Skills --skill wp-hardening-best-practices --agent claude-code # Cursor npx -y skills add wpultimatesecurity/WordPress-Security-Skills --skill wp-hardening-best-practices --agent cursor # Codex npx -y skills add wpultimatesecurity/WordPress-Security-Skills --skill wp-hardening-best-practices --agent codex # Gemini CLI npx -y skills add wpultimatesecurity/WordPress-Security-Skills --skill wp-hardening-best-practices --agent gemini # Windsurf npx -y skills add wpultimatesecurity/WordPress-Security-Skills --skill wp-hardening-best-practices --agent windsurf # Cline npx -y skills add wpultimatesecurity/WordPress-Security-Skills --skill wp-hardening-best-practices --agent cline ``` ## Qué hace - Configura wp-config.php con claves únicas, DISALLOW_FILE_EDIT, FORCE_SSL_ADMIN y depuración desactivada - Escribe reglas .htaccess o nginx para bloquear la ejecución de PHP en uploads y proteger archivos sensibles - Define permisos de archivos y carpetas con mínimo privilegio (755/644/640) - Deshabilita XML-RPC, enumeración de usuarios por REST y Application Passwords si no se usan - Aplica checklists de hardening previo al lanzamiento en producción ## Cuándo usarla - Al editar wp-config.php (claves, constantes, debug) - Al escribir o revisar reglas .htaccess (Apache) o bloques de servidor (nginx) - Al definir permisos y propietarios del sistema de archivos - Al preparar un checklist de hardening previo al lanzamiento o revisar el despliegue ## Qué la activa - "Ayúdame a endurecer el wp-config.php de este sitio WordPress antes de pasarlo a producción" - "Revisa estas reglas de .htaccess para proteger wp-config.php y la carpeta uploads" - "¿Qué permisos de archivos debería usar en mi instalación de WordPress?" - "Necesito un checklist de seguridad antes del lanzamiento de este WordPress" ## Antes de instalar - Los ejemplos de shell requieren las herramientas nombradas; usa WordPress y PHP mantenidos y soportados en producción. - Necesita en el PATH: curl - makes network requests ## Archivos - SKILL.md — 10 KB - references/checklist.md — 1 KB - references/go-live-checklist.md — 2 KB - references/htaccess-hardening.conf — 2 KB - references/wp-config-hardening.php — 2 KB ## SKILL.md Reproducido tal cual desde wpultimatesecurity/WordPress-Security-Skills bajo MIT. Esta sección es el documento original y está en inglés. # WordPress hardening best practices ## When to use this skill Use this skill for **site/environment configuration**, as opposed to plugin code: - Editing `wp-config.php` (keys, constants, debug). - Writing/reviewing `.htaccess` (Apache) or server-block (nginx) rules. - Setting filesystem permissions and ownership. - Locking down `wp-admin`, XML-RPC, REST user enumeration, and the uploads dir. - Pre-launch hardening checklists and deployment review. This complements the secure-coding skills: even perfect code runs on a host that must be configured to fail safely. ## Core principles (and why they matter) 1. **Disable in-dashboard file editing in production.** `DISALLOW_FILE_EDIT` removes the plugin/theme editor — a single compromised admin session otherwise becomes code execution. 2. **Force TLS for admin and logins.** `FORCE_SSL_ADMIN` stops credentials and cookies traveling in cleartext. 3. **Never display errors in production.** Stack traces leak paths, queries, and secrets. `WP_DEBUG` off, `display_errors` off; log to a non-web-readable file if needed. 4. **Block PHP execution where only data should live.** An attacker who slips a PHP file into `wp-content/uploads` gets RCE unless the server refuses to execute it there. 5. **Protect sensitive files.** `wp-config.php`, `.htaccess`, `readme.html`, `debug.log`, and dotfiles should not be web-readable. 6. **Least privilege on the filesystem.** Files `644`, directories `755`, `wp-config.php` `640`/`600`; web server should not own files it doesn't need to write. 7. **Unique, strong security keys/salts.** They invalidate stolen cookies; regenerate if leaked. 8. **Reduce attack surface.** Disable XML-RPC if unused, block user enumeration, keep core/ plugins/themes updated, remove unused plugins. ## Step-by-step implementation 1. In `wp-config.php`: set unique salts, `DISALLOW_FILE_EDIT`, `FORCE_SSL_ADMIN`, disable debug display; optionally `WP_AUTO_UPDATE_CORE`, `DISALLOW_FILE_MODS` for locked builds. 2. Place `wp-config.php` permissions at `640`/`600`; ensure it is above or protected from the web root. 3. Add server rules to deny PHP in `uploads`, protect sensitive files, and (optionally) restrict `wp-admin`/`xmlrpc.php`. 4. Set file/dir permissions to least privilege. 5. Keep everything updated; remove what you don't use. 6. Add abuse controls for public surfaces: comment moderation on, pingbacks off if unused, and — for bot-heavy sites — CAPTCHA/Turnstile on login and registration via an established plugin (hand-rolled CAPTCHAs fail in both directions). Pair with the login throttle from `authentication-session-security`; XML-RPC stays off unless needed. ### Supporting references | Reference | Load when | | --- | --- | | [WordPress hardening checklist](references/checklist.md) | Before final verification of the wordpress hardening controls. | | [Pre-launch (go-live) checklist](references/go-live-checklist.md) | Reviewing a production launch across configuration, code, data, and operations. | | [Apache and nginx hardening rules](references/htaccess-hardening.conf) | Implementing server hardening for sensitive files, uploads, and restricted endpoints. | | [Hardened wp-config.php constants](references/wp-config-hardening.php) | Implementing the wp-config.php hardening flow for salts, HTTPS, debugging, editing, and updates. | ## Common AI mistakes / anti-patterns ### Mistake 1 — Leaving debug output on in production ```php // ❌ Insecure: errors rendered to visitors leak paths, SQL, secrets. define( 'WP_DEBUG', true ); define( 'WP_DEBUG_DISPLAY', true ); ``` ```php // ✅ Secure: log privately, never display, in production. define( 'WP_DEBUG', false ); // If you must debug on a live box, at least never display: @ini_set( 'display_errors', '0' ); define( 'WP_DEBUG_DISPLAY', false ); define( 'WP_DEBUG_LOG', true ); // writes to wp-content/debug.log — block it from the web ``` ### Mistake 2 — Allowing the dashboard file editor ```php // ❌ Risky: compromised admin = arbitrary PHP via Appearance/Plugins editor. // (default: editor enabled) ``` ```php // ✅ Secure: disable file editing (and optionally all file mods). define( 'DISALLOW_FILE_EDIT', true ); // Fully locked deploy (no plugin/theme install/update via UI): define( 'DISALLOW_FILE_MODS', true ); ``` ### Mistake 3 — `777` permissions "to make it work" ```bash # ❌ Insecure: world-writable lets any local process modify your site. chmod -R 777 wp-content ``` ```bash # ✅ Secure: least privilege. find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; chmod 640 wp-config.php ``` ### Mistake 4 — Uploads directory that executes PHP ```apache # ❌ Insecure: a smuggled shell.php in uploads runs. # (no restriction) ``` ```apache # ✅ Secure: deny PHP execution in uploads (Apache). Place in wp-content/uploads/.htaccess Require all denied ``` ### Mistake 5 — Default/duplicated security keys ```php // ❌ Insecure: placeholder salts (or copied between sites). define( 'AUTH_KEY', 'put your unique phrase here' ); ``` ```php // ✅ Secure: generate unique values from the official salt API and rotate if leaked. // https://api.wordpress.org/secret-key/1.1/salt/ define( 'AUTH_KEY', '...64 random chars...' ); // (all eight: AUTH_KEY/SALT, SECURE_AUTH_KEY/SALT, LOGGED_IN_KEY/SALT, NONCE_KEY/SALT) ``` ### Mistake 6 — Leaving XML-RPC enabled when unused ```php // ❌ Risky: XML-RPC is a brute-force and pingback amplification vector if not needed. // (default: enabled) ``` ```php // ✅ Secure: disable XML-RPC entirely if the site does not need it. add_filter( 'xmlrpc_enabled', '__return_false' ); // Or block at the server level (see htaccess-hardening.conf). ``` ### Mistake 7 — Allowing REST user enumeration ```bash # ❌ Risky: /wp-json/wp/v2/users/ reveals usernames to unauthenticated visitors. curl https://example.com/wp-json/wp/v2/users/ ``` ```php // ✅ Safer: require authentication for the users endpoint. add_filter( 'rest_endpoints', function ( $endpoints ) { if ( isset( $endpoints['/wp/v2/users'] ) ) { $endpoints['/wp/v2/users'][0]['permission_callback'] = static function () { return is_user_logged_in(); }; } return $endpoints; } ); ``` ### Mistake 8 — Application Passwords enabled without review Application Passwords (WordPress 5.6+) are powerful for integrations but create a long-lived credential surface. Disable them if unused, or restrict them to users who actually need machine access. ```php // ✅ Secure: disable Application Passwords if the site does not use them. add_filter( 'wp_is_application_passwords_available', '__return_false' ); ``` Related: see the `secrets-credentials-management` skill for storing and handling API keys and tokens safely. See the `security-headers-csp` skill for application-level security headers (HSTS belongs in this skill's server config; the rest is code-level), and the `dependency-supply-chain-security` skill for keeping bundled libraries and CDN assets from rotting. ## Correct code examples Hardened `wp-config.php` constants are in [`references/wp-config-hardening.php`](references/wp-config-hardening.php); Apache and nginx rules (deny PHP in uploads, protect `wp-config.php`/`.htaccess`/`debug.log`, limit `xmlrpc.php`) are in [`references/htaccess-hardening.conf`](references/htaccess-hardening.conf); the consolidated pre-launch sweep is [`references/go-live-checklist.md`](references/go-live-checklist.md). ## Checklist - [ ] Unique, strong security keys/salts set (all eight). - [ ] `DISALLOW_FILE_EDIT` enabled in production. - [ ] `FORCE_SSL_ADMIN` enabled; site served over HTTPS. - [ ] `WP_DEBUG`/`WP_DEBUG_DISPLAY` off in production; logs not web-readable. - [ ] PHP execution denied in `wp-content/uploads`. - [ ] `wp-config.php`, `.htaccess`, `debug.log`, dotfiles not web-accessible. - [ ] Permissions least-privilege: dirs `755`, files `644`, `wp-config.php` `640`/`600`. - [ ] XML-RPC disabled/limited if unused; user enumeration limited. - [ ] Core, plugins, themes kept updated; unused extensions removed. - [ ] Admin accounts use strong passwords + 2FA where possible. ## Official references - [Hardening WordPress — Documentation](https://developer.wordpress.org/advanced-administration/security/hardening/) - [Editing wp-config.php](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/) - [Security keys & salts API](https://api.wordpress.org/secret-key/1.1/salt/) - [Changing File Permissions](https://developer.wordpress.org/advanced-administration/server/file-permissions/) - [`DISALLOW_FILE_EDIT` / `DISALLOW_FILE_MODS`](https://developer.wordpress.org/apis/wp-config-php/#disable-the-plugin-and-theme-file-editor) - [`FORCE_SSL_ADMIN`](https://developer.wordpress.org/advanced-administration/security/https/) - [Debugging in WordPress (`WP_DEBUG`)](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/) - [OWASP — Secure Configuration](https://owasp.org/www-project-top-ten/) ## Dónde encaja - Categoría: [Seguridad](https://skillsagentes.com/categorias/seguridad.md) — Auditorías, revisión de dependencias, manejo de secretos y modelado de amenazas. - Creador: [wpultimatesecurity](https://skillsagentes.com/creators/wpultimatesecurity.md) — 27 skills en el directorio - [Todas las skills](https://skillsagentes.com/skills.md) - [Ranking de instalaciones](https://skillsagentes.com/ranking.md) ## Otras skills del mismo repositorio - [Security Auditing Code Review](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/security-auditing-code-review.md): Úsalo al auditar o revisar código de un plugin o tema WordPress existente, triar un informe de vulnerabilidad o endurecer código heredado, con una metodología sistemática. - [Authentication Session Security](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/authentication-session-security.md): Úsalo cuando el código inicia o cierra sesión, gestiona cookies o tokens de sesión, limita intentos de login o construye un formulario de login propio en WordPress. - [Dependency Supply Chain Security](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/dependency-supply-chain-security.md): Úsalo cuando un plugin o tema empaquete una librería de terceros, cargue un asset desde un CDN, ejecute código remoto, use Composer o prepare el zip distribuible. - [Secure Plugin Development](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/secure-plugin-development.md): Úsalo al iniciar un plugin o tema de WordPress, al añadir hooks o funciones que manejan peticiones, opciones o salida; establece la línea base segura por defecto. - [Gutenberg Block Editor Security](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/gutenberg-block-editor-security.md): Úsalo al construir bloques dinámicos o funciones del editor de bloques: render_callback, ServerSideRender, datos REST o register_rest_field, para evitar XSS almacenado y control de acceso roto. ## Skills relacionadas - [Ai Llm Integration Security](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/ai-llm-integration-security.md): Úsalo al construir o revisar funciones de plugin o tema de WordPress que llaman a un LLM: chatbots, generación de contenido, RAG, agentes con herramientas, Abilities API o exposición MCP. - [Ajax Security](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/ajax-security.md): Úsalo al registrar o manejar AJAX en WordPress vía admin-ajax.php: verifica el nonce, comprueba permisos, sanitiza cada campo y responde con wp_send_json_*, evitando CSRF e inyecciones. - [Authentication Session Security](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/authentication-session-security.md): Úsalo cuando el código inicia o cierra sesión, gestiona cookies o tokens de sesión, limita intentos de login o construye un formulario de login propio en WordPress. - [Capability Permission Checks](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/capability-permission-checks.md): Protege operaciones privilegiadas en WordPress con current_user_can() usando la capability correcta (no el rol), checks por objeto y nonce, evitando escalada de privilegios y control de acceso roto. - [Cron Background Job Security](https://skillsagentes.com/skills/wpultimatesecurity/wordpress-security-skills/cron-background-job-security.md): Úsalo al programar eventos cron con wp_schedule_event / wp_schedule_single_event o al escribir el callback. Revalida la autorización contra el contexto guardado, no con current_user_can, y mantiene los secretos fuera de las URLs de cron. --- Skills Agentes · [Índice de páginas en markdown](https://skillsagentes.com/sitemap.md) · [Inicio](https://skillsagentes.com/index.md)