From aede7704230968885a33a8842c8db2f157137e1d Mon Sep 17 00:00:00 2001 From: Kevin Date: Sun, 18 Jul 2021 12:52:14 +0200 Subject: [PATCH] Limit recursion when parsing URL in document-blocked page Related Issue: https://github.com/uBlockOrigin/uBlock-issues/issues/1649 --- src/js/main-blocked.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/js/main-blocked.js b/src/js/main-blocked.js index ed617645..52793009 100644 --- a/src/js/main-blocked.js +++ b/src/js/main-blocked.js @@ -87,21 +87,22 @@ uDom('.what').text(details.url); return s; }; - const renderParams = function(parentNode, rawURL) { + // https://github.com/uBlockOrigin/uBlock-issues/issues/1649 + // Limit recursion. + const renderParams = function(parentNode, rawURL, depth = 0) { const a = document.createElement('a'); a.href = rawURL; if ( a.search.length === 0 ) { return false; } - const pos = rawURL.indexOf('?'); + let pos = rawURL.indexOf('?'); const li = liFromParam( - vAPI.i18n('mainBlockedNoParamsPrompt'), + vAPI.i18n('docblockedNoParamsPrompt'), rawURL.slice(0, pos) ); parentNode.appendChild(li); const params = a.search.slice(1).split('&'); - for ( let i = 0; i < params.length; i++ ) { - const param = params[i]; + for ( const param of params ) { let pos = param.indexOf('='); if ( pos === -1 ) { pos = param.length; @@ -109,9 +110,9 @@ uDom('.what').text(details.url); const name = safeDecodeURIComponent(param.slice(0, pos)); const value = safeDecodeURIComponent(param.slice(pos + 1)); const li = liFromParam(name, value); - if ( reURL.test(value) ) { + if ( depth < 2 && reURL.test(value) ) { const ul = document.createElement('ul'); - renderParams(ul, value); + renderParams(ul, value, depth + 1); li.appendChild(ul); } parentNode.appendChild(li);