Created
October 5, 2015 23:47
-
-
Save tofumatt/e7787232b59998c30245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(context) { | |
var variables = {}; | |
return { | |
Identifier: function(node) { | |
// Start tracking a variable; it might be used to create an identifier | |
// we don't allow. | |
if (node.parent.type === 'VariableDeclarator') { | |
variables[node.name] = { | |
ops: 0, | |
reported: false, | |
value: node.parent.init.value, | |
}; | |
} | |
console.log(node.name, variables[node.name], node) | |
if (node.parent.type === 'AssignmentExpression') { | |
if (node.parent.right && node.parent.right.type === 'Literal') { | |
if (node.parent.operator === '+=') { | |
variables[node.name].value += node.parent.right.value; | |
variables[node.name].ops++; | |
} | |
if (node.parent.operator === '-=') { | |
variables[node.name].value -= node.parent.right.value; | |
variables[node.name].ops++; | |
} | |
} | |
} | |
if (node.parent.type === 'BinaryExpression') { | |
if (node.parent.operator === '+') { | |
if (node.parent.right.type === 'Literal') { | |
variables[node.name].value = variables[node.name].value + | |
node.parent.right.value; | |
variables[node.name].ops++; | |
} | |
if (node.parent.right.type === 'Identifier') { | |
variables[node.name].value = variables[node.name].value + | |
variables[node.parent.right.name].value; | |
} | |
} | |
} | |
// Catches obsfucated calls to `mozIndexedDB`. | |
for (var varName in variables) { | |
if (variables[varName].value === 'mozIndexedDB' && | |
variables[varName].ops > 0 && | |
variables[varName].reported === false) { | |
variables[varName].reported = true; | |
return context.report(node, 'mozIndexedDB_possible'); | |
} | |
} | |
}, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment