From f1c76c55321473000ee7379bc188ecf679a90221 Mon Sep 17 00:00:00 2001 From: Aaron Campbell Date: Tue, 19 Sep 2017 13:50:32 +0000 Subject: [PATCH] oEmbed: Add extra hardening around allowed HTML for improved sandboxing. Merges [41448] to 4.5 branch. Built from https://develop.svn.wordpress.org/branches/4.5@41454 git-svn-id: http://core.svn.wordpress.org/branches/4.5@41287 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/embed.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/wp-includes/embed.php b/wp-includes/embed.php index 54b9cf75c3..600897464f 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -782,24 +782,30 @@ function wp_filter_oembed_result( $result, $data, $url ) { } $html = $content[1] . $content[2]; + preg_match( '/ src=([\'"])(.*?)\1/', $html, $results ); + + if ( ! empty( $results ) ) { + $secret = wp_generate_password( 10, false ); + + $url = esc_url( "{$results[2]}#?secret=$secret" ); + $q = $results[1]; + + $html = str_replace( $results[0], ' src=' . $q . $url . $q . ' data-secret=' . $q . $secret . $q, $html ); + $html = str_replace( '