• Resolved siegmar

    (@siegmar)


    Hi,
    I installed the “Application Passwords” plugin and your “Cerber” plugin.
    They work fine together for most API endpoints.
    But even when I BLOCK the API the following endpoints are still acessible to non-authenticated users:

    wp/v2/categories
    wp/v2/pages
    wp/v2/posts

    I know these endpoints are, by default, accessible for non-authenticated users, but my guess was that your plugin would block them too when I select:

    [X] Block access to WordPress REST API except any of the following
    [ ] Allow REST API for logged in users
    [ Administrator Vendor ] Allow REST API for these roles
    [ oembed ] Allow these namespaces

    I may solve this problem including the code below in wp-config.php, but would be easier to use your plugin:

    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;
    });

    Is this the normal behavior of your plugin or is it a bug ?
    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author gioni

    (@gioni)

    Hi! The first element in your REST API URLs has to be “wp-json” so the correct URL is /wp-json/wp/v2/posts and so on.

    Thread Starter siegmar

    (@siegmar)

    Hi,
    I am already using /wpson/… for the URLs.
    They are already accessible.
    The question was why they are still accessible after selecting “Block access to WordPress REST API…” ?
    Thanks

    Plugin Author gioni

    (@gioni)

    The correct (default) prefix for the REST API URLs is “wp-json”, not “wpson”.

    Thread Starter siegmar

    (@siegmar)

    Hi,
    I am already using “/wp-json/…”: I just typed it incorrectly in my post.
    The API is already working.
    I just would like to know why when I select “Block access to WordPress REST API…” it is not blocking the following URLs:

    wp/v2/categories
    wp/v2/pages
    wp/v2/posts

    Thanks

    Plugin Author gioni

    (@gioni)

    The only way you can get that is either your IP address is in the white list or you have enabled “Allow REST API for logged in users.”

    Thread Starter siegmar

    (@siegmar)

    Thanks

    • This reply was modified 3 years, 11 months ago by siegmar.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WordPress /categories REST API endpoint not blocking’ is closed to new replies.