Hace poco recibimos una pregunta de un lector que oímos con bastante frecuencia por aquí: “¿Cómo desactivo la API REST en mi sitio WordPress?”. Y sinceramente, es una preocupación válida.
Cuando se lanzó la versión 4.4 de WordPress con la API REST JSON, se abrió un mundo de posibilidades para los desarrolladores. Sin embargo, muchos propietarios de sitios la consideran innecesaria y se preocupan acerca de las posibles vulnerabilidades que introduce.
En este artículo, le mostraremos cómo desactivar fácilmente la API REST JSON en WordPress.
¿Por qué desactivar la API REST JSON en WordPress?
No se puede negar que la API tiene muchas ventajas para los desarrolladores de WordPress. La API facilita enormemente la recuperación de datos mediante solicitudes GET, lo que resulta muy útil para quienes crean aplicaciones con WordPress.
Dicho esto, esto podría potencialmente abrir su sitio web a un nuevo frente de ataques DDoS. También puede consumir muchos recursos y ralentizar tu sitio web WordPress.
Desactivar la API REST de JSON es similar a desactivar XML-RPC, que muchos administradores de sitios desactivan en sus sitios de WordPress sólo para estar seguros.
Le mostraremos dos métodos para desactivar fácilmente la API REST JSON en WordPress. Simplemente utilice los enlaces rápidos a continuación para saltar al método que desea utilizar.
Método 1. Desactivar la API REST JSON en WordPress con código (Recomendado)
Recomendamos utilizar el plugin WPCode para desactivar la API REST JSON en WordPress.
WPCode hace que sea seguro y fácil añadir código personalizado en WordPress, sin editar el archivo functions.php de tu tema. De esta manera, no hay riesgo de cometer un error y romper su sitio.
Además, viene con una biblioteca de código integrada que incluye fragmentos de código verificados para solicitudes de características populares como desactivar REST API, desactivar XML-RPC y mucho más. Esto evita tener que instalar un montón de plugins de un solo uso.
Para empezar, necesitas instalar y activar el plugin gratuito WPCode. Para obtener instrucciones paso a paso, lee nuestra guía sobre cómo instalar un plugin de WordPress.
Nota: La versión gratuita de W PCode tiene todo lo que necesitas para añadir fácilmente código personalizado en WordPress. Pero, si quieres características avanzadas como una biblioteca privada de fragmentos en la nube, fragmentos específicos para páginas y dispositivos, revisiones de código y mucho más, puedes actualizar a WPCode Pro.
Una vez activado el plugin, vaya a Fragmentos de código ” Biblioteca desde su escritorio de WordPress.
A continuación, busque el fragmento de código “Desactivar API REST de WordPress” y haga clic en el botón “Usar fragmento de código”.
A continuación, el plugin añadirá automáticamente el código y seleccionará el método de inserción adecuado.
Todo lo que tienes que hacer es conmutar el interruptor de “Inactivo” a “Activo”.
A continuación, haga clic en el botón “Actualizar”.
Ya está. Ahora la API REST JSON está desactivada en su sitio WordPress.
Método 2. Desactivar la API REST JSON en WordPress con un plugin
También puede desactivar fácilmente la API REST JSON con la ayuda de un plugin dedicado.
Lo primero que tienes que hacer es instalar y activar el plugin Disable REST API. Para más detalles, consulta nuestra guía paso a paso sobre cómo instalar un plugin de WordPress.
El plugin funciona de inmediato y no hay ajustes que configurar.
Una vez activado, el plugin devolverá por la fuerza un error de identificación a cualquier solicitud de API procedente de fuentes que no estén conectadas a su sitio web.
Esto evitará de forma efectiva que solicitudes no autorizadas utilicen la API REST para obtener información de su sitio web.
Puede probarlo visitando la página http://example.com/wp-json. Asegúrese de salir primero del área de administrador de WordPress o cambie su navegador al modo incógnito.
No olvide sustituir ejemplo.com por su propio nombre de dominio. Verá este mensaje, que indica que las solicitudes de la API REST están bloqueadas.
Eso es todo, ha desactivado correctamente las solicitudes no autorizadas de la API REST en su sitio WordPress.
Esperamos que este artículo te haya ayudado a aprender cómo Desactivar la API JSON en WordPress. Los usuarios preocupados por la seguridad también pueden marcar / comprobar estos consejos sobre cómo proteger el área de administración de WordPress o ver nuestra selección de los mejores plugins de copia de seguridad de WordPress.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
RJW
I’d try the disable plugin in Dev environment before production, I found installing it broke some features
WPBeginner Support
If you have many different plugins and tools and have a testing environment then it would definitely be good to test new plugins and how they interact with your site.
Administrador
Ricky
Similar to an above commenter, I’ve noticed the “wp-json” request when using Pingdom and other testing sites. Unfortunately, mine takes over 10 seconds (Yes really!!) to load it. This pushes my overall website load time and I can’t figure out how to fix this. The plugin doesn’t change it at all. Any suggestions?
Janice
How do I know if I actually have JSON API on my website?
This article about removing it is good – if I need it – but I have often been alarmed by certain warnings only to find that they’ve not even applicable to me.
WPBeginner Support
Hey Janice,
If you are using a self-hosted WordPress.org site, then you do have JSON REST API available on your website.
Administrador
Logan Cale
I hate adding yet another plugin to do a simple tasks, and I found that we can disable this functionality by adding the following code snippet to the functions.php file.
add_filter(‘rest_enabled’, ‘_return_false’);
add_filter(‘rest_jsonp_enabled’, ‘_return_false’);
Margarit Koka
Thank you bro, your answer is what I was looking when visiting this page.
Bobby C.
Thank you! Straight to the point.
Hari
I was looking for this code, it worked, thanks, I don’t prefer adding plugins.
Michael
Thanks for your help. There is no ‘add new’ option in my plugins.
WPBeginner Support
You are probably using WordPress.com. Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Administrador
Lynne
Thank you! Spot on worked for me
J.L.
Is this just for self hosted blogs or including free blog sites? Per mostly all plug ins…etc are done for you when you’re not self hosted
PS I’m not subscribing…just want a response
WPBeginner Support
This is for self hosted WordPress.org sites only.
Administrador
Elaine
How can I check if my site has Rest API. I turned off a lot of extras when I first set it up but now don’t know where to look to see if it’s there. Not keen to download a plugin unnecessarily.
WPBeginner Support
Hey Elaine,
You can check if rest is api is enabled on your site by visiting the url like this example.com/wp-json. Make sure you are signed out of WordPress before doing that. If you see lots of information in plain text, then this means REST API is enabled on your site. Follow the above instructions to turn it off
Administrador
Saransh Jain
What about the option to disable json rest api in Jetpack plugin?
Ken Dowling
Is disabling REST API suitable for e-commerce sites such as WooCommerce? My understanding is that WooCommerce uses REST-API quite a bit.
Further, my buyers do not have to login to buy, so what happens to the transaction when a REST API call is rejected?
Regards, Ken
D. Joe Chaffin
Plug-in makes no difference for me in WP 4.7.2. With the plugin activated or disabled, the example.com/wp-json (with my domain replacing “example”) pages gives a massive list of settings for my site.
D. Joe Chaffin
Hmmmm. Now that I look at it, I only see the list in Safari, while Chrome and Firefox for Mac show the expected message specified in this post.
WPBeginner Support
Hi,
Make sure you are logged out of WordPress admin area or use incognito mode before testing the example.com/wp-json page. The plugin disables access to the page only for unauthorized users. As an administrator you will still be able to see it.
Administrador
D. Joe Chaffin
Embarrassed… You are right, of course.
Audra Carpenter
Hey Guys,
First off thanks so much for what you do! I’ve learned so much about Wordpress from you and sent a ton of folks your way!!
Ok, I installed the plugin, but I am not seeing what you suggest above? I have a full screen of information…?
Thoughts?
Thanks!
WPBeginner Support
Hi Audra,
Please logout or use incognito window to test. The plugin only disables access for non-logged in users.
Administrador
Treasure
I followed these steps, but when I went to check it with the example etc., I got 2 pages of code, not the response showed above. Hmmm, don’t know what to do.
Treasure
Alright, I did it again and got the right message. Thanks!
Doug Nix
When I ran the test I think it failed, as I got a boatload of data on screen. Any idea what might have not worked? I installed the plugin as described…
Doug Nix
Works perfectly when I check using an incognito window. Thanks for the explanation regarding authorised vs unauthorised or anonymous users.
Laura Zielke
Worked perfectly. Thank you!
Karl
Thanks for the tip as well as for the hook to disable XMLRPC.
Is there a chance for a filter hook for the REST API as well?
Andrew
When I check the speed of my site using pingdom.com, the first html entry that tried to load shows the link as mydomain.com/wp-json and it has over 2 seconds of “wait” time. Is this the same as what this article is talking about? I’m hesitant to simply disable it since I would assume it will be used in the future. Any idea why it would add a 2+ second delay to loading anything on the page?
Stephen Cronin
Hmm, the REST API is going to become the standard way for plugins and themes to make Ajax calls back to the server from the front end, replacing admin-ajax, so I wouldn’t be disabling it… Hopefully they will fail gracefully, but you will almost end up missing some functionality.
Also, if you really want to protect against DDoS attacks, you better disable html as well!
reza
ver 50,000 WordPress websites have been hacked due to a major security vulnerability that was discovered in the WordPress REST API.
Jim S Smith
OUCH!
That’s disturbing to know. I have noticed a LOT of access attempts in my site’s logs.
What’s more,
I think the folks at WordPress could have done a little better in letting the users decide how much, if at all, they want the REST API exposed.
Again,
More of this, “The developers know MORE about the user’s needs than the user does!” – I also was not too happy about being forced to support EMOJI and remote-loaded fonts from fonts.google.com, even though my sites do not use them!
The REST API may be a boon for (some) actual web-application developers, but what about the rest of us who will not very likely use this? ? ?
Kasey
How likely is it that a plugin will be using this functionality. Just for example would contact forms be utilizing this? Not keen on turning it off in case it breaks anything.
WPBeginner Support
The plugins will most likely notify you if they will be using it and you have it turned off.
Administrador