From d81f522a57b724d1acd0f547745be2a482605728 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Tue, 16 May 2023 14:25:21 +0000 Subject: [PATCH] Embeds: Add protocol validation for WordPress Embed code. Validate that links within auto-discovered embeds are using the `http` or `https` protocols before following links. Props xknown, dd32, peterwilsoncc. Built from https://develop.svn.wordpress.org/trunk@55763 git-svn-id: http://core.svn.wordpress.org/trunk@55275 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/wp-embed.js | 6 ++++++ wp-includes/js/wp-embed.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/wp-includes/js/wp-embed.js b/wp-includes/js/wp-embed.js index fa2934f379..58ae034f49 100644 --- a/wp-includes/js/wp-embed.js +++ b/wp-includes/js/wp-embed.js @@ -49,6 +49,7 @@ var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ), blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ), + allowedProtocols = new RegExp( '^https?:$', 'i' ), i, source, height, sourceURL, targetURL; for ( i = 0; i < blockquotes.length; i++ ) { @@ -84,6 +85,11 @@ sourceURL.href = source.getAttribute( 'src' ); targetURL.href = data.value; + /* Only follow link if the protocol is in the allow list. */ + if ( ! allowedProtocols.test( targetURL.protocol ) ) { + continue; + } + /* Only continue if link hostname matches iframe's hostname. */ if ( targetURL.host === sourceURL.host ) { if ( document.activeElement === source ) { diff --git a/wp-includes/js/wp-embed.min.js b/wp-includes/js/wp-embed.min.js index 5c39878578..3ef2f3c414 100644 --- a/wp-includes/js/wp-embed.min.js +++ b/wp-includes/js/wp-embed.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(c,l){"use strict";var e=!1,o=!1;if(l.querySelector)if(c.addEventListener)e=!0;if(c.wp=c.wp||{},c.wp.receiveEmbedMessage);else if(c.wp.receiveEmbedMessage=function(e){var t=e.data;if(!t);else if(!(t.secret||t.message||t.value));else if(/[^a-zA-Z0-9]/.test(t.secret));else{for(var r,s,a,i=l.querySelectorAll('iframe[data-secret="'+t.secret+'"]'),n=l.querySelectorAll('blockquote[data-secret="'+t.secret+'"]'),o=0;o