Skip to content

Commit

Permalink
Added a safeguard for invalid uploads causing fatals in API endpoints. (
Browse files Browse the repository at this point in the history
#40726)

* Added a special case for non-array data.

* Changelog.
  • Loading branch information
zinigor authored Dec 30, 2024
1 parent 66197da commit 55e87d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Jetpack API: Fixed a bug where invalid upload input caused a fatal error.
5 changes: 5 additions & 0 deletions projects/plugins/jetpack/class.json-api-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,11 @@ public function handle_media_creation_v1_1( $media_files, $media_urls, $media_at

if ( ! $user_can_upload_files ) {
$media_id = new WP_Error( 'unauthorized', 'User cannot upload media.', 403 );
} elseif ( ! is_array( $media_item ) ) {
$media_id = new WP_Error( 'invalid_input', 'Unable to process request.', 400 );
$media_item = array(
'name' => 'invalid_file',
);
} elseif ( $this->media_item_is_free_video_mobile_upload_and_too_long( $media_item ) ) {
$media_id = new WP_Error( 'upload_video_length', 'Video uploads longer than 5 minutes require a paid plan.', 400 );
} else {
Expand Down

0 comments on commit 55e87d5

Please sign in to comment.