Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit b20b224

Browse files
Caleb HooverCaleb Hoover
Caleb Hoover
authored and
Caleb Hoover
committed
reorganized some stuff. Split check.js into custom.js and scope.js
1 parent 6f7568b commit b20b224

File tree

4 files changed

+774
-767
lines changed

4 files changed

+774
-767
lines changed

bin/check

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var yargs = require('yargs')
88
.describe('o', 'if -j, will output json into a file: <file>_log. If a file is given, outputs to that it. Default is false.')
99
.showHelpOnFail(false);
1010

11-
var check = require('../check.js'),
11+
var check = require('../check.js'),
12+
Scope = require('../scope.js'),
1213
colors = require('colors'),
1314
fs = require('fs'),
1415
path = require('path'),
@@ -37,9 +38,6 @@ if (argv.h) {
3738
process.exit();
3839
}
3940

40-
var sinks = module.exports.sinks = require('../danger.json').sinks;
41-
var sources = module.exports.sources = require('../danger.json').sources;
42-
4341
check.flags.verbose = argv.v;
4442
check.flags.recursive = argv.r;
4543
if (argv.j)
@@ -48,75 +46,16 @@ if (argv.j)
4846
if (!argv.j)
4947
console.log(' ---- '.yellow, file.white);
5048

51-
var scope = new check.Scope({
52-
sources: sources, sinks: sinks,
49+
var scope = new Scope({
5350
file: file
5451
});
5552

56-
var reports = [];
57-
58-
if (check.flags.json) {
59-
find = function(r, name) {
60-
return _.find(r, function(i) {
61-
return name.indexOf(i.source.name) === 0;
62-
});
63-
};
64-
65-
/* Creates a report for a source.
66-
Keeps adding possible taints untill the source lands into a sink.
67-
*/
68-
scope.log = function(type, node, name, value) {
69-
if (typeof value !== 'string')
70-
return;
71-
switch(type) {
72-
case 'SOURCE':
73-
this.reports.push({
74-
source: {
75-
name: value,
76-
line: this.file + ':' + check.pos(node)
77-
}
78-
});
79-
break;
80-
case 'SCE':
81-
case 'SCES': // Possible taint: call expression containing the source.
82-
source = find(this.reports, value);
83-
if (source) {
84-
if (!source.chain)
85-
source.chain = [];
86-
source.chain.push({
87-
name: name,
88-
value: value,
89-
line: this.file + ':' + check.pos(node)
90-
});
91-
}
92-
break;
93-
case 'SASSIGN':
94-
break;
95-
case 'SINK':
96-
source = find(this.reports, value);
97-
if (source)
98-
source.sink = {
99-
name: name,
100-
line: this.file + ':' + check.pos(node)
101-
};
102-
103-
104-
// Flush the report. After finding the sink, we don't want to track it anymore.
105-
if (this.reports.indexOf(source) != -1) {
106-
this.reports.splice(this.reports.indexOf(source), 1);
107-
reports.push(source);
108-
}
109-
break;
110-
}
111-
};
112-
}
113-
11453
var ast = check.astFromFile(scope.file);
11554
check.traverse(ast, scope);
11655

11756
if (check.flags.json) {
118-
if (reports.length !== 0)
119-
console.log(require('prettyjson').render(reports));
57+
if (check.reports.length !== 0)
58+
console.log(require('prettyjson').render(check.reports));
12059
else
12160
console.log(colors.green('No vulneralbities found'));
12261
}

0 commit comments

Comments
 (0)