Make WordPress Core

Changeset 44070


Ignore:
Timestamp:
12/13/2018 01:56:35 AM (8 years ago)
Author:
pento
Message:

Editor: Remove unwanted fields before saving posts.

The meta_input, file, and guid fields are not intended to be updated through user input.

Merges [44047] to the 4.0 branch.

Location:
branches/4.0
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

  • branches/4.0/src/wp-admin/includes/ajax-actions.php

    r37802 r44070  
    18361836        }
    18371837
    1838         $post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
     1838        $post_data = ! empty( $_REQUEST['post_data'] ) ? _wp_get_allowed_postdata( _wp_translate_postdata( false, (array) $_REQUEST['post_data'] ) ) : array();
     1839
     1840        if ( is_wp_error( $post_data ) ) {
     1841                wp_die( $post_data->get_error_message() );
     1842        }
    18391843
    18401844        // If the context is custom header or background, make sure the uploaded file is an image.
  • branches/4.0/src/wp-admin/includes/post.php

    r37817 r44070  
    177177
    178178/**
     179 * Returns only allowed post data fields
     180 *
     181 * @since 4.9.9
     182 *
     183 * @param array $post_data Array of post data. Defaults to the contents of $_POST.
     184 * @return object|bool WP_Error on failure, true on success.
     185 */
     186function _wp_get_allowed_postdata( $post_data = null ) {
     187        if ( empty( $post_data ) ) {
     188                $post_data = $_POST;
     189        }
     190
     191        // Pass through errors
     192        if ( is_wp_error( $post_data ) ) {
     193                return $post_data;
     194        }
     195
     196        return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
     197}
     198
     199/**
    179200 * Update an existing post with values provided in $_POST.
    180201 *
     
    242263        if ( is_wp_error($post_data) )
    243264                wp_die( $post_data->get_error_message() );
     265        $translated = _wp_get_allowed_postdata( $post_data );
    244266
    245267        // Post Formats
     
    319341
    320342                /** This filter is documented in wp-admin/includes/media.php */
    321                 $post_data = apply_filters( 'attachment_fields_to_save', $post_data, $attachment_data );
     343                $translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data );
    322344        }
    323345
     
    326348        update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
    327349
    328         $success = wp_update_post( $post_data );
     350        $success = wp_update_post( $translated );
    329351        // If the save failed, see if we can sanity check the main fields and try again
    330352        if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
     
    332354
    333355                foreach( $fields as $field ) {
    334                         if ( isset( $post_data[ $field ] ) ) {
    335                                 $post_data[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $post_data[ $field ] );
     356                        if ( isset( $translated[ $field ] ) ) {
     357                                $translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] );
    336358                        }
    337359                }
    338360
    339                 wp_update_post( $post_data );
     361                wp_update_post( $translated );
    340362        }
    341363
     
    495517                }
    496518
     519                $post_data['post_ID']        = $post_ID;
    497520                $post_data['post_type'] = $post->post_type;
    498521                $post_data['post_mime_type'] = $post->post_mime_type;
    499                 $post_data['guid'] = $post->guid;
    500522
    501523                foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
     
    505527                }
    506528
    507                 $post_data['ID'] = $post_ID;
    508                 $post_data['post_ID'] = $post_ID;
    509 
    510529                $post_data = _wp_translate_postdata( true, $post_data );
    511530                if ( is_wp_error( $post_data ) ) {
     
    513532                        continue;
    514533                }
     534                $post_data = _wp_get_allowed_postdata( $post_data );
    515535
    516536                $updated[] = wp_update_post( $post_data );
     
    523543                }
    524544
    525                 if ( isset( $post_data['post_format'] ) )
    526                         set_post_format( $post_ID, $post_data['post_format'] );
     545                if ( isset( $shared_post_data['post_format'] ) )
     546                        set_post_format( $post_ID, $shared_post_data['post_format'] );
    527547        }
    528548
     
    700720        if ( is_wp_error($translated) )
    701721                return $translated;
     722        $translated = _wp_get_allowed_postdata( $translated );
    702723
    703724        // Create the post.
    704         $post_ID = wp_insert_post( $_POST );
     725        $post_ID = wp_insert_post( $translated );
    705726        if ( is_wp_error( $post_ID ) )
    706727                return $post_ID;
     
    15471568        if ( is_wp_error( $post_data ) )
    15481569                return $post_data;
     1570        $post_data = _wp_get_allowed_postdata( $post_data );
    15491571
    15501572        $post_author = get_current_user_id();
  • branches/4.0/src/wp-admin/post.php

    r44069 r44070  
    228228        // Update the thumbnail filename
    229229        $newmeta = wp_get_attachment_metadata( $post_id, true );
    230         $newmeta['thumb'] = $_POST['thumb'];
     230        $newmeta['thumb'] = wp_basename( $_POST['thumb'] );
    231231
    232232        wp_update_attachment_metadata( $post_id, $newmeta );
Note: See TracChangeset for help on using the changeset viewer.