From 6e81771783f56b720663c648e12f4256725e951b Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 15 Sep 2016 09:06:22 -0400 Subject: [PATCH] #1735: remove spurious whitespaces from data URI description fields --- platform/chromium/vapi-background.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 3014ca2f3..a4c524168 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -240,10 +240,25 @@ vAPI.tabs.registerListeners = function() { // http://raymondhill.net/ublock/popup.html var reGoodForWebRequestAPI = /^https?:\/\//; + // https://forums.lanik.us/viewtopic.php?f=62&t=32826 + // Chromium-based browsers: sanitize target URL. I've seen + // data: URI-based with newline characters, possibly as a way of + // evading filters. There should be no whitespaces in a data: URI's + // standard fields. + var sanitizeURL = function(url) { + if ( url.startsWith('data:') === false ) { return url; } + var pos = url.indexOf(','); + if ( pos === -1 ) { return url; } + var s = url.slice(0, pos); + if ( s.search(/\s/) === -1 ) { return url; } + return s.replace(/\s+/, '') + url.slice(pos); + }; + var onCreatedNavigationTarget = function(details) { //console.debug('onCreatedNavigationTarget: popup candidate tab id %d = "%s"', details.tabId, details.url); if ( reGoodForWebRequestAPI.test(details.url) === false ) { details.frameId = 0; + details.url = sanitizeURL(details.url); onNavigationClient(details); } if ( typeof vAPI.tabs.onPopupCreated === 'function' ) { @@ -261,6 +276,7 @@ vAPI.tabs.registerListeners = function() { if ( details.frameId !== 0 ) { return; } + details.url = sanitizeURL(details.url); onNavigationClient(details); }; @@ -269,6 +285,9 @@ vAPI.tabs.registerListeners = function() { }; var onUpdated = function(tabId, changeInfo, tab) { + if ( changeInfo.url ) { + changeInfo.url = sanitizeURL(changeInfo.url); + } onUpdatedClient(tabId, changeInfo, tab); };