From bcc058eba75d4cbb2cd0447885f75e0705812883 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 20 Nov 2024 07:53:52 -0500 Subject: [PATCH] Add `-safebase64` directive in `urlskip=` Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3206#issuecomment-2487392846 --- src/js/static-net-filtering.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 422d5af5d..f11b2b147 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -5417,6 +5417,8 @@ StaticNetFilteringEngine.prototype.transformRequest = function(fctxt, out = []) * * `-base64`: decode the current string as a base64-encoded string. * + * `-safebase64`: decode the current string as a safe base64-encoded string. + * * `-uricomponent`: decode the current string as a URI encoded string. * * `-blocked`: allow the redirection of blocked requests. By default, blocked @@ -5498,6 +5500,12 @@ function urlSkip(directive, url, blocked, steps) { urlout = self.atob(urlin); continue; } + // Safe Base64 + if ( step === '-safebase64' ) { + urlout = urlin.replace(/[-_]/, safeBase64Replacer); + urlout = self.atob(urlout); + continue; + } // URI component if ( step === '-uricomponent' ) { urlout = self.decodeURIComponent(urlin); @@ -5543,6 +5551,9 @@ function urlSkip(directive, url, blocked, steps) { } } +const safeBase64Map = { '-': '+', '_': '/' }; +const safeBase64Replacer = s => safeBase64Map[s]; + /******************************************************************************/ // https://github.com/uBlockOrigin/uBlock-issues/issues/1626