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