Skip to content

Commit 54a0191

Browse files
committed
Customize: Don't let hardcoded regex override customize_allowed_urls filter.
See #65030.
1 parent 74c99a3 commit 54a0191

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/js/_enqueues/wp/customize/controls.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6574,15 +6574,10 @@
65746574
*/
65756575

65766576
previewer.add( 'previewUrl', params.previewUrl ).setter( function( to ) {
6577-
var result = null, urlParser, queryParams, parsedAllowedUrl, parsedCandidateUrls = [];
6577+
var result = null, urlParser, queryParams, parsedAllowedUrl, matchedAllowedPath, parsedCandidateUrls = [];
65786578
urlParser = document.createElement( 'a' );
65796579
urlParser.href = to;
65806580

6581-
// Abort if URL is for admin or (static) files in wp-includes or wp-content.
6582-
if ( /\/wp-(admin|includes|content)(\/|$)/.test( urlParser.pathname ) ) {
6583-
return null;
6584-
}
6585-
65866581
// Remove state query params.
65876582
if ( urlParser.search.length > 1 ) {
65886583
queryParams = api.utils.parseQueryString( urlParser.search.substr( 1 ) );
@@ -6613,12 +6608,18 @@
66136608
return ! _.isUndefined( _.find( previewer.allowedUrls, function( allowedUrl ) {
66146609
parsedAllowedUrl.href = allowedUrl;
66156610
if ( urlParser.protocol === parsedAllowedUrl.protocol && urlParser.host === parsedAllowedUrl.host && 0 === urlParser.pathname.indexOf( parsedAllowedUrl.pathname.replace( /\/$/, '' ) ) ) {
6611+
matchedAllowedPath = parsedAllowedUrl.pathname.replace( /\/$/, '' );
66166612
result = parsedCandidateUrl.href;
66176613
return true;
66186614
}
66196615
} ) );
66206616
} );
66216617

6618+
// Disallow links to admin, includes, and content, unless the matching allowed URL itself contains such a path.
6619+
if ( result && /\/wp-(admin|includes|content)(\/|$)/.test( urlParser.pathname.substring( matchedAllowedPath ? matchedAllowedPath.length : 0 ) ) ) {
6620+
return null;
6621+
}
6622+
66226623
return result;
66236624
});
66246625

src/js/_enqueues/wp/customize/preview.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
* @return {boolean} Is appropriate for changeset link.
282282
*/
283283
api.isLinkPreviewable = function isLinkPreviewable( element, options ) {
284-
var matchesAllowedUrl, parsedAllowedUrl, args, elementHost;
284+
var matchesAllowedUrl, matchedAllowedPath, parsedAllowedUrl, args, elementHost;
285285

286286
args = _.extend( {}, { allowAdminAjax: false }, options || {} );
287287

@@ -298,7 +298,10 @@
298298
parsedAllowedUrl = document.createElement( 'a' );
299299
matchesAllowedUrl = ! _.isUndefined( _.find( api.settings.url.allowed, function( allowedUrl ) {
300300
parsedAllowedUrl.href = allowedUrl;
301-
return parsedAllowedUrl.protocol === element.protocol && parsedAllowedUrl.host.replace( /:(80|443)$/, '' ) === elementHost && 0 === element.pathname.indexOf( parsedAllowedUrl.pathname.replace( /\/$/, '' ) );
301+
if ( parsedAllowedUrl.protocol === element.protocol && parsedAllowedUrl.host.replace( /:(80|443)$/, '' ) === elementHost && 0 === element.pathname.indexOf( parsedAllowedUrl.pathname.replace( /\/$/, '' ) ) ) {
302+
matchedAllowedPath = parsedAllowedUrl.pathname.replace( /\/$/, '' );
303+
return true;
304+
}
302305
} ) );
303306
if ( ! matchesAllowedUrl ) {
304307
return false;
@@ -314,8 +317,8 @@
314317
return args.allowAdminAjax;
315318
}
316319

317-
// Disallow links to admin, includes, and content.
318-
if ( /\/wp-(admin|includes|content)(\/|$)/.test( element.pathname ) ) {
320+
// Disallow links to admin, includes, and content, unless the matching allowed URL itself contains such a path.
321+
if ( /\/wp-(admin|includes|content)(\/|$)/.test( element.pathname.substring( matchedAllowedPath ? matchedAllowedPath.length : 0 ) ) ) {
319322
return false;
320323
}
321324

0 commit comments

Comments
 (0)