diff --git src/wp-includes/embed-functions.php src/wp-includes/embed-functions.php
index 360399e..32a3e79 100644
|
|
|
function get_post_embed_html( $post = null, $width, $height ) { |
| 461 | 461 | |
| 462 | 462 | $embed_url = get_post_embed_url( $post ); |
| 463 | 463 | |
| 464 | | $output = '<blockquote><a href="' . get_permalink( $post ) . '">' . get_the_title( $post ) . "</a></blockquote>\n"; |
| | 464 | $output = '<blockquote class="wp-embedded-content"><a href="' . get_permalink( $post ) . '">' . get_the_title( $post ) . "</a></blockquote>\n"; |
| 465 | 465 | |
| 466 | 466 | $output .= "<script type='text/javascript'>\n"; |
| 467 | 467 | $output .= "<!--//--><![CDATA[//><!--\n"; |
| … |
… |
function wp_filter_oembed_result( $result, $data, $url ) { |
| 757 | 757 | 'a' => array( |
| 758 | 758 | 'href' => true, |
| 759 | 759 | ), |
| 760 | | 'blockquote' => array(), |
| | 760 | 'blockquote' => array( |
| | 761 | 'class' => true, |
| | 762 | ), |
| 761 | 763 | 'iframe' => array( |
| 762 | 764 | 'src' => true, |
| 763 | 765 | 'width' => true, |
| … |
… |
function wp_filter_oembed_result( $result, $data, $url ) { |
| 773 | 775 | |
| 774 | 776 | $html = wp_kses( $result, $allowed_html ); |
| 775 | 777 | |
| 776 | | preg_match( '|(<blockquote>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content ); |
| | 778 | preg_match( '|(<blockquote.*?>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content ); |
| 777 | 779 | // We require at least the iframe to exist. |
| 778 | 780 | if ( empty( $content[2] ) ) { |
| 779 | 781 | return false; |
| … |
… |
function wp_filter_oembed_result( $result, $data, $url ) { |
| 785 | 787 | $html = str_replace( '<iframe', '<iframe style="display:none;"', $html ); |
| 786 | 788 | } |
| 787 | 789 | |
| 788 | | $html = str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $html ); |
| 789 | | |
| 790 | | preg_match( '/ src=[\'"]([^\'"]*)[\'"]/', $html, $results ); |
| 791 | | |
| 792 | | if ( ! empty( $results ) ) { |
| 793 | | $secret = wp_generate_password( 10, false ); |
| 794 | | |
| 795 | | $url = esc_url( "{$results[1]}#?secret=$secret" ); |
| 796 | | |
| 797 | | $html = str_replace( $results[0], " src=\"$url\" data-secret=\"$secret\"", $html ); |
| 798 | | $html = str_replace( '<blockquote', "<blockquote data-secret=\"$secret\"", $html ); |
| 799 | | } |
| 800 | | |
| 801 | | return $html; |
| | 790 | return str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $html ); |
| 802 | 791 | } |
| 803 | 792 | |
| 804 | 793 | /** |
diff --git src/wp-includes/js/wp-embed-template.js src/wp-includes/js/wp-embed-template.js
index 847ebcf..819ef0c 100644
|
|
|
|
| 1 | 1 | (function ( window, document ) { |
| 2 | 2 | 'use strict'; |
| 3 | 3 | |
| 4 | | var secret = window.location.hash.replace( /.*secret=([\d\w]{10}).*/, '$1' ), |
| 5 | | resizing; |
| | 4 | var secret, secretTimeout, resizing; |
| 6 | 5 | |
| 7 | 6 | function sendEmbedMessage( message, value ) { |
| 8 | 7 | window.parent.postMessage( { |
| … |
… |
|
| 159 | 158 | } |
| 160 | 159 | |
| 161 | 160 | window.addEventListener( 'resize', onResize, false ); |
| | 161 | |
| | 162 | /** |
| | 163 | * Re-get the secret when it was added later on. |
| | 164 | */ |
| | 165 | function getSecret() { |
| | 166 | if ( window.self === window.top || !!secret ) { |
| | 167 | return; |
| | 168 | } |
| | 169 | |
| | 170 | secret = window.location.hash.replace( /.*secret=([\d\w]{10}).*/, '$1' ); |
| | 171 | |
| | 172 | clearTimeout( secretTimeout ); |
| | 173 | |
| | 174 | secretTimeout = setTimeout( function () { |
| | 175 | getSecret(); |
| | 176 | }, 100 ); |
| | 177 | } |
| | 178 | |
| | 179 | getSecret(); |
| 162 | 180 | })( window, document ); |
diff --git src/wp-includes/js/wp-embed.js src/wp-includes/js/wp-embed.js
index 3829d0d..71f2bed 100644
|
|
|
|
| 13 | 13 | return; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | | var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ), |
| 17 | | blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ), |
| | 16 | var iframes = document.querySelectorAll( '.wp-embedded-content[data-secret="' + data.secret + '"]' ), |
| 18 | 17 | i, source, height, sourceURL, targetURL; |
| 19 | 18 | |
| 20 | | for ( i = 0; i < blockquotes.length; i++ ) { |
| 21 | | blockquotes[ i ].style.display = 'none'; |
| 22 | | } |
| 23 | | |
| 24 | 19 | for ( i = 0; i < iframes.length; i++ ) { |
| 25 | 20 | source = iframes[ i ]; |
| 26 | 21 | |
| 27 | | source.style.display = ''; |
| 28 | | |
| 29 | 22 | /* Resize the iframe on request. */ |
| 30 | 23 | if ( 'height' === data.message ) { |
| 31 | 24 | height = data.value; |
| … |
… |
|
| 58 | 51 | |
| 59 | 52 | function onLoad() { |
| 60 | 53 | var isIE10 = -1 !== navigator.appVersion.indexOf( 'MSIE 10' ), |
| 61 | | isIE11 = !!navigator.userAgent.match( /Trident.*rv\:11\./ ), |
| 62 | | iframes, iframeClone, i; |
| | 54 | isIE11 = !!navigator.userAgent.match( /Trident.*rv:11\./ ), |
| | 55 | iframes = document.querySelectorAll( 'iframe.wp-embedded-content' ), |
| | 56 | blockquotes = document.querySelectorAll( 'blockquote.wp-embedded-content' ), |
| | 57 | iframeClone, i, source, secret; |
| | 58 | |
| | 59 | for ( i = 0; i < blockquotes.length; i++ ) { |
| | 60 | blockquotes[ i ].style.display = 'none'; |
| | 61 | } |
| | 62 | |
| | 63 | for ( i = 0; i < iframes.length; i++ ) { |
| | 64 | source = iframes[ i ]; |
| | 65 | source.style.display = ''; |
| | 66 | |
| | 67 | if ( !!source.getAttribute( 'data-secret' ) ) { |
| | 68 | continue; |
| | 69 | } |
| 63 | 70 | |
| 64 | | /* Remove security attribute from iframes in IE10 and IE11. */ |
| 65 | | if ( isIE10 || isIE11 ) { |
| 66 | | iframes = document.querySelectorAll( '.wp-embedded-content[security]' ); |
| | 71 | /* Add secret to iframe */ |
| | 72 | secret = Math.random().toString( 36 ).substr( 2, 10 ); |
| | 73 | source.src += '#?secret=' + secret; |
| | 74 | source.setAttribute( 'data-secret', secret ); |
| 67 | 75 | |
| 68 | | for ( i = 0; i < iframes.length; i++ ) { |
| 69 | | iframeClone = iframes[ i ].cloneNode( true ); |
| | 76 | /* Remove security attribute from iframes in IE10 and IE11. */ |
| | 77 | if ( ( isIE10 || isIE11 ) && !!source.getAttribute( 'security' ) ) { |
| | 78 | iframeClone = source.cloneNode( true ); |
| 70 | 79 | iframeClone.removeAttribute( 'security' ); |
| 71 | | iframes[ i ].parentNode.insertBefore( iframeClone, iframes[ i ].nextSibling ); |
| 72 | | iframes[ i ].parentNode.removeChild( iframes[ i ] ); |
| | 80 | source.parentNode.replaceChild( iframeClone, source ); |
| 73 | 81 | } |
| 74 | 82 | } |
| 75 | 83 | } |
diff --git tests/phpunit/tests/oembed/filterResult.php tests/phpunit/tests/oembed/filterResult.php
index 7559f62..063fdd0 100644
|
|
|
class Tests_Filter_oEmbed_Result extends WP_UnitTestCase { |
| 16 | 16 | $html = '<p></p><iframe onload="alert(1)" src="http://example.com/sample-page/"></iframe>'; |
| 17 | 17 | $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), 'http://example.com/sample-page/' ); |
| 18 | 18 | |
| 19 | | $matches = array(); |
| 20 | | preg_match( '|src=".*#\?secret=([\w\d]+)" data-secret="([\w\d]+)"|', $actual, $matches ); |
| 21 | | |
| 22 | | $this->assertTrue( isset( $matches[1] ) ); |
| 23 | | $this->assertTrue( isset( $matches[2] ) ); |
| 24 | | $this->assertEquals( $matches[1], $matches[2] ); |
| | 19 | $this->assertEquals( '<iframe sandbox="allow-scripts" security="restricted" src="http://example.com/sample-page/"></iframe>', $actual ); |
| 25 | 20 | } |
| 26 | 21 | |
| 27 | 22 | function test_filter_oembed_result_only_one_iframe_is_allowed() { |
| … |
… |
EOD; |
| 56 | 51 | $this->assertFalse( $actual ); |
| 57 | 52 | } |
| 58 | 53 | |
| 59 | | function test_filter_oembed_result_secret_param_available() { |
| 60 | | $html = '<iframe src="https://wordpress.org"></iframe>'; |
| 61 | | $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ); |
| 62 | | |
| 63 | | $matches = array(); |
| 64 | | preg_match( '|src="https://wordpress.org#\?secret=([\w\d]+)" data-secret="([\w\d]+)"|', $actual, $matches ); |
| 65 | | |
| 66 | | $this->assertTrue( isset( $matches[1] ) ); |
| 67 | | $this->assertTrue( isset( $matches[2] ) ); |
| 68 | | $this->assertEquals( $matches[1], $matches[2] ); |
| 69 | | } |
| 70 | | |
| 71 | 54 | function test_filter_oembed_result_wrong_type_provided() { |
| 72 | 55 | $actual = wp_filter_oembed_result( 'some string', (object) array( 'type' => 'link' ), '' ); |
| 73 | 56 | |
| … |
… |
EOD; |
| 87 | 70 | } |
| 88 | 71 | |
| 89 | 72 | function test_filter_oembed_result_allowed_html() { |
| 90 | | $html = '<blockquote><strong><a href="" target=""></a></strong></blockquote><iframe></iframe>'; |
| | 73 | $html = '<blockquote class="foo" id="bar"><strong><a href="" target=""></a></strong></blockquote><iframe></iframe>'; |
| 91 | 74 | $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ); |
| 92 | 75 | |
| 93 | | $this->assertEquals( '<blockquote><a href=""></a></blockquote><iframe sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual ); |
| | 76 | $this->assertEquals( '<blockquote class="foo"><a href=""></a></blockquote><iframe sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual ); |
| 94 | 77 | } |
| 95 | 78 | } |