Skip to content

Commit 67ac5a7

Browse files
committed
addressing the last kink (stylesheet requests) re privacy
1 parent 57fd2d2 commit 67ac5a7

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

js/httpsb.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ HTTPSB.evaluate = function(src, type, hostname) {
136136
if ( this.off ) {
137137
return 'gpt';
138138
}
139-
// rhill 2013-12-07:
140-
// stylesheets are evaluated as `main_frame`.
141-
if ( type === 'stylesheet' ) {
142-
type = 'main_frame';
143-
}
144139
return this.temporaryScopes.evaluate(src, type, hostname);
145140
};
146141

js/tab.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ PageStatsEntry.factory = function(pageUrl) {
281281

282282
PageStatsEntry.prototype.init = function(pageUrl) {
283283
this.pageUrl = pageUrl;
284+
this.pageHostname = uriTools.uri(pageUrl).hostname();
285+
this.pageDomain = uriTools.domainFromHostname(this.pageHostname);
284286
this.requests = PageStatsRequests.factory();
285287
this.domains = {};
286288
this.state = {};
@@ -302,6 +304,8 @@ PageStatsEntry.prototype.dispose = function() {
302304
// sizeable enough chunks (especially requests, through the request URL
303305
// used as a key).
304306
this.pageUrl = '';
307+
this.pageHostname = '';
308+
this.pageDomain = '';
305309
this.domains = {};
306310
this.state = {};
307311

js/traffic.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,10 @@ function beforeRequestHandler(details) {
134134
return;
135135
}
136136

137-
// Don't block stylesheet requests, these are considered has being parts
138-
// of the root frame. If root frame is blocked, stylesheets will never
139-
// be requested.
140-
var type = details.type;
141-
// if ( type === 'stylesheet' ) {
142-
// console.log("HTTPSB > %s @ url=%s", details.type, details.url);
143-
// return;
144-
// }
145-
146137
// quickProfiler.start();
147138

148139
// If it's a top frame, bind to a new page stats store
140+
var type = details.type;
149141
var isMainFrame = type === 'main_frame';
150142
var isRootFrame = isMainFrame && details.parentFrameId < 0;
151143
if ( isRootFrame ) {
@@ -156,11 +148,29 @@ function beforeRequestHandler(details) {
156148
hostname = uriTools.hostnameFromURI(url);
157149
pageURL = pageUrlFromPageStats(pageStats) || '*';
158150

151+
// rhill 2013-12-08:
152+
// Better handling of stylesheet requests: if domain of `stylesheet` object
153+
// is same as domain of `main_frame`, the `stylesheet` is evaluated as if
154+
// it is `main_frame` (permissive), else it is evaluated as `other`,
155+
// i.e. an external resources (restrictive).
156+
// This is for privacy reasons: a whole lot of web sites pull their fonts
157+
// from, say, `fonts.googleapis.com`, thus giving Google log data that one
158+
// specific IP address has been visiting one specific website.
159+
// We don't want that.
160+
var typeToEval = type;
161+
if ( type === 'stylesheet' ) {
162+
if ( uriTools.domainFromHostname(hostname) === pageStats.pageDomain ) {
163+
typeToEval = 'main_frame';
164+
} else {
165+
typeToEval = 'other';
166+
}
167+
}
168+
159169
// Block request?
160170
// https://github.com/gorhill/httpswitchboard/issues/27
161171
var block = false; // By default, don't block behind-the-scene requests
162172
if ( tabId !== httpsb.behindTheSceneTabId || httpsb.userSettings.processBehindTheSceneRequests ) {
163-
block = httpsb.blacklisted(pageURL, type, hostname);
173+
block = httpsb.blacklisted(pageURL, typeToEval, hostname);
164174
}
165175

166176
if ( pageStats ) {
@@ -301,18 +311,18 @@ function headersReceivedHandler(details) {
301311
return;
302312
}
303313

304-
// Ignore traffic outside tabs
314+
// rhill 2013-12-08: ALWAYS evaluate for javascript, do not rely too much
315+
// on the top page to be bound to a tab.
316+
// https://github.com/gorhill/httpswitchboard/issues/75
305317
var tabId = details.tabId;
306-
if ( tabId < 0 ) {
307-
return;
308-
}
309318

310319
// rhill 2013-12-07:
311320
// Apparently in Opera, onBeforeRequest() is triggered while the
312321
// URL is not yet bound to a tab (-1), which caused the code here
313322
// to not be able to lookup the pageStats. So let the code here bind
314323
// the page to a tab if not done yet.
315-
if ( isMainFrame && details.parentFrameId < 0 ) {
324+
// https://github.com/gorhill/httpswitchboard/issues/75
325+
if ( tabId >= 0 && isMainFrame && details.parentFrameId < 0 ) {
316326
bindTabToPageStats(tabId, uriTools.normalizeURI(details.url));
317327
}
318328

@@ -323,6 +333,7 @@ function headersReceivedHandler(details) {
323333
// Worst case scenario, if no pageURL can be found for this
324334
// request, use global scope to evaluate whether it should be blocked
325335
// or allowed.
336+
// https://github.com/gorhill/httpswitchboard/issues/75
326337
var pageURL = pageStats ? pageUrlFromPageStats(pageStats) : '*';
327338
var hostname = uriTools.hostnameFromURI(details.url);
328339

js/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ function PageStatsRequests() {
7272

7373
function PageStatsEntry(pageUrl) {
7474
this.pageUrl = '';
75+
this.pageHostname = '';
76+
this.pageDomain = '';
7577
this.requests = PageStatsRequests.factory();
7678
this.domains = {};
7779
this.state = {};

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "__MSG_extName__",
4-
"version": "0.6.5",
4+
"version": "0.6.6",
55
"description": "__MSG_extShortDesc__",
66
"icons": {
77
"16": "icon_16.png",

0 commit comments

Comments
 (0)