Elegant, Fast JavaScript static security analyzer for finding issues like DOM XSS.
Install esflow as a command line tool (might require sudo permission):
npm install -g esflow
esflow -v : Prints the current version
esflow https://example.com : Scans for all embedded js code in example.com
esflow https://example.com -a : Scans for all embedded js code in example.com and all included js files
esflow ./ : Scans all the JS files in the current directory
esflow ./test.js : Scans a specific JS file
esflow -h : Show this help menu
$ esflow https://public-firing-range.appspot.com/dom/toxicdom/window/name/innerHtml
$ esflow http://damnvulnerable.me/domxss/cookie_to_innerhtml -a
esflow fileName.js
or
esflow ./
git clone https://github.com/skepticfx/esflow.git
cd esflow
npm install
And then use it like this:
var esflow = require('./index.js');
// The code to analyze./bin
var code = require('fs').readFileSync('./inputs/basic.js', 'utf8');
// Define sources and sinks
var sources = ['document.cookie', 'location.href', 'location.hash', 'window.name'];
var sinks = ['.innerHTML', '.outerHTML', '$', 'jQuery', 'eval', 'setTimeout', 'document.write'];
var specialSinks = [{'calleeName': '.setAttribute', 'argumentPosition': 1, 'argumentValue': ['onclick', 'href']}];
var filters = ['escape', 'encodeURI', 'encodeHTML', 'clean'];
var result = esflow.analyze(code, {sources: sources, sinks: sinks, specialSinks: specialSinks}, statusCallback);
console.log(result.assignmentPairs);
console.log(result.functionCallPairs);
function statusCallback(status){
console.log(status.progress);
}
You can try,
node runner.js fileName.js
to run an analysis on the ./fileName.js
file.
npm test
npm run testAll
All tests are under ./test/.
Take a look at ./test/assignments.test.js
& ./test/functionCalls.test.js
and their
respective fixtures to get an idea.
npm run testFiringRange
- Find DOM XSS for usual coding patterns.
- Should be easily extensible to any framework like NodeJS, AngularJS, or any X-Library.
- Should have an approach to specify filters like escape(), encodeURIComponent and custom filter functions. In these cases, do not flag as a vulnerable flow. (TODO)
- False positives and negatives are common, we try to focus on coding patterns for given frameworks and focus on improving detection for that.
- Should always complete to end. Do not get stuck in a infinite recursion / stack call, Tail Code Optimize when possible.
Static analyzers are usually dumb and easily miss a valid vulnerability or report an invalid issue as a vulnerability. Its a island full of false positives and negatives.
Please file an issue when you see any insanely unexpected results and we can work towards fixing that ASAP, if the issue makes sense.