From 59487b189cc65d9b0f030268eaeb3c3fc28c7c67 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 20 Sep 2024 08:15:31 -0400 Subject: [PATCH] Add `+https` directive to `urlskip=` option When present, the `+https` directive will force the protocol of the resulting URL to be `https:`. Related feedback: https://github.com/uBlockOrigin/uBlock-issues/issues/3206#issuecomment-2363392357 --- src/js/static-net-filtering.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 5ae59f062..e5e9017d2 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -5424,13 +5424,25 @@ function urlSkip(urlin, steps) { try { let urlout; for ( const step of steps ) { - if ( step.startsWith('?') === false ) { return; } - urlout = (new URL(urlin)).searchParams.get(step.slice(1)); - if ( urlout === null ) { return; } - if ( urlout.includes(' ') ) { - urlout = urlout.replace(/ /g, '%20'); + // Extract from URL parameter + if ( step.startsWith('?') ) { + urlout = (new URL(urlin)).searchParams.get(step.slice(1)); + if ( urlout === null ) { return; } + if ( urlout.includes(' ') ) { + urlout = urlout.replace(/ /g, '%20'); + } + urlin = urlout; + continue; } - urlin = urlout; + // Enforce https + if ( step === '+https' ) { + const s = urlin.replace(/^https?:\/\//, ''); + if ( /^[\w-]:\/\//.test(s) ) { return; } + urlin = urlout = `https://${s}`; + continue; + } + // Unknown directive + return; } void new URL(urlout); return urlout;