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

Commit 45b8ede

Browse files
committed
fixed sources and sinks across different modules
1 parent 0d1accf commit 45b8ede

File tree

4 files changed

+188
-122
lines changed

4 files changed

+188
-122
lines changed

check.js

Lines changed: 19 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,73 +24,13 @@ var flags = module.exports.flags = {
2424
};
2525

2626
var reports = module.exports.reports = [];
27-
var lookupTable = {};
2827

2928
module.exports.setFlags = function(newFlags) {
3029
Scope.flags.verbose = flags.verbose = newFlags.verbose;
3130
Scope.flags.recursive = flags.recursive = newFlags.recursive;
3231
Scope.flags.json = flags.json = newFlags.json;
3332
Scope.flags.debug = flags.debug = newFlags.debug;
3433

35-
if (flags.recursive) {
36-
// function to handle loading and traversing a file upon require()
37-
Scope.custom = Scope.custom.push(function(scope, node, ce) { // require
38-
if (ce.name != 'require')
39-
return false;
40-
41-
if (!ce.arguments[0])
42-
return;
43-
44-
var file;
45-
if (node.arguments[0].type == 'Literal') {
46-
file = node.arguments[0].value;
47-
} else if (node.arguments[0].type == 'Identifier') {
48-
file = scope.resolve(node.arguments[0].name);
49-
if (typeof file != 'string')
50-
return;
51-
} else {
52-
return;
53-
}
54-
55-
if (['hapi', 'express', 'jade', 'mysql', 'consolidate'].indexOf(file) != -1 || file.indexOf('hapi') != -1)
56-
return; // just ignore these things. They have prewritten handlers anyways.
57-
58-
var r;
59-
scope.resolvePath(file, function (pkg) {
60-
if (!pkg)
61-
return;
62-
63-
// Lookup table is a list of files already looked at.
64-
// In static analysis, we only want to look at each file once.
65-
if (lookupTable[pkg])
66-
return;
67-
lookupTable[pkg] = true;
68-
69-
var ast = astFromFile(pkg);
70-
if (ast) {
71-
if (flags.verbose && !flags.json)
72-
console.log(' ---- '.yellow, pkg);
73-
74-
var newScope = new Scope.Scope({
75-
file: pkg,
76-
});
77-
traverse(ast, newScope);
78-
79-
r = newScope.vars.module.exports;
80-
newScope.sinks.forEach(function (i) {
81-
if (i.indexOf('module.exports.') === 0)
82-
scope.sinks.push(i.replace('module.exports', 'a'))
83-
});
84-
85-
} else
86-
if (flags.verbose && !flags.json)
87-
console.log(' ---- '.yellow, String(pkg).red);
88-
});
89-
90-
return r;
91-
});
92-
}
93-
9434
if (flags.json) {
9535
// We don't do anything with these function when outputing json.
9636
Scope.Scope.createNewScope = function() {};
@@ -120,6 +60,7 @@ module.exports.setFlags = function(newFlags) {
12060
var file = this.file || this.scope.file;
12161
var p = pos(node);
12262
var p = path.relative(Scope.Scope.baseFile.split('/').reverse().slice(1).reverse().join('/'), file) + ':' + p;
63+
12364
switch(type) {
12465
case 'SOURCE':
12566
var source = find(scope.reports, value);
@@ -138,13 +79,27 @@ module.exports.setFlags = function(newFlags) {
13879
if (!source.chain)
13980
source.chain = [];
14081
source.chain.push({
82+
type: 'function',
14183
name: name,
14284
value: value,
14385
line: p
14486
});
14587
}
14688
break;
147-
case 'SASSIGN':
89+
case 'SOURCE_ASSIGN':
90+
case 'SINK_ASSIGN':
91+
var source = find(scope.reports, value);
92+
93+
if (source) {
94+
if (!source.chain)
95+
source.chain = [];
96+
source.chain.push({
97+
type: 'assign',
98+
name: name,
99+
value: value,
100+
line: p
101+
});
102+
}
148103
break;
149104
case 'SINK':
150105
var source = find(scope.reports, value);
@@ -190,10 +145,10 @@ module.exports.setFlags = function(newFlags) {
190145
if (flags.recursive)
191146
p = path.relative(Scope.Scope.baseFile.split('/').reverse().slice(1).reverse().join('/'), this.file) + ':' + p;
192147

193-
console.log(' ', '[' + type + ']', p, name, value ? value : '');
148+
// console.log(' ', '[' + type + ']', p, name, value ? value : '');
194149

195-
// console.log(' ', cs[type]?cs[type]('[' + type + ']'):colors.blue('[' + type + ']'),
196-
// colors.grey(p), name, value ? value : '');
150+
console.log(' ', cs[type]?cs[type]('[' + type + ']'):colors.blue('[' + type + ']'),
151+
colors.grey(p), name, value ? value : '');
197152
};
198153
}
199154

0 commit comments

Comments
 (0)