WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/11/2016 09:25:40 PM (3 years ago)
Author:
rachelbaker
Message:

REST API: Allow schema sanitization_callback to be set to null to bypass fallback sanitization functions.

The logic in WP_REST_Request->sanitize_params() added in [39091] did not account for null or false being the sanitization_callback preventing overriding rest_parse_request_arg(). This fixes that oversight, allowing the built in sanitization function to be bypassed. See #38593.

Props kkoppenhaver, rachelbaker, jnylen0.
Fixes #39042.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-request.php

    r39111 r39563  
    819819            }
    820820            foreach ( $this->params[ $type ] as $key => $value ) {
    821                 // if no sanitize_callback was specified, default to rest_parse_request_arg
    822                 // if a type was specified in the args.
    823                 if ( ! isset( $attributes['args'][ $key ]['sanitize_callback'] ) && ! empty( $attributes['args'][ $key ]['type'] ) ) {
    824                     $attributes['args'][ $key ]['sanitize_callback'] = 'rest_parse_request_arg';
    825                 }
    826                 // Check if this param has a sanitize_callback added.
    827                 if ( ! isset( $attributes['args'][ $key ] ) || empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) {
     821                if ( ! isset( $attributes['args'][ $key ] ) ) {
    828822                    continue;
    829823                }
    830 
    831                 $sanitized_value = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key );
     824                $param_args = $attributes['args'][ $key ];
     825
     826                // If the arg has a type but no sanitize_callback attribute, default to rest_parse_request_arg.
     827                if ( ! array_key_exists( 'sanitize_callback', $param_args ) && ! empty( $param_args['type'] ) ) {
     828                    $param_args['sanitize_callback'] = 'rest_parse_request_arg';
     829                }
     830                // If there's still no sanitize_callback, nothing to do here.
     831                if ( empty( $param_args['sanitize_callback'] ) ) {
     832                    continue;
     833                }
     834
     835                $sanitized_value = call_user_func( $param_args['sanitize_callback'], $value, $this, $key );
    832836
    833837                if ( is_wp_error( $sanitized_value ) ) {
Note: See TracChangeset for help on using the changeset viewer.