From 8cf8e2c66d9ad104a2a000832b4a4a0ab68a3ee0 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 3 Dec 2015 20:17:25 +0000 Subject: [PATCH] WP oEmbed: validate the `secret` send via `postMessage` in `wp.receiveEmbedMessage`. Also, compare `window` instances. In the data sent to us from the embedded iframe by postMessage(), the secret value is being used directly in a document.querySelectorAll() call without first being validated or escaped. In theory, this could lead to some broken embeds. Props mdawaffe. Fixes #34831. Built from https://develop.svn.wordpress.org/trunk@35761 git-svn-id: http://core.svn.wordpress.org/trunk@35725 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/embed.php | 2 +- wp-includes/js/wp-embed.js | 8 ++++++++ wp-includes/js/wp-embed.min.js | 2 +- wp-includes/version.php | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/wp-includes/embed.php b/wp-includes/embed.php index 739f0270e2..5e4cdc1605 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -478,7 +478,7 @@ function get_post_embed_html( $width, $height, $post = null ) { * and edit wp-embed.js directly. */ $output .=<<1e3)g=1e3;else if(200>~~g)g=200;f.height=g}if("link"===d.message)if(h=b.createElement("a"),i=b.createElement("a"),h.href=f.getAttribute("src"),i.href=d.value,i.host===h.host)if(b.activeElement===f)a.top.location.href=d.value}}},d)a.addEventListener("message",a.wp.receiveEmbedMessage,!1),b.addEventListener("DOMContentLoaded",c,!1),a.addEventListener("load",c,!1)}(window,document); + !function(a,b){"use strict";function c(){if(!e){e=!0;var a,c,d,f,g=-1!==navigator.appVersion.indexOf("MSIE 10"),h=!!navigator.userAgent.match(/Trident.*rv:11\./),i=b.querySelectorAll("iframe.wp-embedded-content"),j=b.querySelectorAll("blockquote.wp-embedded-content");for(c=0;c1e3)g=1e3;else if(200>~~g)g=200;f.height=g}if("link"===d.message)if(h=b.createElement("a"),i=b.createElement("a"),h.href=f.getAttribute("src"),i.href=d.value,i.host===h.host)if(b.activeElement===f)a.top.location.href=d.value}else;}},d)a.addEventListener("message",a.wp.receiveEmbedMessage,!1),b.addEventListener("DOMContentLoaded",c,!1),a.addEventListener("load",c,!1)}(window,document); JS; } $output .= "\n//-->"; diff --git a/wp-includes/js/wp-embed.js b/wp-includes/js/wp-embed.js index 50471c714b..985f0b801d 100644 --- a/wp-includes/js/wp-embed.js +++ b/wp-includes/js/wp-embed.js @@ -22,6 +22,10 @@ return; } + if ( /[^a-zA-Z0-9]/.test( data.secret ) ) { + return; + } + var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ), blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ), i, source, height, sourceURL, targetURL; @@ -33,6 +37,10 @@ for ( i = 0; i < iframes.length; i++ ) { source = iframes[ i ]; + if ( e.source !== source.contentWindow ) { + continue; + } + source.style.display = ''; /* Resize the iframe on request. */ diff --git a/wp-includes/js/wp-embed.min.js b/wp-includes/js/wp-embed.min.js index aed371f911..6c4be094c4 100644 --- a/wp-includes/js/wp-embed.min.js +++ b/wp-includes/js/wp-embed.min.js @@ -1 +1 @@ -!function(a,b){"use strict";function c(){if(!e){e=!0;var a,c,d,f,g=-1!==navigator.appVersion.indexOf("MSIE 10"),h=!!navigator.userAgent.match(/Trident.*rv:11\./),i=b.querySelectorAll("iframe.wp-embedded-content"),j=b.querySelectorAll("blockquote.wp-embedded-content");for(c=0;c1e3)g=1e3;else if(200>~~g)g=200;f.height=g}if("link"===d.message)if(h=b.createElement("a"),i=b.createElement("a"),h.href=f.getAttribute("src"),i.href=d.value,i.host===h.host)if(b.activeElement===f)a.top.location.href=d.value}}},d)a.addEventListener("message",a.wp.receiveEmbedMessage,!1),b.addEventListener("DOMContentLoaded",c,!1),a.addEventListener("load",c,!1)}(window,document); \ No newline at end of file +!function(a,b){"use strict";function c(){if(!e){e=!0;var a,c,d,f,g=-1!==navigator.appVersion.indexOf("MSIE 10"),h=!!navigator.userAgent.match(/Trident.*rv:11\./),i=b.querySelectorAll("iframe.wp-embedded-content"),j=b.querySelectorAll("blockquote.wp-embedded-content");for(c=0;c1e3)g=1e3;else if(200>~~g)g=200;f.height=g}if("link"===d.message)if(h=b.createElement("a"),i=b.createElement("a"),h.href=f.getAttribute("src"),i.href=d.value,i.host===h.host)if(b.activeElement===f)a.top.location.href=d.value}else;}},d)a.addEventListener("message",a.wp.receiveEmbedMessage,!1),b.addEventListener("DOMContentLoaded",c,!1),a.addEventListener("load",c,!1)}(window,document); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index cad50d3db3..144ee21419 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-RC1-35760'; +$wp_version = '4.4-RC1-35761'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.