Make WordPress Core


Ignore:
Timestamp:
07/01/2026 09:32:34 PM (3 months ago)
Author:
adamsilverstein
Message:

REST API: Add dimension validation to sideload endpoint.

Validate uploaded image dimensions in the wp/v2/media/<id>/sideload endpoint before metadata is written, ensuring sideloaded files match the requested image_size. A new private validate_image_dimensions() helper on WP_REST_Attachments_Controller enforces:

  • The original size must match the original attachment dimensions exactly.
  • The full and scaled sizes require positive dimensions only.
  • Regular registered sizes must not exceed the registered sub-size maximums, with a 1px tolerance for rounding differences.

Follow-up to [62428].

Props apermo, westonruter.
Fixes #64798.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r62615 r62619  
    1717 * @since 4.7.0
    1818 *
     19 * @see add_image_size()
     20 *
    1921 * @global array $_wp_additional_image_sizes
    2022 *
    2123 * @return array Additional images size data.
     24 *
     25 * @phpstan-return array<string, array{
     26 *                     width: non-negative-int,
     27 *                     height: non-negative-int,
     28 *                     crop: array{ 'left'|'center'|'right', 'top'|'center'|'bottom' }|bool,
     29 *                 }>
    2230 */
    2331function wp_get_additional_image_sizes() {
    … …  
    297305 *     @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
    298306 * }
     307 *
     308 * @phpstan-param non-negative-int $width
     309 * @phpstan-param non-negative-int $height
     310 * @phpstan-param array{ 'left'|'center'|'right', 'top'|'center'|'bottom' }|bool $crop
    299311 */
    300312function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
    … …  
    909921 * @return array[] Associative array of arrays of image sub-size information,
    910922 *                 keyed by image size name.
    911  */
    912 function wp_get_registered_image_subsizes() {
     923 *
     924 * @phpstan-return array<string, array{
     925 *                     width: non-negative-int,
     926 *                     height: non-negative-int,
     927 *                     crop: array{ 'left'|'center'|'right', 'top'|'center'|'bottom' }|bool,
     928 *                 }>
     929 */
     930function wp_get_registered_image_subsizes(): array {
    913931        $additional_sizes = wp_get_additional_image_sizes();
    914932        $all_sizes        = array();
Note: See TracChangeset for help on using the changeset viewer.