Home / Admin / _MK – SECURITÉ
Duplicate Snippet

Embed Snippet on Your Site

_MK – SECURITÉ

<10
Code Preview
php
<?php
<?php
// ============================================================
// SECURITY — User enumeration
// ============================================================
// Block ?author= enumeration + REST /users exposed to guests
add_action('init', function () {
    if (!is_admin() && isset($_GET['author'])) {
        wp_redirect(home_url(), 301);
        exit;
    }
});
add_filter('rest_endpoints', function ($endpoints) {
    if (!is_user_logged_in()) {
        unset($endpoints['/wp/v2/users']);
        unset($endpoints['/wp/v2/users/(?P<id>[\d]+)']);
    }
    return $endpoints;
});
// ============================================================
// SECURITY — XML-RPC & Pingbacks
// ============================================================
add_filter('xmlrpc_enabled', '__return_false');
add_action('init', function () {
    if (
        isset($_SERVER['REQUEST_URI']) &&
        basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)) === 'xmlrpc.php'
    ) {
        wp_die('Access denied.', 'Forbidden', ['response' => 403]);
    }
});
add_filter('wp_headers', function ($headers) {
    unset($headers['X-Pingback']);
    return $headers;
});
add_filter('xmlrpc_methods', function ($methods) {
    unset($methods['pingback.ping']);
    unset($methods['pingback.extensions.getPingbacks']);
    unset($methods['trackback.ping']);
    return $methods;
});
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('template_redirect', 'rest_output_link_header', 11, 0);
// ============================================================
// SECURITY — REST API
// ============================================================
// Restrict REST API to logged-in users only
// ⚠️ Désactiver si le site a un front public avec blocs dynamiques
add_filter('rest_authentication_errors', function ($result) {
    if (!is_user_logged_in()) {
        return new WP_Error(
            'rest_disabled',
            'REST API restricted.',
            ['status' => 403]
        );
    }
    return $result;
});
// ============================================================
// SECURITY — Login hardening
// ============================================================
// Ne pas indiquer si c'est le login ou le mot de passe qui est faux
add_filter('login_errors', function () {
    return 'Identifiants incorrects.';
});
// ============================================================
// SECURITY — Info leakage
// ============================================================
add_filter('the_generator', '__return_empty_string');
remove_action('wp_head', 'wp_generator');

Comments

Add a Comment