diff options
Diffstat (limited to 'data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker')
9 files changed, 801 insertions, 728 deletions
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js index 1a3b2a9..a2da0da 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js @@ -2,20 +2,22 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ //var debug = require("debug/debug"); @@ -140,49 +142,49 @@ var checkTypes = { exports.checkTypes = checkTypes; -exports.emptyTypeObj = function () { +exports.emptyTypeObj = function() { return { 'type': null, 'reason': null }; }; -exports.nontrivialWithComment = function (comment) { +exports.nontrivialWithComment = function(comment) { return { 'type': checkTypes.NONTRIVIAL, 'reason': comment }; }; -exports.trivialWithComment = function (comment) { +exports.trivialWithComment = function(comment) { return { 'type': checkTypes.TRIVIAL, 'reason': comment }; }; -exports.trivialFuncWithComment = function (comment) { +exports.trivialFuncWithComment = function(comment) { return { 'type': checkTypes.TRIVIAL_DEFINES_FUNCTION, 'reason': comment }; }; -exports.freeWithComment = function (comment) { +exports.freeWithComment = function(comment) { return { 'type': checkTypes.FREE, 'reason': comment }; }; -exports.singleFreeWithComment = function (comment) { +exports.singleFreeWithComment = function(comment) { return { 'type': checkTypes.FREE_SINGLE_ITEM, 'reason': comment }; }; -exports.whitelisted = function (comment) { +exports.whitelisted = function(comment) { return { 'type': checkTypes.WHITELISTED, 'reason': comment + ' -- whitelisted by user' diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js index f5690f2..71a262e 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js @@ -2,24 +2,24 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ - - var licenses = require('js_checker/license_definitions'); var simpleStorage = require("sdk/simple-storage"); const LAZY = licenses.types.LAZY; @@ -35,193 +35,199 @@ var licStartLicEndRe = /@licstartThefollowingistheentirelicensenoticefortheJavaS var licenseMagnet = /.*@license ?(magnet\:\?xt=urn\:btih\:[0-9A-Za-z]+).*/; var licenseEndMagnet = /.*@license-end.*/i; exports.freeCheck = { - initLicenses: function (licenses) { - for (var item in licenses) { - this.stripLicenseToRegexp(licenses[item]); - } - }, - - /** - * stripLicenseToRegexp - * - * Removes all non-alphanumeric characters except for the - * special tokens, and replace the text values that are - * hardcoded in license_definitions.js - * - */ - stripLicenseToRegexp: function (license) { - var i = 0, - max = license.licenseFragments.length, - item; - - for (; i < max; i++) { - item = license.licenseFragments[i]; - item.regex = patternUtils.removeNonalpha(item.text); - - if (license.licenseFragments[i].type === LAZY) { - - // do not permit words before. Since "Not" could be added - // and make it nonfree. e.g.: Not licensed under the GPLv3. - item.regex = '^(?!.*not).*' + item.regex; - - } - - item.regex = new RegExp(patternUtils.replaceTokens(item.regex), 'i'); - } - - return license; - }, - - /** - * checkNodeFreeLicense - * - * Check if the node mentions a free license - * in one of its comments. - * - */ - checkNodeFreeLicense: function (n, queue) { - var strippedComment, - magnetLink, - comment = this.getComment(n), - list = licenses.licenses, - i, j, - max, - regex, - frag, - matchLicStart, - matchMagnet, - license, - isMagnetValid = false; - - if (n.counter === 2 && - n.parent != undefined && - n.parent.type === token.SCRIPT && - comment != undefined && - comment != " ") { - strippedComment = patternUtils.removeNonalpha(comment); - matchLicStart = strippedComment.match(licStartLicEndRe); - console.debug("matchMagnet is", matchMagnet); - if (matchLicStart) { - strippedComment = matchLicStart[1]; - for (license in list) { - frag = list[license].licenseFragments; - max = list[license].licenseFragments.length; - for (i = 0;i < max; i++) { - if (frag[i].regex.test(strippedComment)) { - return {licenseName: list[license].licenseName, - type: types.checkTypes.FREE} ; - - } - } - } - } - return this.matchMagnet(comment, queue); /// check for @license -- @license-end notation. - } - - }, - - /** - * matchMagnet - * Attempts to find valid @license [magnet] - * and @license-end notation. - */ - matchMagnet: function (comment, queue) { - let matchMagnet = comment.match(licenseMagnet); - if (matchMagnet) { - let magnetLinkRe = new RegExp(matchMagnet[1].replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); - let list = licenses.licenses; - let queue_end = queue.length; - - for (var license in list) { - frag = list[license].canonicalUrl; - console.debug("frag is ", frag); - if (frag != undefined) { - max = list[license].canonicalUrl.length; - console.debug("max is", max); - for (i = 0;i < max; i++) { - console.debug("current frag is", frag[i]); - if (frag[i].match(magnetLinkRe)) { - for (let i = 0; i < queue_end; i++) { - console.debug(queue[i]); - let n = queue[i]; - comment = this.getComment(n); - if (comment != undefined && - comment.match(licenseEndMagnet) && - this.checkIsLastNode(n)) { - // found a closing match. Just accept this script. - return {licenseName: list[license].licenseName, - type: types.checkTypes.FREE_SINGLE_ITEM}; + initLicenses: function (licenses) { + for (var item in licenses) { + this.stripLicenseToRegexp(licenses[item]); + } + }, + + /** + * stripLicenseToRegexp + * + * Removes all non-alphanumeric characters except for the + * special tokens, and replace the text values that are + * hardcoded in license_definitions.js + * + */ + stripLicenseToRegexp: function (license) { + var i = 0, + max = license.licenseFragments.length, + item; + + for (; i < max; i++) { + item = license.licenseFragments[i]; + item.regex = patternUtils.removeNonalpha(item.text); + + if (license.licenseFragments[i].type === LAZY) { + + // do not permit words before. Since "Not" could be added + // and make it nonfree. e.g.: Not licensed under the GPLv3. + item.regex = '^(?!.*not).*' + item.regex; + + } + + item.regex = new RegExp( + patternUtils.replaceTokens(item.regex), 'i'); + } + + return license; + }, + + /** + * checkNodeFreeLicense + * + * Check if the node mentions a free license + * in one of its comments. + * + */ + checkNodeFreeLicense: function (n, queue) { + var strippedComment, + magnetLink, + comment = this.getComment(n), + list = licenses.licenses, + i, j, + max, + regex, + frag, + matchLicStart, + matchMagnet, + license, + isMagnetValid = false; + + if (n.counter === 2 && + n.parent != undefined && + n.parent.type === token.SCRIPT && + comment != undefined && + comment != " " + ) { + strippedComment = patternUtils.removeNonalpha(comment); + matchLicStart = strippedComment.match(licStartLicEndRe); + console.debug("matchMagnet is", matchMagnet); + if (matchLicStart) { + strippedComment = matchLicStart[1]; + for (license in list) { + frag = list[license].licenseFragments; + max = list[license].licenseFragments.length; + for (i = 0; i < max; i++) { + if (frag[i].regex.test(strippedComment)) { + return { + licenseName: list[license].licenseName, + type: types.checkTypes.FREE + }; + + } + } + } + } + // check for @license -- @license-end notation. + return this.matchMagnet(comment, queue); + } + }, + + /** + * matchMagnet + * Attempts to find valid @license [magnet] + * and @license-end notation. + */ + matchMagnet: function (comment, queue) { + let matchMagnet = comment.match(licenseMagnet); + if (matchMagnet) { + let magnetLinkRe = new RegExp( + matchMagnet[1].replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + ); + let list = licenses.licenses; + let queue_end = queue.length; + + for (var license in list) { + frag = list[license].canonicalUrl; + console.debug("frag is ", frag); + if (frag != undefined) { + max = list[license].canonicalUrl.length; + console.debug("max is", max); + for (i = 0;i < max; i++) { + console.debug("current frag is", frag[i]); + if (frag[i].match(magnetLinkRe)) { + for (let i = 0; i < queue_end; i++) { + console.debug(queue[i]); + let n = queue[i]; + comment = this.getComment(n); + if (comment != undefined && + comment.match(licenseEndMagnet) && + this.checkIsLastNode(n) + ) { + // found a closing match. Just accept this script. + return { + licenseName: list[license].licenseName, + type: types.checkTypes.FREE_SINGLE_ITEM + }; + } + } + } + } } - } } - } - } - } - } - return; - }, - - /** - * checkIsLastJsNode. - * returns true if n is the last node. - * Or if nodes before it are only comments etc (not valid code.) - * A special LibreJS node is appended at the end of a script tree to - * check if this is the last (and also for narcissus to keep the last comment - * in the tree.) - * TODO: Refactor LibreJS so that END nodes can have a comment. - */ - checkIsLastNode: function (n) { - // first check if the comment is part of the very last statement. - if (n.value == "this" && n.next == undefined) { - // just make sure the last node is indeed our harmless bit of - // js. - if (n.tokenizer) { - let source = n.tokenizer.source; - let substring = source.substr(n.start, n.end+23); - if (substring == END_OF_SCRIPT) { - return true; } - else { - console.debug("substring is ", substring); - return false; + return; + }, + + /** + * checkIsLastJsNode. + * returns true if n is the last node. + * Or if nodes before it are only comments etc (not valid code.) + * A special LibreJS node is appended at the end of a script tree to + * check if this is the last (and also for narcissus to keep the last comment + * in the tree.) + * TODO: Refactor LibreJS so that END nodes can have a comment. + */ + checkIsLastNode: function (n) { + // first check if the comment is part of the very last statement. + if (n.value == "this" && n.next == undefined) { + // just make sure the last node is indeed our harmless bit of + // js. + if (n.tokenizer) { + let source = n.tokenizer.source; + let substring = source.substr(n.start, n.end+23); + if (substring == END_OF_SCRIPT) { + return true; + } + else { + console.debug("substring is ", substring); + return false; + } + } + console.debug("Hurra! This is the end of our script"); + return true; } - } - console.debug("Hurra! This is the end of our script"); - return true; - } - // isn't our last node. - return false; - }, - - /** - * getComment - * - * Grab the comment(s) from the node. Concatenates - * multiple comments. - * - */ - getComment: function (n) { - - var i = 0, length, comment = ""; - - if (n.blockComments == undefined || n.blockComments == " ") { - return; - } - - length = n.blockComments.length; - if (length > 0) { - for (; i < length; i++) { - comment += n.blockComments[i]; - } - } - if (comment == "") { - return; - } - return comment; - - } - + // isn't our last node. + return false; + }, + + /** + * getComment + * + * Grab the comment(s) from the node. Concatenates + * multiple comments. + * + */ + getComment: function (n) { + var i = 0, length, comment = ""; + + if (n.blockComments == undefined || n.blockComments == " ") { + return; + } + + length = n.blockComments.length; + if (length > 0) { + for (; i < length; i++) { + comment += n.blockComments[i]; + } + } + if (comment == "") { + return; + } + return comment; + } }; exports.freeCheck.initLicenses(licenses.licenses); diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js index a96eea7..3b03084 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js @@ -2,25 +2,28 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ var {Cc, Ci, Cu, Cm, Cr} = require("chrome"); -const narcissusWorker = require("narcissus_parser/narcissus_worker"); +var narcissusWorker = require("parser/narcissus_worker") + .narcissusWorker; const nonTrivialModule = require("js_checker/nontrivial_checker"); const freeChecker = require("js_checker/free_checker"); @@ -40,33 +43,25 @@ const timer = require("sdk/timers"); var callbackMap = {}; /** - * This module needs to be updated so that it is asynchronous - * and to reduce CPU usage -- - * - * Partly already done in: - * https://gitorious.org/librejs/librejs/blobs/async/lib/js_checker/js_checker.js - * data/complain/contact_finder.js on how to proceed. - * - */ -/** * * Pairs a hash with a given callback * method from an object. * */ var setHashCallback = function(hash, callback, notification) { - console.debug("hash is now ", hash); + console.debug('setHashCallback', hash); if (hash in callbackMap && isDryRun()) { - // work around for issue with dryrun after - // checking box. + // workaround for issue with dryrun after checking box. // do nothing. callbackMap[hash] = callback; - } - else if (hash in callbackMap) { - // console.debug("callback", callbackMap[hash]); - notification.close(); + } else if (hash in callbackMap) { + console.debug("callback", callbackMap[hash]); + if (notification && typeof notification.close === 'function') { + notification.close(); + } throw Error("already being checked."); } else { + console.debug('setting callbackMap for', hash, 'to', callback); callbackMap[hash] = callback; } console.debug("callback is type: ", callback.constructor); @@ -84,19 +79,22 @@ var removeHashCallback = function(hash) { * */ exports.callbackHashResult = function(hash, result) { + console.debug('typeof callbackMap function:', typeof callbackMap[hash]); + console.debug('for hash', hash); try { callbackMap[hash](result, hash); } catch (x) { console.debug('error in jsChecker', x, 'hash:', hash); // return tree as false. console.debug("Error with", x); - if (typeof callbackMap[hash] == 'function') { + if (typeof callbackMap[hash] === 'function') { callbackMap[hash](false, hash); } else { console.debug('callbackHashResult Error', x); } } // remove callback after it's been called. + console.debug('JsChecker.callbackHashResult: calling removeHashCallback'); removeHashCallback(hash); }; @@ -127,6 +125,7 @@ var JsChecker = function() { JsChecker.prototype.searchJs = function(jsCode, resultReady, url) { var that = this; var bugfix = require('html_script_finder/bug_fix').narcissusBugFixLibreJS; + console.debug('JsChecker.searchJs for script url:', url); this.url = url; this.resultReady = resultReady; this.jsCode = jsCode; @@ -141,7 +140,8 @@ JsChecker.prototype.searchJs = function(jsCode, resultReady, url) { console.debug("We have it cached indeed!"); // there is an existing entry for this exact copy // of script text. - console.debug('this script result is cached', this.hash, isCached.result.type); + console.debug('this script result is cached', this.hash, + isCached.result.type); console.debug("Return right away"); // we are not generating a parse tree. this.parseTree = {}; @@ -155,21 +155,27 @@ JsChecker.prototype.searchJs = function(jsCode, resultReady, url) { return; } + console.debug('url is not cached:', url); + try { // no cache, continue. this.relationChecker = relationChecker.relationChecker(); this.freeToken = types.emptyTypeObj(); this.nontrivialness = types.emptyTypeObj(); - // use this.hash to keep track of comments made by the nontrivial checker code - // about why/how the code is found to be nontrivial. - this.nonTrivialChecker = nonTrivialModule.nonTrivialChecker(this.hash); + // use this.hash to keep track of comments made by the nontrivial + // checker code about why/how the code is found to be nontrivial. + this.nonTrivialChecker = + nonTrivialModule.nonTrivialChecker(this.hash); // register callback and hash. So that result // can be passed. - setHashCallback(this.hash, this.handleTree.bind(this), this.notification); + setHashCallback( + this.hash, this.handleTree.bind(this), this.notification); // parse using ChromeWorker. + console.debug( + 'JsChecker.searchJs(): starting narcissusWorker.parse()'); narcissusWorker.parse(this.jsCode, this.hash); } catch (x) { console.debug('error', x); @@ -185,7 +191,7 @@ JsChecker.prototype.handleTree = function(tree, errorMessage) { // error parsing tree. Just return nonfree nontrivial. this.parseTree = {}; this.parseTree.freeTrivialCheck = types.nontrivialWithComment( - 'error parsing: ' + errorMessage); + 'error parsing: ' + errorMessage); // cache result with hash of script for future checks. scriptsCached.addEntry(this.jsCode, this.parseTree.freeTrivialCheck, @@ -195,7 +201,7 @@ JsChecker.prototype.handleTree = function(tree, errorMessage) { try { // no need to keep parseTree in property this.parseTree = {}; //tree; - console.debug(tree); + //console.debug(tree); this.walkTree(tree); } catch (x) { console.debug(x, x.lineNumber, x.fileName); @@ -304,20 +310,21 @@ JsChecker.prototype.walkTree = function(node) { len = n.children.length; for (i = 0; i < len; i++) { if (n.children[i] != undefined && - n.children[i].visited == undefined) { - // figure out siblings. - if (i > 0) { - n.children[i].previous = n.children[i-1]; - } - - if (i < len) { - n.children[i].next = n.children[i+1]; - } - // set parent property. - n.children[i].parent = n; - n.children[i].visited = true; - queue.push(n.children[i]); - } + n.children[i].visited == undefined + ) { + // figure out siblings. + if (i > 0) { + n.children[i].previous = n.children[i-1]; + } + + if (i < len) { + n.children[i].next = n.children[i+1]; + } + // set parent property. + n.children[i].parent = n; + n.children[i].visited = true; + queue.push(n.children[i]); + } } } @@ -330,24 +337,25 @@ JsChecker.prototype.walkTree = function(node) { n[item] != null && typeof n[item] === 'object' && n[item].type != undefined && - n[item].visited == undefined) { - n[item].visited = true; - // set parent property - n[item].parent = n; - queue.push(n[item]); - } + n[item].visited == undefined + ) { + n[item].visited = true; + // set parent property + n[item].parent = n; + queue.push(n[item]); + } } } that.checkNode(n); if (that.freeToken.type === checkTypes.FREE || - that.freeToken.type === checkTypes.FREE_SINGLE_ITEM) { - // nothing more to look for. We are done. - that.walkTreeComplete(that.freeToken); - return; - } - else if (that.nontrivialness.type === checkTypes.NONTRIVIAL) { + that.freeToken.type === checkTypes.FREE_SINGLE_ITEM + ) { + // nothing more to look for. We are done. + that.walkTreeComplete(that.freeToken); + return; + } else if (that.nontrivialness.type === checkTypes.NONTRIVIAL) { // nontrivial // we are done. that.walkTreeComplete(that.nontrivialness); @@ -473,8 +481,7 @@ JsChecker.prototype.checkNode = function(n) { "Script appears to be free under the following license: " + fc.licenseName); return; - } - else if (fc && fc.type == checkTypes.FREE_SINGLE_ITEM) { + } else if (fc && fc.type == checkTypes.FREE_SINGLE_ITEM) { console.debug("free single item"); this.freeToken = types.singleFreeWithComment( "Script appears to be free under the following license: " + @@ -487,9 +494,7 @@ JsChecker.prototype.checkNode = function(n) { // nontrivial_global is deprecated this.nontrivialness = tc; return; - } - - else if (tc.type === checkTypes.TRIVIAL_DEFINES_FUNCTION) { + } else if (tc.type === checkTypes.TRIVIAL_DEFINES_FUNCTION) { this.nontrivialness = tc; return; } @@ -497,15 +502,17 @@ JsChecker.prototype.checkNode = function(n) { }; JsChecker.prototype.removeNotification = function() { - if (this.notification && this.notification.close) { - console.debug("removing", this.shortText); + console.debug('JsChecker.removeNotification()'); + if (this.notification && + typeof this.notification.close === 'function' + ) { + console.debug('removing', this.shortText); // remove notification early on. this.notification.close(); this.notification = null; } }; -// create an instance of JsChecker exports.jsChecker = function() { return new JsChecker(); }; diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js index 36711fd..41cfb7b 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js @@ -2,20 +2,22 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ exports.types = { SHORT: 'short', @@ -32,8 +34,10 @@ var type = exports.types; exports.licenses = { CC0: { licenseName: 'Creative Commons CC0 1.0 Universal', - canonicalUrl: ['http://creativecommons.org/publicdomain/zero/1.0/legalcode', - 'magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt'], + canonicalUrl: [ + 'http://creativecommons.org/publicdomain/zero/1.0/legalcode', + 'magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt' + ], identifier: 'CC0-1.0', licenseFragments: [] }, @@ -41,8 +45,10 @@ exports.licenses = { gplv2: { licenseName: 'GNU General Public License (GPL) version 2', - canonicalUrl: ['http://www.gnu.org/licenses/gpl-2.0.html', - 'magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt'], + canonicalUrl: [ + 'http://www.gnu.org/licenses/gpl-2.0.html', + 'magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt' + ], identifier: 'GNU-GPL-2.0', licenseFragments: [{text: "<THISPROGRAM> is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.", type: type.SHORT}, {text:"Alternatively, the contents of this file may be used under the terms of either the GNU General Public License Version 2 or later (the \"GPL\"), or the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL.", type: type.SHORT}] @@ -50,8 +56,10 @@ exports.licenses = { gplv3: { licenseName: 'GNU General Public License (GPL) version 3', - canonicalUrl: ['http://www.gnu.org/licenses/gpl-3.0.html', - 'magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt'], + canonicalUrl: [ + 'http://www.gnu.org/licenses/gpl-3.0.html', + 'magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt' + ], identifier: 'GNU-GPL-3.0', licenseFragments: [ {text: "The JavaScript code in this page is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License (GNU GPL) as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The code is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. As additional permission under GNU GPL version 3 section 7, you may distribute non-source (e.g., minimized or compacted) forms of that code without the copy of the GNU GPL normally required by section 4, provided you include this license notice and a URL through which recipients can access the Corresponding Source.", type: type.SHORT}, @@ -65,94 +73,137 @@ exports.licenses = { apache_2License: { licenseName: 'Apache License, Version 2.0', - canonicalUrl: ['http://www.apache.org/licenses/LICENSE-2.0', - 'magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt'], + canonicalUrl: [ + 'http://www.apache.org/licenses/LICENSE-2.0', + 'magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt' + ], identifier: 'Apache-2.0', licenseFragments: [{text: "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0", type: type.SHORT}] }, lgpl21: { licenseName: 'GNU Lesser General Public License, version 2.1', - canonicalUrl: ['http://www.gnu.org/licenses/lgpl-2.1.html', - 'magnet:?xt=urn:btih:5de60da917303dbfad4f93fb1b985ced5a89eac2&dn=lgpl-2.1.txt'], + canonicalUrl: [ + 'http://www.gnu.org/licenses/lgpl-2.1.html', + 'magnet:?xt=urn:btih:5de60da917303dbfad4f93fb1b985ced5a89eac2&dn=lgpl-2.1.txt' + ], identifier: 'GNU-LGPL-2.1', licenseFragments: [{text: "<THISLIBRARY> is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.", type: type.SHORT}] }, lgplv3: { licenseName: 'GNU Lesser General Public License, version 3', - canonicalUrl: ['http://www.gnu.org/licenses/lgpl-3.0.html', - 'magnet:?xt=urn:btih:0ef1b8170b3b615170ff270def6427c317705f85&dn=lgpl-3.0.txt'], + canonicalUrl: [ + 'http://www.gnu.org/licenses/lgpl-3.0.html', + 'magnet:?xt=urn:btih:0ef1b8170b3b615170ff270def6427c317705f85&dn=lgpl-3.0.txt' + ], identifier: 'GNU-LGPL-3.0', licenseFragments: [{text: "<THISPROGRAM> is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.", type: type.SHORT}] }, agplv3: { licenseName: 'GNU AFFERO GENERAL PUBLIC LICENSE version 3', - canonicalUrl: ['http://www.gnu.org/licenses/agpl-3.0.html', - 'magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt'], + canonicalUrl: [ + 'http://www.gnu.org/licenses/agpl-3.0.html', + 'magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt' + ], identifier: 'GNU-AGPL-3.0', licenseFragments: [{text: "<THISPROGRAM> is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.", type: type.SHORT}] }, boostSoftware: { licenseName: 'Boost Software License', - canonicalUrl: ["magnet:?xt=urn:btih:89a97c535628232f2f3888c2b7b8ffd4c078cec0&dn=Boost-1.0.txt"], + canonicalUrl: [ + 'http://www.boost.org/LICENSE_1_0.txt', + 'magnet:?xt=urn:btih:89a97c535628232f2f3888c2b7b8ffd4c078cec0&dn=Boost-1.0.txt' + ], licenseFragments: [{text: "Boost Software License <VERSION> <DATE> Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the \"Software\") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following", type: type.SHORT}] }, bsd3: { - licenseName: "The BSD 3-Clause License", - canonicalUrl: ["magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt"], + licenseName: "BSD 3-Clause License", + canonicalUrl: [ + 'http://opensource.org/licenses/BSD-3-Clause', + 'magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt' + ], licenseFragments: [{text: "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.", type: type.SHORT}] }, bsd2: { - licenseName: "The BSD 2-Clause License", + licenseName: "BSD 2-Clause License", licenseFragments: [{text: "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.", type: type.SHORT}] }, + epl_1_0: { + licenseName: "Eclipse Public License Version 1.0", + identifier: "EPL-1.0", + canonicalUrl: [ + "http://www.eclipse.org/legal/epl-v10.html", + "magnet:?xt=urn:btih:4c6a2ad0018cd461e9b0fc44e1b340d2c1828b22&dn=epl-1.0.txt" + ], + licenseFragments: [ + { + text: "THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE (\"AGREEMENT\"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.", + type: type.SHORT + } + ] + }, + mozillaPublicLicense_2_0: { licenseName: 'Mozilla Public License Version 2.0', identifier: 'MPL-2.0', - canonicalUrl: ['http://www.mozilla.org/MPL/2.0', - 'magnet:?xt=urn:btih:3877d6d54b3accd4bc32f8a48bf32ebc0901502a&dn=mpl-2.0.txt'], + canonicalUrl: [ + 'http://www.mozilla.org/MPL/2.0', + 'magnet:?xt=urn:btih:3877d6d54b3accd4bc32f8a48bf32ebc0901502a&dn=mpl-2.0.txt' + ], licenseFragments: [{text: "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/.", type: type.SHORT }] }, expat: { licenseName: 'Expat License (sometimes called MIT Licensed)', identifier: 'Expat', - canonicalUrl: ['http://www.jclark.com/xml/copying.txt', - 'magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt'], + canonicalUrl: [ + 'http://www.jclark.com/xml/copying.txt', + 'magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt' + ], licenseFragments: [{text: "Copyright <YEAR> <NAME> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.", type: type.SHORT}] }, X11: { licenseName: 'X11 License', - canonicalUrl: ['magnet:?xt=urn:btih:5305d91886084f776adcf57509a648432709a7c7&dn=x11.txt'], + canonicalUrl: [ + 'magnet:?xt=urn:btih:5305d91886084f776adcf57509a648432709a7c7&dn=x11.txt' + ], licenseFragments: [{text: "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.", type: type.SHORT}] }, XFree86: { licenseName: "XFree86 License", identifier: 'Modified-BSD', - canonicalUrl: ['http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3', 'http://www.xfree86.org/current/LICENSE4.html', 'magnet:?xt=urn:btih:12f2ec9e8de2a3b0002a33d518d6010cc8ab2ae9&dn=xfree86.txt'], + canonicalUrl: [ + 'http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3', + 'http://www.xfree86.org/current/LICENSE4.html', + 'magnet:?xt=urn:btih:12f2ec9e8de2a3b0002a33d518d6010cc8ab2ae9&dn=xfree86.txt' + ], licenseFragments: [{text: "All rights reserved.\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution, and in the same place and form as other copyright, license and disclaimer information.\n3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: \"This product includes software developed by The XFree86 Project, Inc (http://www.xfree86.org/) and its contributors\", in the same place and form as other third-party acknowledgments. Alternately, this acknowledgment may appear in the software itself, in the same form and location as other such third-party acknowledgments.4. Except as contained in this notice, the name of The XFree86 Project, Inc shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The XFree86 Project, Inc.", type: type.SHORT} ] }, FreeBSD: { licenseName: "FreeBSD License", - canonicalUrl: ['http://www.freebsd.org/copyright/freebsd-license.html', - 'magnet:?xt=urn:btih:87f119ba0b429ba17a44b4bffcab33165ebdacc0&dn=freebsd.txt'], + canonicalUrl: [ + 'http://www.freebsd.org/copyright/freebsd-license.html', + 'magnet:?xt=urn:btih:87f119ba0b429ba17a44b4bffcab33165ebdacc0&dn=freebsd.txt' + ], licenseFragments: [{text: "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\nRedistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\nRedistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.", type: type.SHORT}] }, ISC: { licenseName: "The ISC License", - canonicalUrl: ['https://www.isc.org/downloads/software-support-policy/isc-license/', - 'magnet:?xt=urn:btih:b8999bbaf509c08d127678643c515b9ab0836bae&dn=ISC.txt'], + canonicalUrl: [ + 'https://www.isc.org/downloads/software-support-policy/isc-license/', + 'magnet:?xt=urn:btih:b8999bbaf509c08d127678643c515b9ab0836bae&dn=ISC.txt' + ], licenseFragments: [{text: "Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.", type: type.SHORT}, {text: "Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.", type: type.SHORT}] }, @@ -164,14 +215,18 @@ exports.licenses = { ArtisticLicense2: { licenseName: "Artistic License 2.0", - canonicalUrl: ["http://www.perlfoundation.org/artistic_license_2_0", - "magnet:?xt=urn:btih:54fd2283f9dbdf29466d2df1a98bf8f65cafe314&dn=artistic-2.0.txt"], + canonicalUrl: [ + "http://www.perlfoundation.org/artistic_license_2_0", + "magnet:?xt=urn:btih:54fd2283f9dbdf29466d2df1a98bf8f65cafe314&dn=artistic-2.0.txt" + ], licenseFragments: [] }, PublicDomain: { licenseName: "Public Domain", - canonicalUrl: ['magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt'], + canonicalUrl: [ + 'magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt' + ], licenseFragments: [] }, diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js index 0f7332a..6a22992 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js @@ -2,20 +2,22 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ const types = require("js_checker/constant_types"); @@ -27,363 +29,348 @@ const token = types.token; var checkTypes = types.checkTypes; var utils = { + /** + * nodeContains + * Checks that node contains both a type and a value. + * Shortcut to check for null/undefined. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if matching. + */ + nodeContains: function (n, type, value) { + if (n != undefined) { + return n.type === type && + n.value === value; + } + }, + + /** + * isType + * Checks that node is of a certain type. + * Shortcut to check for null/undefined. + * + * @param {object} n. The current node being studied. + * @return {boolean}. True if it's the right type. + */ + isType: function (n, type) { + return n != undefined && n.type === type; + }, + + isNotType: function (n, type) { + return n != undefined && n.type !== type; + }, + + /** + * hasChildren + * + * Checks the token on the left + * and on the right. + * + * @param {object} n. The current node being studied. + * @param {leftType} token constant. The type on the + * left. + * @param {rightType} token constant. The type of child + * on the right + * + */ + hasChildren: function (n, leftType, rightType) { + if (types == undefined) { + return false; + } + return this.isType(n.children[0], leftType) && + this.isType(n.children[1], rightType); + }, + + /** + * findScriptTag + * + * This method should probably be replaced with DOM testing + * as regex is rather insufficiant, and this wouldn't cover + * tricky constructs as shown in http://ha.ckers.org/xss.html. + */ + findScriptTag: function (n) { + return n.value != undefined && + /<script[^>]*?>/i.test(n.value); + } +}; - /** - * nodeContains - * Checks that node contains both a type and a value. - * Shortcut to check for null/undefined. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if matching. - */ - nodeContains: function (n, type, value) { - if (n != undefined) { - return n.type === type && - n.value === value; - } - }, - - - /** - * isType - * Checks that node is of a certain type. - * Shortcut to check for null/undefined. - * - * @param {object} n. The current node being studied. - * @return {boolean}. True if it's the right type. - */ - isType: function (n, type) { - return n != undefined && n.type === type; - }, - - isNotType: function (n, type) { - return n != undefined && n.type !== type; - }, - - - /** - * hasChildren - * - * Checks the token on the left - * and on the right. - * - * @param {object} n. The current node being studied. - * @param {leftType} token constant. The type on the - * left. - * @param {rightType} token constant. The type of child - * on the right - * - */ - hasChildren: function (n, leftType, rightType) { - if (types == undefined) { - return false; - } - return this.isType(n.children[0], leftType) && - this.isType(n.children[1], rightType); - }, - - - /** - * findScriptTag - * - * This method should probably be replaced with DOM testing - * as regex is rather insufficiant, and this wouldn't cover - * tricky constructs as shown in http://ha.ckers.org/xss.html. - */ - findScriptTag: function (n) { - return n.value != undefined && - /<script[^>]*?>/i.test(n.value); - } +var NonTrivialChecker = function() { + this.definesFunction = false; + this.hash = null; +}; +/** + * definesFunctionFound + * + * Returns true if it finds a node of type FUNCTION + * that isn't a callback or an IIFE. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + */ +NonTrivialChecker.prototype.definesFunctionFound = function (n) { + var isFunction = false; + if (n.type === token.FUNCTION && + n.body != undefined) { + + if (n.functionForm !== token.DECLARED_FORM && + ((n.parent.type === token.LIST && + n.parent.parent.type === token.CALL) || + n.parent.type === token.CALL) && + n.name == undefined) { + // this is a callback or an immediately + // invoked function expression "IIFE". + isFunction = false; + } else { + // this is a regular function declaration or + // function expression assigned to a variable. + //console.log("THIS DEFINES FUNCTION"); + isFunction = true; + } + } + + // look for Function constructor. + if (n.type === token.IDENTIFIER && + n.value === 'Function' && + (n.parent.type === token.NEW_WITH_ARGS || + n.parent.type === token.CALL)) { + // this is a Function constructor. + //console.log("THIS DEFINES FUNCTION"); + isFunction = true; + } + + return isFunction; }; -var nonTrivialChecker = { - - definesFunction: false, - hash: null, - /** - * definesFunctionFound - * - * Returns true if it finds a node of type FUNCTION - * that isn't a callback or an IIFE. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - */ - definesFunctionFound: function (n) { - var isFunction = false; - if (n.type === token.FUNCTION && - n.body != undefined) { - - if (n.functionForm !== token.DECLARED_FORM && - ((n.parent.type === token.LIST && - n.parent.parent.type === token.CALL) || - n.parent.type === token.CALL) && - n.name == undefined) { - // this is a callback or an immediately - // invoked function expression "IIFE". - isFunction = false; - } else { - // this is a regular function declaration or - // function expression assigned to a variable. - //console.log("THIS DEFINES FUNCTION"); - isFunction = true; - } - - } - - // look for Function constructor. - if (n.type === token.IDENTIFIER && - n.value === 'Function' && - (n.parent.type === token.NEW_WITH_ARGS || - n.parent.type === token.CALL)) { - // this is a Function constructor. - //console.log("THIS DEFINES FUNCTION"); - isFunction = true; - } - - return isFunction; - }, - - - /** - * invokesEval - * - * Returns true (nontrivial) if it finds any use of - * the eval function. For simplicity, we assume any - * use of an identifier "eval" is the eval function. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - */ - invokesEval: function (n) { - return (n.type === token.CALL && - utils.nodeContains(n.children[0], token.IDENTIFIER, 'eval') || - n.type === token.IDENTIFIER && n.value === 'eval'); - }, - - /** - * evalIdentifier - * - * Returns true (nontrivial) if it finds any use of - * the eval function. For simplicity, we assume any - * use of an identifier "eval" is the eval function. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - */ - evalIdentifier: function (n) { - return n.type === token.IDENTIFIER && - n.value === 'eval'; - }, - - - /** - * invokesMethodBracketSuffix - * - * Finds a method being invoked using the bracket suffix notation - * rather than the dot notation. It is difficult without keeping track of - * variable values to check for what method is actually being called. - * So we're just flagging any use of this construct as nontrivial. - * e.g., should catch: xhr[a+b]('GET', 'http://www.example.com'); - * Should not catch other uses such as: myArray[num]; - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - */ - invokesMethodBracketSuffix: function (n) { - return n.type === token.CALL && utils.isType(n.children[0], token.INDEX); - }, - - - /** - * createsXhrObject - * - * Creates an xhr object. - * Since all "new XMLHttpRequest", "XMLHttpRequest()", - * and "new window.XMLHttpRequest" instantiate the xhr object, - * we assume (without further proof) that any use - * of the identifier "XMLHttpRequest" and "ActiveXObject" - * is an xhr object. - * Constructs like window[a+b]() are already caught by the - * bracket suffix check. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - */ - createsXhrObject: function (n) { - return (n.type === token.IDENTIFIER) && - (n.value === 'XMLHttpRequest' || - n.value === 'ActiveXObject'); - }, - - - /** - * invokesXhrOpen - * - * Here we assume the call of an open method must be an xhr request - * (and not some other object) by checking the number of arguments. - * In most cases this method won't be used since createsXhrObject - * will already have caught the xhr. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - * - */ - invokesXhrOpen: function (n) { - return n.type === token.CALL && - utils.hasChildren(n, token.DOT, token.LIST) && - utils.isType(n.children[0].children[0], token.IDENTIFIER) && - utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'open') && - n.children[1].children.length > 1; - }, - - - /** - * createsScriptElement - * - * Checks for document.createElement() that create a script. In the case - * it creates an element from a variable, we assume it's a script. In the - * future we might want to check for the value of that string variable - * (e.g., if a variable is assigned 'script', raise a flag) - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - * - * - */ - createsScriptElement: function (n) { - return n.type === token.CALL && - utils.hasChildren(n, token.DOT, token.LIST) && - utils.isType(n.children[0].children[0], token.IDENTIFIER) && - utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'createElement') && - (utils.nodeContains(n.children[1].children[0], token.STRING, 'script') || - utils.isType(n.children[1].children[0], token.IDENTIFIER)); - }, - - - /** - * writesScriptAsHtmlString - * - * catches myObj.write('<script></script>'); - * or any myObj.write(myStringVariable); - * or concatenation such as: - * myObj.write('<scri' + stringVariable); - * or 'something' + 'somethingelse'. - * - * To check for javascript here we might want to look at the list - * from ha.ckers.org/xss.html for the future. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - * - */ - writesScriptAsHtmlString: function (n) { - var listArg; - - if (n.type === token.CALL && - utils.hasChildren(n, token.DOT, token.LIST) && - utils.isType(n.children[0].children[0], token.IDENTIFIER) && - utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'write')) { - - if (utils.isNotType(n.children[1].children[0], token.STRING)) { - // return true if any operation or concatenation. - // We are cautious (as it could - // embed a script) and flag this as nontrivial. - - return true; - } - return utils.findScriptTag(n.children[1].children[0]); - } else { - return false; - } - }, - - /** - * nontrivial anytime we see an identifier as innerHTML - */ - innerHTMLIdentifier: function (n) { - if ((n.type === token.IDENTIFIER || - n.type === token.STRING) && - n.value === 'innerHTML') { - return true; - } - }, - - - /** - * checkNontrivial - * - * Contains all the conditionals that try to identify, - * step by step, all code that could be flagged as - * nontrivial. - * - * @param {object} n. The current node being studied. - * @return {boolean} . True if found. - * - */ - checkNontrivial: function (n, t) { - - if (n.type === token.IDENTIFIER && this.evalIdentifier(n)) { - //console.log("NONTRIVIAL: eval has been found in code"); - return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code"); - } - - if (this.innerHTMLIdentifier(n)) { - //console.log("NONTRIVIAL: innerHTML identifier"); - return types.nontrivialWithComment("NONTRIVIAL: innerHTML identifier"); - } - - // the node is an identifier - if (n.type === token.IDENTIFIER && this.createsXhrObject(n)) { - //console.log('NONTRIVIAL: Creates an xhr object'); - return types.nontrivialWithComment('NONTRIVIAL: Creates an xhr object'); - } - - // this is a method/function call - if (n.type === token.CALL) { - - if (this.invokesEval(n)) { - //console.log("NONTRIVIAL: eval has been found in code"); - return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code"); - } - if (this.invokesMethodBracketSuffix(n)) { - //console.log('NONTRIVIAL: square bracket suffix method call detected'); +/** + * invokesEval + * + * Returns true (nontrivial) if it finds any use of + * the eval function. For simplicity, we assume any + * use of an identifier "eval" is the eval function. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + */ +NonTrivialChecker.prototype.invokesEval = function (n) { + return (n.type === token.CALL && + utils.nodeContains(n.children[0], token.IDENTIFIER, 'eval') || + n.type === token.IDENTIFIER && n.value === 'eval'); +}; + +/** + * evalIdentifier + * + * Returns true (nontrivial) if it finds any use of + * the eval function. For simplicity, we assume any + * use of an identifier "eval" is the eval function. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + */ +NonTrivialChecker.prototype.evalIdentifier = function (n) { + return n.type === token.IDENTIFIER && n.value === 'eval'; +}; + + +/** + * invokesMethodBracketSuffix + * + * Finds a method being invoked using the bracket suffix notation + * rather than the dot notation. It is difficult without keeping track of + * variable values to check for what method is actually being called. + * So we're just flagging any use of this construct as nontrivial. + * e.g., should catch: xhr[a+b]('GET', 'http://www.example.com'); + * Should not catch other uses such as: myArray[num]; + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + */ +NonTrivialChecker.prototype.invokesMethodBracketSuffix = function (n) { + return n.type === token.CALL && utils.isType(n.children[0], token.INDEX); +}; + +/** + * createsXhrObject + * + * Creates an xhr object. + * Since all "new XMLHttpRequest", "XMLHttpRequest()", + * and "new window.XMLHttpRequest" instantiate the xhr object, + * we assume (without further proof) that any use + * of the identifier "XMLHttpRequest" and "ActiveXObject" + * is an xhr object. + * Constructs like window[a+b]() are already caught by the + * bracket suffix check. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + */ +NonTrivialChecker.prototype.createsXhrObject = function (n) { + return (n.type === token.IDENTIFIER) && + (n.value === 'XMLHttpRequest' || + n.value === 'ActiveXObject'); +}; + +/** + * invokesXhrOpen + * + * Here we assume the call of an open method must be an xhr request + * (and not some other object) by checking the number of arguments. + * In most cases this method won't be used since createsXhrObject + * will already have caught the xhr. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + * + */ +NonTrivialChecker.prototype.invokesXhrOpen = function (n) { + return n.type === token.CALL && + utils.hasChildren(n, token.DOT, token.LIST) && + utils.isType(n.children[0].children[0], token.IDENTIFIER) && + utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'open') && + n.children[1].children.length > 1; +}; + +/** + * createsScriptElement + * + * Checks for document.createElement() that create a script. In the case + * it creates an element from a variable, we assume it's a script. In the + * future we might want to check for the value of that string variable + * (e.g., if a variable is assigned 'script', raise a flag) + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + * + * + */ +NonTrivialChecker.prototype.createsScriptElement = function (n) { + return n.type === token.CALL && + utils.hasChildren(n, token.DOT, token.LIST) && + utils.isType(n.children[0].children[0], token.IDENTIFIER) && + utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'createElement') && + (utils.nodeContains(n.children[1].children[0], token.STRING, 'script') || + utils.isType(n.children[1].children[0], token.IDENTIFIER)); +}; + +/** + * writesScriptAsHtmlString + * + * catches myObj.write('<script></script>'); + * or any myObj.write(myStringVariable); + * or concatenation such as: + * myObj.write('<scri' + stringVariable); + * or 'something' + 'somethingelse'. + * + * To check for javascript here we might want to look at the list + * from ha.ckers.org/xss.html for the future. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + * + */ +NonTrivialChecker.prototype.writesScriptAsHtmlString = function (n) { + var listArg; + + if (n.type === token.CALL && + utils.hasChildren(n, token.DOT, token.LIST) && + utils.isType(n.children[0].children[0], token.IDENTIFIER) && + utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'write') + ) { + if (utils.isNotType(n.children[1].children[0], token.STRING)) { + // return true if any operation or concatenation. + // We are cautious (as it could + // embed a script) and flag this as nontrivial. + + return true; + } + return utils.findScriptTag(n.children[1].children[0]); + } else { + return false; + } +}; + +/** + * nontrivial anytime we see an identifier as innerHTML + */ +NonTrivialChecker.prototype.innerHTMLIdentifier = function (n) { + if ((n.type === token.IDENTIFIER || + n.type === token.STRING) && + n.value === 'innerHTML' + ) { + return true; + } +}; + +/** + * checkNontrivial + * + * Contains all the conditionals that try to identify, + * step by step, all code that could be flagged as + * nontrivial. + * + * @param {object} n. The current node being studied. + * @return {boolean} . True if found. + * + */ +NonTrivialChecker.prototype.checkNontrivial = function (n, t) { + + if (n.type === token.IDENTIFIER && this.evalIdentifier(n)) { + //console.log("NONTRIVIAL: eval has been found in code"); return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code"); - } - - if (this.invokesXhrOpen(n)) { - //console.log('NONTRIVIAL: an open method similar to xhr.open is used'); - return types.nontrivialWithComment('NONTRIVIAL: square bracket suffix method call detected'); - } - - if (this.createsScriptElement(n)) { - //console.log('NONTRIVIAL: creates script element dynamically.'); - return types.nontrivialWithComment('NONTRIVIAL: an open method similar to xhr.open is used'); - } - - if (this.writesScriptAsHtmlString(n)) { - //console.log('NONTRIVIAL: writes script as html dynamically.'); - return types.nontrivialWithComment('NONTRIVIAL: creates script element dynamically.'); - } - } - - // The node is a function definition. - // Most common occurence. - if (this.definesFunctionFound(n)) { - return types.trivialFuncWithComment("Script is trivial but defines one or more functions"); - } - - // found nothing else, so trivial. - return types.trivialWithComment("Script is trivial"); - - } + } + + if (this.innerHTMLIdentifier(n)) { + //console.log("NONTRIVIAL: innerHTML identifier"); + return types.nontrivialWithComment("NONTRIVIAL: innerHTML identifier"); + } + + // the node is an identifier + if (n.type === token.IDENTIFIER && this.createsXhrObject(n)) { + //console.log('NONTRIVIAL: Creates an xhr object'); + return types.nontrivialWithComment('NONTRIVIAL: Creates an xhr object'); + } + + // this is a method/function call + if (n.type === token.CALL) { + + if (this.invokesEval(n)) { + //console.log("NONTRIVIAL: eval has been found in code"); + return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code"); + } + + if (this.invokesMethodBracketSuffix(n)) { + //console.log('NONTRIVIAL: square bracket suffix method call detected'); + return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code"); + } + + if (this.invokesXhrOpen(n)) { + //console.log('NONTRIVIAL: an open method similar to xhr.open is used'); + return types.nontrivialWithComment('NONTRIVIAL: square bracket suffix method call detected'); + } + + if (this.createsScriptElement(n)) { + //console.log('NONTRIVIAL: creates script element dynamically.'); + return types.nontrivialWithComment('NONTRIVIAL: an open method similar to xhr.open is used'); + } + + if (this.writesScriptAsHtmlString(n)) { + //console.log('NONTRIVIAL: writes script as html dynamically.'); + return types.nontrivialWithComment('NONTRIVIAL: creates script element dynamically.'); + } + } + + // The node is a function definition. + // Most common occurence. + if (this.definesFunctionFound(n)) { + return types.trivialFuncWithComment("Script is trivial but defines one or more functions"); + } + + // found nothing else, so trivial. + return types.trivialWithComment("Script is trivial"); }; exports.nonTrivialChecker = function () { - - var checker = Object.create(nonTrivialChecker); - - return checker; -};
\ No newline at end of file + return new NonTrivialChecker(); +}; diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js index 10874fc..b3e84d6 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js @@ -2,39 +2,41 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ exports.patternUtils = { - /** - * removeNonalpha - * - * Remove all nonalphanumeric values, except for - * < and >, since they are what we use for tokens. - * - */ - removeNonalpha: function (str) { - var regex = /[^a-z0-9<>@]+/gi; - return str.replace(regex, ''); - }, - removeWhitespace: function (str) { - return str.replace(/[ \t\r\n]+/gmi,""); - }, - replaceTokens: function (str) { - var regex = /<.*?>/gi; - return str.replace(regex, '.*?'); - } -};
\ No newline at end of file + /** + * removeNonalpha + * + * Remove all nonalphanumeric values, except for + * < and >, since they are what we use for tokens. + * + */ + removeNonalpha: function (str) { + var regex = /[^a-z0-9<>@]+/gi; + return str.replace(regex, ''); + }, + removeWhitespace: function (str) { + return str.replace(/\s+/gmi, ''); + }, + replaceTokens: function (str) { + var regex = /<.*?>/gi; + return str.replace(regex, '.*?'); + } +}; diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js index b5dad1b..f39e0b7 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js @@ -2,47 +2,45 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ -var privacyThreatJs = require('js_checker/privacy_threat_definitions.js'); -var patternUtils = require('js_checker/pattern_utils').patternUtils; +const privacyThreatJs = require('js_checker/privacy_threat_definitions.js'); +const patternUtils = require('js_checker/pattern_utils').patternUtils; exports.privacyCheck = { - - checkScriptPrivacyThreat: function (currentScript) { - var list = privacyThreatJs.js, - i, - jsRegexp, - match, - max, - check; - - currentScript = patternUtils.removeWhitespace(currentScript); + checkScriptPrivacyThreat: function (currentScript) { + var list = privacyThreatJs.js; + var i; + var item; + var max; - for (var item in list) { - max = list[item].length; + currentScript = patternUtils.removeWhitespace(currentScript); - for (i = 0; i < max; i++) { - if (list[item][i].test(currentScript)) { - return true; - } - } + for (item in list) { + max = list[item].length; - } - } - + for (i = 0; i < max; i++) { + if (list[item][i].test(currentScript)) { + return true; + } + } + } + return false; + } }; diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js index ea6d279..fd04dcf 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js @@ -2,39 +2,53 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ exports.js = { - /** - * googleAnalytics - * Tracking code for Google Analytics. - * It corresponds to: - * var _gaq = _gaq || []; - * _gaq.push(['_setAccount', 'UA-XXXXXXX-X']); - * _gaq.push(['_trackPageview']); - * - * (function() { - * var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - * ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - * var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - * })(); - * - */ - googleAnalytics: [/var_gaq=_gaq\|\|\[\];_gaq\.push\(\['_setAccount','UA[0-9\-]*?'\]\);(_gaq.push\(\['_setDomainName','[a-z\.]*?'\]\);)?_gaq\.push\(\['_trackPageview'\]\);\(function\(\){varga=document\.createElement\('script'\);ga\.type='text\/javascript\';ga\.async=true;ga\.src=\(\'https:\'==document\.location\.protocol\?'https:\/\/ssl':'http:\/\/www'\)\+'\.google\-analytics\.com\/ga\.js';vars=document\.getElementsByTagName\('script'\)\[0\];s\.parentNode\.insertBefore\(ga,s\);}\)\(\);/ig, - /vargaJsHost\=\(\(\"https\:\"\=\=document\.location\.protocol\)\?\"https\:\/\/ssl\.\"\:\"http\:\/\/www\.\"\)\;document\.write\(unescape\(\"\%3Cscriptsrc\=\'\"\+gaJsHost\+\"google\-analytics\.com\/ga\.js\'type\=\'text\/javascript\'\%3E\%3C\/script\%3E\"\)\)\;/ig, - /try{varpageTracker\=\_gat\.\_getTracker\(\"UA[0-9\-]*?\"\)\;pageTracker\.\_trackPageview\(\)\;}catch\(err\){}/ig] -};
\ No newline at end of file + /** + * googleAnalytics + * Tracking code for Google Analytics. + * It corresponds to: + * var _gaq = _gaq || []; + * _gaq.push(['_setAccount', 'UA-XXXXXXX-X']); + * _gaq.push(['_trackPageview']); + * + * (function() { + * var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + * ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + * var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + * })(); + * + * It also matches GA code that doesn't track a page view, like this: + * var _gaq = _gaq || []; + * _gaq.push(['_setAccount', 'UA-5936383-6']); + * + * (function() { + * var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + * ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + * var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + * })(); + * + */ + googleAnalytics: [ + /var_gaq=_gaq\|\|\[\];_gaq\.push\(\['_setAccount','UA[0-9\-]*?'\]\);(_gaq.push\(\['_setDomainName','[a-z\.]*?'\]\);)?(_gaq\.push\(\['_trackPageview'\]\);)?\(function\(\){varga=document\.createElement\('script'\);ga\.type='text\/javascript\';ga\.async=true;ga\.src=\(\'https:\'==document\.location\.protocol\?'https:\/\/ssl':'http:\/\/www'\)\+'\.google\-analytics\.com\/ga\.js';vars=document\.getElementsByTagName\('script'\)\[0\];s\.parentNode\.insertBefore\(ga,s\);}\)\(\);/i, + /vargaJsHost\=\(\(\"https\:\"\=\=document\.location\.protocol\)\?\"https\:\/\/ssl\.\"\:\"http\:\/\/www\.\"\)\;document\.write\(unescape\(\"\%3Cscriptsrc\=\'\"\+gaJsHost\+\"google\-analytics\.com\/ga\.js\'type\=\'text\/javascript\'\%3E\%3C\/script\%3E\"\)\)\;/i, + /try{varpageTracker\=\_gat\.\_getTracker\(\"UA[0-9\-]*?\"\)\;pageTracker\.\_trackPageview\(\)\;}catch\(err\){}/i + ] +}; diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js index 1904812..c504444 100644 --- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js @@ -2,20 +2,22 @@ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. * * * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros + * Copyright (C) 2014, 2015 Nik Nyby * - * This program is free software: you can redistribute it and/or modify + * This file is part of GNU LibreJS. + * + * GNU LibreJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * GNU LibreJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>. */ /** * relation_checker.js |