{"id":1474,"date":"2024-03-15T16:42:37","date_gmt":"2024-03-15T07:42:37","guid":{"rendered":"https:\/\/www.santoshkori.com\/blog\/?p=1474"},"modified":"2024-03-15T16:52:00","modified_gmt":"2024-03-15T07:52:00","slug":"secure-rest-api-endpoints-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/secure-rest-api-endpoints-in-wordpress\/","title":{"rendered":"Secure REST API endpoints in WordPress"},"content":{"rendered":"<div class=\"wp-block-image wp-duotone-unset-1\">\n<figure class=\"alignright size-full is-resized\"><a href=\"https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2024\/03\/Wordpress-Secure-rest-api-endpoints.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2024\/03\/Wordpress-Secure-rest-api-endpoints.jpg\" alt=\"\" class=\"wp-image-1480\" style=\"width:179px;height:auto\" title=\"\" srcset=\"https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2024\/03\/Wordpress-Secure-rest-api-endpoints.jpg 1024w, https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2024\/03\/Wordpress-Secure-rest-api-endpoints-300x300.jpg 300w, https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2024\/03\/Wordpress-Secure-rest-api-endpoints-150x150.jpg 150w, https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2024\/03\/Wordpress-Secure-rest-api-endpoints-768x768.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Secure Rest API in WordPress<\/figcaption><\/figure>\n<\/div>\n\n\n<p><strong>Securing the WordPress REST API <\/strong>developer endpoint is crucial to prevent unauthorized access and potential security vulnerabilities. The developer endpoint in the WordPress REST API is typically used for debugging and development purposes, and it&#8217;s important to restrict access to it in a production environment. <\/p>\n\n\n\n<p>Here are some steps you can take to secure the WordPress REST API developer endpoint:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Disable the Debugging Mode<\/strong><\/h2>\n\n\n\n<p>Ensure that the WordPress site is not in debugging mode (<code>WP_DEBUG<\/code> is set to <code>true<\/code>). Debugging mode can expose sensitive information and should be turned off in a production environment.<\/p>\n\n\n\n<p>In your <code>wp-config.php<\/code> file, set the following:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\ndefine('WP_DEBUG', false);\ndefine('WP_DEBUG_DISPLAY', false);\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Limit Access with Authentication<\/h2>\n\n\n\n<p>By default, the developer endpoint does not require authentication. You can implement authentication to restrict access.<\/p>\n\n\n\n<p>Use Application Passwords: WordPress supports application passwords for authentication. You can generate an application password for a specific user and use it to authenticate requests to the REST API.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( 'wp_is_application_passwords_available', '__return_true' );\n<\/pre><\/div>\n\n\n<p><small>Use OAuth 1.0a: Implement OAuth 1.0a authentication for more secure access. You might need a plugin like the &#8220;Application Passwords&#8221; or &#8220;OAuth 1.0a Server&#8221; to enable these features.<\/small><\/p>\n\n\n\n<p><strong>JWT based Authentication<\/strong><\/p>\n\n\n\n<p>By default, WordPress REST API provides access control similar to the WordPress admin panel. Public content is accessible anonymously, while private content requires authentication. You can use plugins like JWT Authentication for WP REST API to implement JWT based authentication for the API.<\/p>\n\n\n\n<p>Some useful links, which will give more details.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/developer.wordpress.org\/rest-api\/using-the-rest-api\/authentication\/\">https:\/\/developer.wordpress.org\/rest-api\/using-the-rest-api\/authentication\/<\/a><\/li>\n\n\n\n<li><a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/developer.wordpress.org\/rest-api\/\">https:\/\/developer.wordpress.org\/rest-api\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Securing the WordPress REST API developer endpoint is crucial to prevent unauthorized access and potential security vulnerabilities. The developer endpoint in the WordPress REST API is typically used for debugging and development purposes, and it&#8217;s important to restrict access to it in a production environment. Here are some steps you can take to secure the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1474","post","type-post","status-publish","format-standard","hentry","category-just-blogging"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/1474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=1474"}],"version-history":[{"count":4,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/1474\/revisions"}],"predecessor-version":[{"id":1482,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/1474\/revisions\/1482"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=1474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=1474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=1474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}