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

Commit 06fc621

Browse files
Caleb HooverCaleb Hoover
Caleb Hoover
authored and
Caleb Hoover
committed
WORKS
1 parent 43b0213 commit 06fc621

File tree

1 file changed

+55
-33
lines changed

1 file changed

+55
-33
lines changed

check.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,29 @@ function(scope, node, ce) { // http.get
4646
var func = ce.arguments[1];
4747

4848
func.scope.sources = func.scope.sources.concat(func.params[0]);
49-
traverse(func.body, func.scope);
49+
return true;
50+
51+
}, function(scope, node, ce) {// (new require('hapi').server()).route()
52+
if (ce.name.indexOf('require(\'hapi\').Server()') === 0)
53+
return false;
54+
if (scope.resolve(ce.name).split('.').slice(-1)[0] != 'route')
55+
return false;
56+
57+
if (ce.arguments[0]) {
58+
var func;
59+
if (ce.arguments[0].config && ce.arguments[0].config.handler) {
60+
func = ce.arguments[0].config.handler;
61+
} else {
62+
func = ce.arguments[0].handler;
63+
}
64+
65+
if (func && func.scope) {
66+
func.scope.sources.push(func.params[0]);
67+
traverse(func.body, func.scope);
68+
69+
}
70+
}
71+
5072
return true;
5173

5274
}, function(scope, node, ce) { // require
@@ -66,6 +88,8 @@ function(scope, node, ce) { // http.get
6688
return;
6789
}
6890

91+
if (file == 'hapi')
92+
return;
6993

7094
scope.resolvePath(file, function (pkg) {
7195
if (!pkg)
@@ -116,21 +140,20 @@ Scope.prototype.track = function(variable) {
116140
var scope = this;
117141
var name = variable.id.name;
118142

119-
var value = this.resolveExpression(variable.init);//, function(extra) {
120-
// scope.sources.push(name);
121-
// scope.log('[SOURCE]'.red, variable, name);
122-
// });
123-
if (value) {
124-
var resolved = this.resolve(value);
125-
if (resolved && typeof resolved == 'string') {
126-
if (this.isSource(resolved.name || resolved) || this.isSource(value.name || value)) {
127-
this.sources.push(name);
128-
this.log('SOURCE', variable, name, value);
143+
var expr = this.resolveExpression(variable.init, function(value) {
144+
if (value) {
145+
var resolved = scope.resolve(value);
146+
if (resolved && typeof resolved == 'string') {
147+
if (scope.isSource(resolved.name || resolved) || scope.isSource(value.name || value)) {
148+
scope.sources.push(name);
149+
scope.log('SOURCE', variable, name, value);
150+
}
129151
}
130152
}
131-
}
132153

133-
this.vars[name] = value;
154+
});
155+
156+
this.vars[name] = expr;
134157

135158
if (flags.verbose && value)
136159
this.log('VAR', variable, name, value?value.raw || value:'');
@@ -293,32 +316,32 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
293316
case 'Identifier':
294317
// if variable is being set to a bad variable, mark it too as bad
295318

296-
var resolved = scope.resolve(right.name);
297-
if (resolved && typeof resolved == 'string') {
298-
if (scope.isSource(resolved.name)) {
299-
if (isSourceCB) {
300-
isSourceCB();
301-
}
302-
}
319+
if (isSourceCB) {
320+
isSourceCB(right.name);
303321
}
322+
304323
return right.name;
305324
case 'ArrayExpression':
306325
var array = scope.resolveArrayExpression(right);
307326
if (flags.verbose)
308327
this.log('ARRAY', right, array);
309328
return array;
310329
case 'BinaryExpression':
311-
var bin = this.resolveExpression(right.left, isSourceCB) +
312-
' ' + right.operator + ' ' +
313-
this.resolveExpression(right.right, isSourceCB);
330+
var bin = {
331+
left: this.resolveExpression(right.left, isSourceCB),
332+
op: right.operator,
333+
right: this.resolveExpression(right.right, isSourceCB)
334+
};
314335
// if (flags.verbose)
315-
// this.log('BE', right, bin);
336+
// this.log('BE', right, bin);
316337

338+
// console.log(bin, this.sources);
317339
return bin;
340+
341+
case 'NewExpression':
318342
case 'CallExpression':
319343
var ce = scope.resolveCallExpression(right);
320344

321-
322345
if (!ce.name)
323346
return ce;
324347
if (typeof ce.name != 'string')
@@ -330,10 +353,9 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
330353
this.log('CE', right, ceName, ce.raw);
331354

332355
if (ceName && typeof ceName == 'string') {
333-
if (scope.isSource(ceName)) {
334-
if (isSourceCB)
335-
isSourceCB(ceName);
336-
}
356+
if (isSourceCB)
357+
isSourceCB(ceName);
358+
337359

338360
if (this.isSink(ceName)) {
339361
ce.arguments.some(function (arg) {
@@ -352,16 +374,16 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
352374
return ce;
353375
case 'MemberExpression':
354376
var me = scope.resolveMemberExpression(right);
355-
if (typeof me == 'string' && scope.isSource(me)) {
356-
if (isSourceCB)
357-
isSourceCB();
358-
}
377+
if (isSourceCB)
378+
isSourceCB(me);
379+
359380
return me;
360381
case 'ObjectExpression': // json objects
361382
return scope.resolveObjectExpression(right);
362383
case 'FunctionExpression': // functions
363384
var fe = scope.resolveFunctionExpression(right);
364385
return fe;
386+
365387
}
366388
};
367389

0 commit comments

Comments
 (0)