Skip to content

Commit

Permalink
gorhill#1735: remove spurious whitespaces from data URI description f…
Browse files Browse the repository at this point in the history
…ields
  • Loading branch information
gorhill committed Sep 15, 2016
1 parent 63691a2 commit 6e81771
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) {
Expand All @@ -261,6 +276,7 @@ vAPI.tabs.registerListeners = function() {
if ( details.frameId !== 0 ) {
return;
}
details.url = sanitizeURL(details.url);
onNavigationClient(details);
};

Expand All @@ -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);
};

Expand Down

0 comments on commit 6e81771

Please sign in to comment.