Skip to content
Snippets Groups Projects
Commit 7d8eee86 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Refactor domain tainting code

parent d0277c03
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,12 @@ var { Cc, Ci, Cr } = require('chrome');
*/
var simplePreferences = require('sdk/simple-prefs');
/**
* Retains data across Firefox restarts.
* @var {object} simpleStorage
*/
var simpleStorage = require('sdk/simple-storage');
//noinspection JSUnresolvedFunction
var observerService = Cc['@mozilla.org/observer-service;1']
.getService(Ci.nsIObserverService);
......@@ -34,30 +40,12 @@ var observerService = Cc['@mozilla.org/observer-service;1']
var requestAnalyzer = require('./request-analyzer');
var dataHandler = require('./data-handler');
/**
* Constants
*/
const VALUE_SEPARATOR = ';';
/**
* Variables
*/
var preferences = require('sdk/simple-prefs').prefs;
var taintedDomains = {};
/**
* Initializations
*/
_applyTaintPreference();
/**
* Event Handlers
*/
simplePreferences.on('taintedDomainList', _applyTaintPreference);
var preferences = simplePreferences.prefs;
var storage = simpleStorage.storage;
/**
* Interceptor Class
......@@ -119,7 +107,7 @@ var Interceptor = new Class({
httpChannel.loadInfo && httpChannel.loadInfo.loadingDocument && httpChannel.loadInfo.loadingDocument.domain ||
httpChannel.referrer && httpChannel.referrer.host;
if (taintedDomains[initiatorDomain] === true) {
if (storage.taintedDomains[initiatorDomain]) {
return this.handleMissingCandidate(httpChannel);
}
......@@ -143,20 +131,6 @@ var Interceptor = new Class({
}
});
/**
* Private Methods
*/
function _applyTaintPreference() {
taintedDomains = {};
//noinspection JSUnresolvedVariable
preferences.taintedDomainList.split(VALUE_SEPARATOR).forEach(function (domain) {
taintedDomains[domain] = true;
});
}
/**
* Exports
*/
......
......@@ -30,10 +30,10 @@ var xpcom = require('sdk/platform/xpcom');
var mappings = require('./mappings');
/**
* Gets and sets add-on specific preferences.
* @var {object} simplePreferences
* Retains data across Firefox restarts.
* @var {object} simpleStorage
*/
var simplePreferences = require('sdk/simple-prefs');
var simpleStorage = require('sdk/simple-storage');
//noinspection JSUnresolvedFunction
var categoryManager = Cc['@mozilla.org/categorymanager;1']
......@@ -45,24 +45,21 @@ var categoryManager = Cc['@mozilla.org/categorymanager;1']
const CONTRACT_ID = '@decentraleyes.org/load-watcher;1';
const SCRIPT_CONTENT_TYPE = Ci.nsIContentPolicy.TYPE_SCRIPT;
const SCRIPT_ELEMENT = Ci.nsIDOMHTMLScriptElement;
const HTML_DOCUMENT = Ci.nsIDOMHTMLDocument;
const VALUE_SEPARATOR = ';';
const SCRIPT_ELEMENT = Ci.nsIDOMHTMLScriptElement;
const REQUEST_ACCEPTATION = Ci.nsIContentPolicy.ACCEPT;
/**
* Variables
*/
var preferences = simplePreferences.prefs;
var taintedDomains = {};
var storage = simpleStorage.storage;
/**
* Initializations
*/
_applyTaintPreference();
storage.taintedDomains = storage.taintedDomains || {};
/**
* Load Watcher Class
......@@ -76,7 +73,7 @@ var LoadWatcher = new Class({
register: function () {
categoryManager.deleteCategoryEntry('content-policy', '@decentraleyes.org/load-watcher;1', false);
categoryManager.deleteCategoryEntry('content-policy', CONTRACT_ID, false);
categoryManager.addCategoryEntry('content-policy', CONTRACT_ID, CONTRACT_ID, false, true);
},
......@@ -89,30 +86,24 @@ var LoadWatcher = new Class({
if (node.hasAttribute('crossorigin') || node.hasAttribute('integrity')) {
// Add corresponding origin domain to the list of tainted domains.
this.saveTaintedDomain(requestOrigin.host);
storage.taintedDomains[requestOrigin.host] = true;
}
} else if (node instanceof HTML_DOCUMENT) {
if (node.defaultView && node.defaultView.frameElement && node.defaultView.frameElement.tagName === 'IFRAME') {
if (node.defaultView && node.defaultView.frameElement) {
// Add corresponding origin domain to the list of tainted domains.
this.saveTaintedDomain(requestOrigin.host);
if (node.defaultView.frameElement.tagName === 'IFRAME') {
// Add corresponding origin domain to the list of tainted domains.
storage.taintedDomains[requestOrigin.host] = true;
}
}
}
}
// Accept the resource load request.
return Ci.nsIContentPolicy.ACCEPT;
},
saveTaintedDomain: function (taintedDomain) {
if (taintedDomains[taintedDomain] !== true) {
taintedDomains[taintedDomain] = true;
preferences.taintedDomainList = Object.keys(taintedDomains).join(VALUE_SEPARATOR);
}
return REQUEST_ACCEPTATION;
}
});
......@@ -154,20 +145,6 @@ unload.when(function () {
}
});
/**
* Private Methods
*/
function _applyTaintPreference() {
taintedDomains = {};
//noinspection JSUnresolvedVariable
preferences.taintedDomainList.split(VALUE_SEPARATOR).forEach(function (domain) {
taintedDomains[domain] = true;
});
}
/**
* Exports
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment