From 87ef0fb5c73181866fdecc2b3ef25715a2a47cdb Mon Sep 17 00:00:00 2001 From: Sam SINGH-LIEGARD Date: Fri, 21 Jun 2024 08:24:26 +0000 Subject: [PATCH] Retours audit XMCO --- .htaccess | 7 +++++++ content/themes/ldc/functions.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/.htaccess b/.htaccess index ee580817..fc166406 100755 --- a/.htaccess +++ b/.htaccess @@ -932,3 +932,10 @@ RewriteRule . /index.php [L] # END WordPress + +# Block WordPress xmlrpc.php requests + +order deny,allow +deny from all + + diff --git a/content/themes/ldc/functions.php b/content/themes/ldc/functions.php index e2efeb07..d5adef9b 100644 --- a/content/themes/ldc/functions.php +++ b/content/themes/ldc/functions.php @@ -1037,3 +1037,34 @@ function writeLog($log) } } } + +/** + * Require Authentication for All Requests FOR REST API + */ + + add_filter( 'rest_authentication_errors', function( $result ) { + // If a previous authentication check was applied, + // pass that result along without modification. + if ( true === $result || is_wp_error( $result ) ) { + return $result; + } + + // No authentication has been performed yet. + // Return an error if user is not logged in. + if ( ! is_user_logged_in() ) { + return new WP_Error( + 'rest_not_logged_in', + __( 'You are not currently logged in.' ), + array( 'status' => 401 ) + ); + } + + // Our custom authentication check should have no effect + // on logged-in requests + return $result; +}); + +/** + * disable XML-RPC + */ +add_filter( 'xmlrpc_enabled', '__return_false' );