Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional avatar REST checks #317

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion includes/class-simple-local-avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -1324,11 +1324,22 @@ public function set_avatar_rest( $input, $user ) {
return new \WP_Error( 'invalid_media_id', esc_html__( 'Request did not contain a valid media_id field.', 'simple-local-avatars' ) );
}

$attachment = get_post( (int) $input['media_id'] );

// Ensure this media_id is a valid attachment.
if ( ! wp_get_attachment_url( (int) $input['media_id'] ) ) {
if (
! $attachment ||
'attachment' !== $attachment->post_type ||
! wp_attachment_is_image( $attachment )
) {
return new \WP_Error( 'invalid_media_id', esc_html__( 'Media ID did not match a valid attachment.', 'simple-local-avatars' ) );
}

// Ensure this attachment is associated with this user.
if ( (int) $attachment->post_author !== (int) $user->ID ) {
return new \WP_Error( 'invalid_media_id', esc_html__( 'This attachment was not uploaded by this user.', 'simple-local-avatars' ) );
}

$this->assign_new_user_avatar( (int) $input['media_id'], $user->ID );
}

Expand Down
Loading