From 2a7026d88fd7c59e62323c3b432e54886dfd7394 Mon Sep 17 00:00:00 2001 From: Aaron Campbell Date: Tue, 19 Sep 2017 13:48:35 +0000 Subject: [PATCH] oEmbed: Add extra hardening around allowed HTML for improved sandboxing. Merges [41448] to 4.7 branch. Built from https://develop.svn.wordpress.org/branches/4.7@41451 git-svn-id: http://core.svn.wordpress.org/branches/4.7@41284 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/embed.php | 30 ++++++++++++++++++------------ wp-includes/version.php | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/wp-includes/embed.php b/wp-includes/embed.php index b987649f52..fcc61a947f 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -753,24 +753,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( '