Skip to content

Commit dd319b8

Browse files
committed
Collaboration: Harden entity permission checks
Reject non-numeric object IDs early in can_user_collaborate_on_entity_type(). Verify that a post's actual type matches the room's claimed entity name before granting access. For taxonomy rooms, confirm the term exists in the specified taxonomy and simplify the capability check to use assign_term with the term's object ID.
1 parent 9b45174 commit dd319b8

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/wp-includes/collaboration/class-wp-http-polling-collaboration-server.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,25 @@ public function handle_request( WP_REST_Request $request ) {
347347
* @return bool True if user has permission, otherwise false.
348348
*/
349349
private function can_user_collaborate_on_entity_type( string $entity_kind, string $entity_name, ?string $object_id ): bool {
350+
// Reject non-numeric object IDs early.
351+
if ( ! is_null( $object_id ) && ! is_numeric( $object_id ) ) {
352+
return false;
353+
}
354+
350355
// Handle single post type entities with a defined object ID.
351356
if ( 'postType' === $entity_kind && is_numeric( $object_id ) ) {
357+
if ( get_post_type( $object_id ) !== $entity_name ) {
358+
return false;
359+
}
352360
return current_user_can( 'edit_post', (int) $object_id );
353361
}
354362

355363
// Handle single taxonomy term entities with a defined object ID.
356364
if ( 'taxonomy' === $entity_kind && is_numeric( $object_id ) ) {
357-
$taxonomy = get_taxonomy( $entity_name );
358-
return isset( $taxonomy->cap->assign_terms ) && current_user_can( $taxonomy->cap->assign_terms );
365+
if ( ! term_exists( (int) $object_id, $entity_name ) ) {
366+
return false;
367+
}
368+
return current_user_can( 'assign_term', (int) $object_id );
359369
}
360370

361371
// Handle single comment entities with a defined object ID.

0 commit comments

Comments
 (0)