diff --git src/wp-includes/embed-functions.php src/wp-includes/embed-functions.php
index 7e90221..2b827e5 100644
|
|
|
function wp_filter_oembed_result( $result, $data, $url ) { |
| 728 | 728 | return false; |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | | $html = str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $iframes[1] ); |
| 732 | | |
| 733 | | preg_match( '/ src=[\'"]([^\'"]*)[\'"]/', $html, $results ); |
| 734 | | |
| 735 | | if ( ! empty( $results ) ) { |
| 736 | | $secret = wp_generate_password( 10, false ); |
| 737 | | |
| 738 | | $url = esc_url( "{$results[1]}#?secret=$secret" ); |
| 739 | | |
| 740 | | $html = str_replace( $results[0], " src=\"$url\" data-secret=\"$secret\"", $html ); |
| 741 | | } |
| 742 | | |
| 743 | | return $html; |
| | 731 | return str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $iframes[1] ); |
| 744 | 732 | } |
| 745 | 733 | |
| 746 | 734 | /** |
diff --git src/wp-includes/js/wp-embed.js src/wp-includes/js/wp-embed.js
index dd03bc0..2dbef36 100644
|
|
|
|
| 48 | 48 | |
| 49 | 49 | function onLoad() { |
| 50 | 50 | var isIE10 = -1 !== navigator.appVersion.indexOf( 'MSIE 10' ), |
| 51 | | isIE11 = !!navigator.userAgent.match( /Trident.*rv\:11\./ ); |
| | 51 | isIE11 = !!navigator.userAgent.match( /Trident.*rv:11\./ ), |
| | 52 | iframeClone, secret; |
| 52 | 53 | |
| 53 | | /* Remove security attribute from iframes in IE10 and IE11. */ |
| 54 | | if ( isIE10 || isIE11 ) { |
| 55 | | var iframes = document.querySelectorAll( '.wp-embedded-content[security]' ), iframeClone; |
| | 54 | var iframes = document.querySelectorAll( '.wp-embedded-content' ); |
| | 55 | for ( var i = 0; i < iframes.length; i++ ) { |
| | 56 | /* Add secret to iframe */ |
| | 57 | secret = Math.random().toString( 36 ).substr( 2, 10 ); |
| | 58 | iframes[ i ].src += '#?secret=' + secret; |
| | 59 | iframes[ i ].setAttribute( 'data-secret', secret ); |
| 56 | 60 | |
| 57 | | for ( var i = 0; i < iframes.length; i++ ) { |
| | 61 | /* Remove security attribute from iframes in IE10 and IE11. */ |
| | 62 | if ( !!iframes[ i ].getAttribute( 'security' ) && (isIE10 || isIE11) ) { |
| 58 | 63 | iframeClone = iframes[ i ].cloneNode( true ); |
| 59 | 64 | iframeClone.removeAttribute( 'security' ); |
| 60 | | iframes[ i ].parentNode.insertBefore( iframeClone, iframes[ i ].nextSibling ); |
| 61 | | iframes[ i ].parentNode.removeChild( iframes[ i ] ); |
| | 65 | iframes[ i ].parentNode.replaceChild( iframeClone, iframes[ i ] ); |
| 62 | 66 | } |
| 63 | 67 | } |
| 64 | 68 | } |
diff --git tests/phpunit/tests/oembed/filterResult.php tests/phpunit/tests/oembed/filterResult.php
index cfe5c98..fceba65 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 | |