Make WordPress Core


Ignore:
Timestamp:
07/21/2020 12:01:10 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Issue a _doing_it_wrong when registering a route without a permission callback.

The REST API treats routes without a permission_callback as public. Because this happens without any warning to the user, if the permission callback is unintentionally omitted or misspelled, the endpoint can end up being available to the public. Such a scenario has happened multiple times in the wild, and the results can be catostrophic when it occurs.

For REST API routes that are intended to be public, it is recommended to set the permission callback to the __return_true built in function.

Fixes #50075.
Props rmccue, sorenbronsted, whyisjake, SergeyBiryukov, TimothyBlynJacobs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php

    r47122 r48526  
    6161                ),
    6262                array(
    63                     'methods'  => WP_REST_Server::READABLE,
    64                     'callback' => array( $this, 'get_item' ),
    65                     'args'     => array(
     63                    'methods'             => WP_REST_Server::READABLE,
     64                    'callback'            => array( $this, 'get_item' ),
     65                    'permission_callback' => '__return_true',
     66                    'args'                => array(
    6667                        'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    6768                    ),
Note: See TracChangeset for help on using the changeset viewer.