Microsoft has acquired GitHub. Decentraleyes has left GitHub. Welcome to its new home!

To participate, please register, or sign in with an existing GitLab.com, Bitbucket, or GitHub account.

Past contributions on GitHub? Be sure to reclaim your Comments, Issues, and Pull Requests.

Verified Commit 81f60022 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Refactor existing codebase

parent 00998af2
_locales
audit
icons
modules/*
!modules/internal
resources
# Usage: `eslint --config .eslint.yml .`
extends: "eslint:recommended"
env:
browser: true
rules:
indent:
- error
- 4
no-undef: 1 # warn
no-unused-vars: 1
no-console: 1
\ No newline at end of file
{
"env": {
"browser": true,
"es6": true,
"webextensions": true
},
"extends": "eslint:recommended",
"globals": {
"Address": true,
"files": true,
"helpers": true,
"interceptor": true,
"mappings": true,
"requestAnalyzer": true,
"Resource": true,
"resources": true,
"Setting": true,
"stateManager": true,
"WebRequest": true,
"Whitelist": true
},
"overrides": {
"files": [
"core/constants.js",
"core/files.js",
"core/mappings.js",
"core/resources.js"
],
"rules": {
"no-unused-vars": "off"
}
},
"rules": {
"array-bracket-newline": "error",
"array-bracket-spacing": "error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-spacing": "error",
"brace-style": "error",
"camelcase": "error",
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": "error",
"consistent-this": "error",
"curly": "error",
"eol-last": "error",
"eqeqeq": "error",
"func-call-spacing": "error",
"function-paren-newline": "error",
"generator-star-spacing": "error",
"indent": [
"error",
4
],
"key-spacing": "error",
"keyword-spacing": "error",
"linebreak-style": [
"error",
"unix"
],
"new-cap": "error",
"new-parens": "error",
"no-array-constructor": "error",
"no-bitwise": "error",
"no-confusing-arrow": "error",
"no-continue": "error",
"no-duplicate-imports": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-implicit-coercion": "error",
"no-implied-eval": "error",
"no-invalid-this": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": [
"error", {
"max": 1,
"maxEOF": 1,
"maxBOF": 0
}
],
"max-len": [
"error", {
"code": 120
}
],
"no-negated-condition": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-proto": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow-restricted-names": "error",
"no-tabs": "error",
"no-ternary": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-use-before-define": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-void": "error",
"no-warning-comments": "warn",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-spacing": "error",
"object-shorthand": [
"error",
"consistent-as-needed"
],
"operator-assignment": "error",
"operator-linebreak": "error",
"prefer-numeric-literals": "error",
"prefer-promise-reject-errors": "error",
"quote-props": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"quotes": [
"error",
"single"
],
"rest-spread-spacing": "error",
"require-await": "error",
"semi": "error",
"semi-spacing": "error",
"semi-style": "error",
"space-before-blocks": "error",
"space-before-function-paren": "error",
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
"strict": [
"error",
"global"
],
"switch-colon-spacing": "error",
"symbol-description": "error",
"template-curly-spacing": "error",
"template-tag-spacing": "error",
"unicode-bom": "error",
"vars-on-top": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": "error"
}
}
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"array-bracket-newline": "error",
"array-bracket-spacing": "error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-spacing": "error",
"brace-style": "error",
"camelcase": "error",
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": "error",
"consistent-this": "error",
"curly": "error",
"eol-last": "error",
"eqeqeq": "error",
"func-call-spacing": "error",
"function-paren-newline": "error",
"generator-star-spacing": "error",
"indent": [
"error",
4
],
"key-spacing": "error",
"keyword-spacing": "error",
"linebreak-style": [
"error",
"unix"
],
"new-cap": "error",
"new-parens": "error",
"no-array-constructor": "error",
"no-bitwise": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "error",
"no-duplicate-imports": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-implicit-coercion": "error",
"no-implied-eval": "error",
"no-invalid-this": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": [
"error", {
"max": 1,
"maxEOF": 1,
"maxBOF": 0
}
],
"no-negated-condition": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-proto": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow-restricted-names": "error",
"no-tabs": "error",
"no-ternary": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-use-before-define": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-void": "error",
"no-warning-comments": "warn",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-spacing": "error",
"object-shorthand": [
"error",
"consistent-as-needed"
],
"operator-assignment": "error",
"operator-linebreak": "error",
"prefer-numeric-literals": "error",
"prefer-promise-reject-errors": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"quote-props": "error",
"quotes": [
"error",
"single"
],
"require-await": "error",
"rest-spread-spacing": "error",
"semi": "error",
"semi-spacing": "error",
"semi-style": "error",
"space-before-blocks": "error",
"space-before-function-paren": "error",
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
"strict": [
"error",
"global"
],
"switch-colon-spacing": "error",
"symbol-description": "error",
"template-curly-spacing": "error",
"template-tag-spacing": "error",
"unicode-bom": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": "error"
}
}
/* eslint-env node */
/**
* Resource Audit Script
* Belongs to Decentraleyes.
......@@ -38,11 +37,11 @@ var resourceAmount = 0;
* Functions
*/
function _fetchLocalResourcePaths(folderPath) {
function _fetchLocalResourcePaths (folderPath) {
fileSystem.readdirSync(folderPath).forEach(function (resourceName) {
var resourcePath = folderPath + '/' + resourceName;
var resourcePath = `${folderPath}/${resourceName}`;
var resourceStatistics = fileSystem.statSync(resourcePath);
if (resourceStatistics && resourceStatistics.isDirectory()) {
......@@ -56,7 +55,7 @@ function _fetchLocalResourcePaths(folderPath) {
return localResourcePaths;
}
function _getLocalResourceContents(fileLocation, callback) {
function _getLocalResourceContents (fileLocation, callback) {
fileSystem.exists(fileLocation, function (exists) {
......@@ -82,16 +81,16 @@ function _getLocalResourceContents(fileLocation, callback) {
});
}
function _getRemoteResourceContents(remoteResourceRoute, callback) {
function _getRemoteResourceContents (remoteResourceRoute, callback) {
var resourceURL = 'https://ajax.googleapis.com/ajax/libs/' + remoteResourceRoute;
var resourceURL = `https://ajax.googleapis.com/ajax/libs/${remoteResourceRoute}`;
https.get(resourceURL, function (response) {
var resourceContents = '';
response.on('data', function (chunk) {
resourceContents = resourceContents + chunk;
resourceContents += chunk;
});
response.on('end', function () {
......@@ -102,20 +101,20 @@ function _getRemoteResourceContents(remoteResourceRoute, callback) {
} else {
resourceURL = 'https://cdnjs.cloudflare.com/ajax/libs/' + remoteResourceRoute;
resourceURL = `https://cdnjs.cloudflare.com/ajax/libs/${remoteResourceRoute}`;
https.get(resourceURL, function (response) {
resourceContents = '';
response.on('data', function (chunk) {
resourceContents = resourceContents + chunk;
resourceContents += chunk;
});
response.on('end', function () {
if (response.statusCode !== 200) {
throw 'Error: Resource ' + remoteResourceRoute + ' could not be fetched.';
throw `Error: Resource ${remoteResourceRoute} could not be fetched.`;
}
callback(resourceContents, resourceURL);
......@@ -130,7 +129,7 @@ function _getRemoteResourceContents(remoteResourceRoute, callback) {
});
}
function _hashFileContents(fileContents) {
function _hashFileContents (fileContents) {
var hash;
......@@ -143,7 +142,27 @@ function _hashFileContents(fileContents) {
return hash.read();
}
function _compareResources(localResourceContents, remoteResourceContents, URL) {
function _showCompletedMessage () {
console.log();
console.log(' *** FILE INTEGRITY CHECKS COMPLETED');
console.log(` *** ${resourceAmount}/${resourceAmount} RESOURCES WERE ANALYZED`);
console.log();
}
function _incrementComparedResourceAmount () {
comparedResourceAmount++;
if (comparedResourceAmount === resourceAmount) {
setTimeout(function () {
_showCompletedMessage();
}, 500);
}
}
function _compareResources (localResourceContents, remoteResourceContents, URL) {
var hasSourceMappingURL = sourceMappingURL.existsIn(remoteResourceContents);
var sourceMappingNotice = '[ ] REMOTE RESOURCE HAD SOURCE MAPPING URL';
......@@ -156,8 +175,8 @@ function _compareResources(localResourceContents, remoteResourceContents, URL) {
var localResourceHash = _hashFileContents(localResourceContents);
var remoteResourceHash = _hashFileContents(remoteResourceContents);
console.log('RESOURCE HASH (SHA512): ' + localResourceHash);
console.log('RESOURCE HASH (SHA512): ' + remoteResourceHash);
console.log(`RESOURCE HASH (SHA512): ${localResourceHash}`);
console.log(`RESOURCE HASH (SHA512): ${remoteResourceHash}`);
var fileHashesMatch = (localResourceHash === remoteResourceHash);
......@@ -174,26 +193,6 @@ function _compareResources(localResourceContents, remoteResourceContents, URL) {
_incrementComparedResourceAmount();
}
function _showCompletedMessage() {
console.log();
console.log(' *** FILE INTEGRITY CHECKS COMPLETED');
console.log(' *** ' + resourceAmount + '/' + resourceAmount + ' RESOURCES WERE ANALYZED');
console.log();
}
function _incrementComparedResourceAmount() {
comparedResourceAmount++;
if (comparedResourceAmount === resourceAmount) {
setTimeout(function () {
_showCompletedMessage();
}, 500);
}
}
/**
* Initializations
*/
......@@ -205,7 +204,7 @@ resourceAmount = localResourcePaths.length;
* Script
*/
localResourcePaths.forEach(function (resourcePath, index) {
localResourcePaths.forEach(function (resourcePath) {
var resourceRoute = resourcePath.substr(localResourceLocationLength + 1);
resourceRoute = resourceRoute.substring(0, resourceRoute.length - 4);
......
/**
* Global Constants
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2017-10-27
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Constants
*/
const Address = {
'ANY': '*://*/*',
'ANY_PATH': '/*',
'ANY_PROTOCOL': '*://',
'DOMAIN_EXPRESSION': /:\/\/(.[^/]+)(.*)/,
'EXAMPLE': 'example.org',
'HTTP_EXPRESSION': /^http?:\/\//,
'HTTPS': 'https://',
'WWW_PREFIX': 'www.',
'WWW_PREFIX_LENGTH': 4
};
const Resource = {
'MAPPING_EXPRESSION': /\.map$/i,
'VERSION_EXPRESSION': /(?:\d{1,2}\.){1,3}\d{1,2}/,
'VERSION_PLACEHOLDER': '{version}'
};
const Setting = {
'AMOUNT_INJECTED': 'amountInjected',
'BLOCK_MISSING': 'blockMissing',
'DISABLE_PREFETCH': 'disablePrefetch',
'SHOW_ICON_BADGE': 'showIconBadge',
'STRIP_METADATA': 'stripMetadata',
'WHITELISTED_DOMAINS': 'whitelistedDomains'
};
const WebRequest = {
'GET': 'GET',
'BLOCKING': 'blocking',
'HEADERS': 'requestHeaders',
'ORIGIN_HEADER': 'Origin',
'REFERER_HEADER': 'Referer'
};
const Whitelist = {
'TRIM_EXPRESSION': /^;+|;+$/g,
'VALUE_SEPARATOR': ';'
};
......@@ -19,12 +19,6 @@
var interceptor = {};
/**
* Constants
*/
const HTTP_EXPRESSION = /^http?:\/\//;
/**
* Public Methods
*/
......@@ -43,24 +37,28 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
}
try {
tabDomain = tab.url.match(WEB_DOMAIN_EXPRESSION)[1];
tabDomain = tab.url.match(Address.DOMAIN_EXPRESSION)[1];
tabDomain = requestAnalyzer._normalizeDomain(tabDomain);
} catch (exception) {
tabDomain = 'example.org';
tabDomain = Address.EXAMPLE;
}
// Temporary list of undetectable tainted domains.
let undetectableTaintedDomains = {
'cdnjs.com': true,
'dropbox.com': true,
'glowing-bear.org': true,
'jadi.sk': true,
'minigames.mail.ru': true,
'report-uri.io': true,
'scotthelme.co.uk': true,
'securityheaders.io': true,
'stefansundin.github.io': true,
'udacity.com': true
'udacity.com': true,
'yourvotematters.co.uk': true
};
if (undetectableTaintedDomains[tabDomain] || /yandex\./.test(tabDomain)) {
if (undetectableTaintedDomains[tabDomain] || (/yandex\./).test(tabDomain)) {
if (tabDomain !== 'yandex.ru') {
return interceptor._handleMissingCandidate(requestDetails.url);
......@@ -79,8 +77,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
}
stateManager.requests[requestDetails.requestId] = {
'tabIdentifier': tabIdentifier,
'targetDetails': targetDetails
tabIdentifier, targetDetails
};
return {
......@@ -101,12 +98,12 @@ interceptor._handleMissingCandidate = function (requestUrl) {
};
}
if (requestUrl.match(HTTP_EXPRESSION)) {
if (requestUrl.match(Address.HTTP_EXPRESSION)) {
requestUrl = requestUrl.replace(HTTP_EXPRESSION, 'https://');
let secureRequestUrl = requestUrl.replace(Address.HTTP_EXPRESSION, Address.HTTPS);
return {
'redirectUrl': requestUrl
'redirectUrl': secureRequestUrl
};
} else {
......@@ -119,7 +116,7 @@ interceptor._handleMissingCandidate = function (requestUrl) {
interceptor._handleStorageChanged = function (changes) {
if ('blockMissing' in changes) {
if (Setting.BLOCK_MISSING in changes) {
interceptor.blockMissing = changes.blockMissing.newValue;
}
};
......@@ -131,7 +128,7 @@ interceptor._handleStorageChanged = function (changes) {
interceptor.amountInjected = 0;
interceptor.blockMissing = false;
chrome.storage.local.get(['amountInjected', 'blockMissing'], function (items) {
chrome.storage.local.get([Setting.AMOUNT_INJECTED, Setting.BLOCK_MISSING], function (items) {
interceptor.amountInjected = items.amountInjected || 0;
interceptor.blockMissing = items.blockMissing || false;
......
......@@ -54,7 +54,8 @@ main._showReleaseNotes = function (details) {
let location = chrome.extension.getURL('pages/welcome/welcome.html');
if (details.reason === 'install' || details.reason === 'update') {
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL ||
details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
if (details.temporary !== true) {
......
......@@ -37,40 +37,40 @@ var mappings = {
// Common Shorthand Notations [Deprecated]
'dojo/1/dojo/dojo.': {
path: 'resources/dojo/1.6.1/dojo/dojo.js.dec',
type: 'application/javascript'
'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec',
'type': 'application/javascript'
},
'jquery/1/jquery.': {