Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit e35f6b1

Browse files
committed
sanitize code paths
1 parent fd2f4f0 commit e35f6b1

File tree

1 file changed

+60
-32
lines changed

1 file changed

+60
-32
lines changed

js/traffic.js

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,54 @@ background: #c00; \
9797

9898
/******************************************************************************/
9999

100+
// If it is HTTP Switchboard's root frame replacement URL, verify that
101+
// the page that was blacklisted is still blacklisted, and if not,
102+
// redirect to the previously blacklisted page.
103+
104+
function onBeforeChromeExtensionRequestHandler(details) {
105+
var requestURL = details.url;
106+
107+
// Is it me?
108+
if ( requestURL.indexOf(chrome.runtime.id) < 0 ) {
109+
return;
110+
}
111+
112+
// Is it a top frame?
113+
if ( details.parentFrameId >= 0 ) {
114+
return;
115+
}
116+
117+
// Is it the noop css file?
118+
var httpsb = HTTPSB;
119+
if ( requestURL.indexOf(httpsb.noopCSSURL) !== 0 ) {
120+
return;
121+
}
122+
123+
// rhill 2013-12-10: Avoid regex whenever a faster indexOf() can be used:
124+
// here we can use fast indexOf() as a first filter -- which is executed
125+
// for every single request (so speed matters).
126+
var matches = requestURL.match(/url=([^&]+)&hostname=([^&]+)/);
127+
if ( !matches ) {
128+
return;
129+
}
130+
131+
// Is the target page still blacklisted?
132+
var pageURL = decodeURIComponent(matches[1]);
133+
var hostname = decodeURIComponent(matches[2]);
134+
if ( httpsb.blacklisted(pageURL, 'main_frame', hostname) ) {
135+
return;
136+
}
137+
138+
// Reload to cancel jailing
139+
chrome.runtime.sendMessage({
140+
what: 'gotoURL',
141+
tabId: details.tabId,
142+
url: pageURL
143+
});
144+
}
145+
146+
/******************************************************************************/
147+
100148
// Intercept and filter web requests according to white and black lists.
101149

102150
function onBeforeRequestHandler(details) {
@@ -111,8 +159,16 @@ function onBeforeRequestHandler(details) {
111159

112160
// quickProfiler.start();
113161

114-
var canEvaluate = true;
115162
var httpsb = HTTPSB;
163+
164+
// Don't block chrome extensions
165+
if ( requestURL.indexOf(httpsb.chromeExtensionURLPrefix) === 0 ) {
166+
onBeforeChromeExtensionRequestHandler(details);
167+
// quickProfiler.stop('onBeforeRequestHandler');
168+
return;
169+
}
170+
171+
var canEvaluate = true;
116172
var tabId = details.tabId;
117173

118174
// Do not ignore traffic outside tabs
@@ -121,35 +177,6 @@ function onBeforeRequestHandler(details) {
121177
// console.debug('onBeforeRequestHandler()> behind-the-scene: "%s"', details.url);
122178
}
123179

124-
var hostname, pageURL;
125-
126-
// Don't block chrome extensions
127-
// rhill 2013-12-10: Avoid regex whenever a faster indexOf() can be used:
128-
// here we can use fast indexOf() as a first filter -- which is executed
129-
// for every single request (so speed matters).
130-
if ( requestURL.indexOf(httpsb.chromeExtensionURLPrefix) === 0 ) {
131-
// If it is HTTP Switchboard's root frame replacement URL, verify that
132-
// the page that was blacklisted is still blacklisted, and if not,
133-
// redirect to the previously blacklisted page.
134-
if ( details.parentFrameId < 0 && requestURL.indexOf(httpsb.noopCSSURL) === 0 ) {
135-
var matches = requestURL.match(/url=([^&]+)&hostname=([^&]+)/);
136-
if ( matches ) {
137-
pageURL = decodeURIComponent(matches[1]);
138-
hostname = decodeURIComponent(matches[2]);
139-
if ( httpsb.whitelisted(pageURL, 'main_frame', hostname) ) {
140-
chrome.runtime.sendMessage({
141-
what: 'gotoURL',
142-
tabId: tabId,
143-
url: pageURL
144-
});
145-
}
146-
}
147-
}
148-
// Chrome extensions are not processed further
149-
// quickProfiler.stop('onBeforeRequestHandler');
150-
return;
151-
}
152-
153180
// Normalizing will get rid of the fragment part
154181
requestURL = uriTools.normalizeURI(requestURL);
155182

@@ -194,8 +221,9 @@ function onBeforeRequestHandler(details) {
194221
pageStats.ignore = true;
195222
}
196223

197-
hostname = uriTools.hostnameFromURI(requestURL);
198-
pageURL = httpsb.pageUrlFromPageStats(pageStats);
224+
var hostname = uriTools.hostnameFromURI(requestURL);
225+
var pageURL = httpsb.pageUrlFromPageStats(pageStats);
226+
199227

200228
// rhill 2013-12-15:
201229
// Try to transpose generic `other` category into something more

0 commit comments

Comments
 (0)