From fc3483a80717fdafbd1e206a257cffeaab6f62ce Mon Sep 17 00:00:00 2001 From: Heyde Moura Date: Mon, 12 Oct 2026 17:22:34 -0300 Subject: [PATCH] VideoPress Channel: only resolve a GUID to this site's attachment On WordPress.com, videopress_get_post_id_by_guid() returns the post ID of whichever blog owns the GUID. Channel::attachment_id() trusted it, so a foreign GUID could route /videopress?v= to an unrelated local post that shares that ID. Every candidate must now be this blog's attachment carrying the same GUID. Co-Authored-By: Claude Opus 5.5 --- .../fix-videopress-channel-guid-lookup | 4 ++ .../packages/videopress/src/class-channel.php | 38 ++++++++++-- .../tests/php/Channel_Data_Scoping_Test.php | 59 +++++++++++++++++++ .../fix-videopress-channel-guid-lookup | 4 ++ .../fix-videopress-channel-guid-lookup | 4 ++ 5 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 projects/packages/videopress/changelog/fix-videopress-channel-guid-lookup create mode 100644 projects/packages/videopress/tests/php/Channel_Data_Scoping_Test.php create mode 100644 projects/plugins/jetpack/changelog/fix-videopress-channel-guid-lookup create mode 100644 projects/plugins/videopress/changelog/fix-videopress-channel-guid-lookup diff --git a/projects/packages/videopress/changelog/fix-videopress-channel-guid-lookup b/projects/packages/videopress/changelog/fix-videopress-channel-guid-lookup new file mode 100644 index 000000000000..59b12a1a6270 --- /dev/null +++ b/projects/packages/videopress/changelog/fix-videopress-channel-guid-lookup @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Channel: Only open a channel video page for a video uploaded to this site. diff --git a/projects/packages/videopress/src/class-channel.php b/projects/packages/videopress/src/class-channel.php index 763caf78aa2e..d2fac3501612 100644 --- a/projects/packages/videopress/src/class-channel.php +++ b/projects/packages/videopress/src/class-channel.php @@ -125,14 +125,42 @@ public static function attachment_id( $guid ) { if ( ! is_string( $guid ) || ! preg_match( '/^[a-zA-Z0-9]{8}$/', $guid ) ) { return 0; } - $id = function_exists( 'videopress_get_post_id_by_guid' ) ? videopress_get_post_id_by_guid( $guid ) : false; - if ( ! is_int( $id ) && function_exists( 'video_get_info_by_guid' ) ) { + + /* + * WordPress.com's videopress_get_post_id_by_guid() returns the post ID of + * whichever blog owns the GUID, so every candidate must prove it is this + * blog's attachment for that GUID before it is used. + */ + $candidates = array(); + if ( function_exists( 'videopress_get_post_id_by_guid' ) ) { + $candidates[] = videopress_get_post_id_by_guid( $guid ); + } + if ( function_exists( 'video_get_info_by_guid' ) ) { $info = video_get_info_by_guid( $guid ); - if ( is_object( $info ) && ! empty( $info->post_id ) && (int) $info->blog_id === get_current_blog_id() ) { - $id = (int) $info->post_id; + if ( is_object( $info ) && ! empty( $info->post_id ) && isset( $info->blog_id ) && (int) $info->blog_id === get_current_blog_id() ) { + $candidates[] = $info->post_id; } } - return is_int( $id ) && $id > 0 ? $id : 0; + + foreach ( $candidates as $candidate ) { + $id = is_numeric( $candidate ) ? (int) $candidate : 0; + if ( $id > 0 && self::is_attachment_for( $id, $guid ) ) { + return $id; + } + } + return 0; + } + + /** + * Whether a post ID is this blog's VideoPress attachment for a GUID. + * + * @param int $id Post ID. + * @param string $guid The GUID. + * @return bool + */ + private static function is_attachment_for( $id, $guid ) { + $post = get_post( $id ); + return $post instanceof WP_Post && 'attachment' === $post->post_type && self::guid( $post ) === $guid; } /** diff --git a/projects/packages/videopress/tests/php/Channel_Data_Scoping_Test.php b/projects/packages/videopress/tests/php/Channel_Data_Scoping_Test.php new file mode 100644 index 000000000000..7c5d83010f80 --- /dev/null +++ b/projects/packages/videopress/tests/php/Channel_Data_Scoping_Test.php @@ -0,0 +1,59 @@ + 'attachment', + 'post_status' => 'inherit', + 'post_mime_type' => Channel::MIME_TYPE, + 'post_title' => $guid, + ) + ); + update_post_meta( $id, 'videopress_guid', $guid ); + return $id; + } + + /** + * WordPress.com's GUID lookup returns another blog's post ID; a local post with + * that ID but another GUID, or one that is not an attachment, is never used. + */ + public function test_attachment_id_only_returns_this_blogs_attachment_for_the_guid() { + $local = $this->video( 'localGU1' ); + $page = wp_insert_post( + array( + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => 'Not a video', + ) + ); + + set_transient( 'videopress_get_post_id_by_guid_localGU1', $local, HOUR_IN_SECONDS ); + set_transient( 'videopress_get_post_id_by_guid_remoteG1', $local, HOUR_IN_SECONDS ); + set_transient( 'videopress_get_post_id_by_guid_remoteG2', $page, HOUR_IN_SECONDS ); + + $this->assertSame( $local, Channel::attachment_id( 'localGU1' ) ); + $this->assertSame( 0, Channel::attachment_id( 'remoteG1' ) ); + $this->assertSame( 0, Channel::attachment_id( 'remoteG2' ) ); + } +} diff --git a/projects/plugins/jetpack/changelog/fix-videopress-channel-guid-lookup b/projects/plugins/jetpack/changelog/fix-videopress-channel-guid-lookup new file mode 100644 index 000000000000..8a818d508b85 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-videopress-channel-guid-lookup @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +VideoPress: Only open a channel video page for a video uploaded to this site. diff --git a/projects/plugins/videopress/changelog/fix-videopress-channel-guid-lookup b/projects/plugins/videopress/changelog/fix-videopress-channel-guid-lookup new file mode 100644 index 000000000000..d141b0956702 --- /dev/null +++ b/projects/plugins/videopress/changelog/fix-videopress-channel-guid-lookup @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Only open a channel video page for a video uploaded to this site.