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

Commit c15fc78

Browse files
Caleb HooverCaleb Hoover
Caleb Hoover
authored and
Caleb Hoover
committed
began documenting
1 parent 4092717 commit c15fc78

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

custom.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ function(scope, node, ce) { // http.get
5858

5959
return true;
6060

61-
}, function(scope, node, ce) {// (new require('hapi').server()).route()
61+
}, function(scope, node, ce) {// require('fs').readFile
6262
var ceName = scope.resolve(ce.name);
6363
if (ceName != 'require(\'fs\').readFile') {
6464
return false;
6565
}
6666

6767
var func = ce.arguments[2]; // the callback
68-
if (func) {
69-
func.scope.sources.push(func.params[1]); // data
68+
if (func && func.scope) {
69+
func.scope.sources.push(func.params[1]); // the 2nd argument is the source
7070
func.scope.log('SOURCE', node, false, func.params[1]);
71+
7172
traverse(func.body, func.scope);
7273
}
7374
return true;

danger.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{"sinks": [
22
"eval",
33
"setTimeout",
4-
"setImmediate",
54
"clearTimeout",
65
"setInterval",
76
"clearInterval",

scope.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ var fs = require('fs'),
1717

1818
var custom = module.exports.custom = require('./custom');
1919

20-
var sinks = require('./danger.json').sinks;
21-
var sources = require('./danger.json').sources;
20+
// Global initial list of sources and sinks
21+
var Sinks = require('./danger.json').sinks;
22+
var Sources = require('./danger.json').sources;
2223

2324
var baseFile;
2425

@@ -38,8 +39,9 @@ Scope = function(scope) {
3839
this.vars = scope.vars || {};
3940
if (!this.vars.module) this.vars.module = {exports: {}};
4041
if (!this.vars.global) this.vars.global = {};
41-
this.sources = scope.sources||sources;
42-
this.sinks = scope.sinks||sinks;
42+
// dynamic list of sources and sinks as variables get set to them
43+
this.sources = scope.sources || Sources;
44+
this.sinks = scope.sinks || Sinks;
4345
this.log = Scope.log;
4446
this.file = scope.file;
4547
if (!baseFile) baseFile = scope.file;
@@ -55,6 +57,9 @@ Scope.prototype.track = function(variable) {
5557

5658
var expr = this.resolveExpression(variable.init, function(value) {
5759
if (value) {
60+
// if a = process.argv
61+
// resolve(a) will result in process.argv
62+
// although a should already be a source, this is safer
5863
var resolved = scope.resolve(value);
5964
if (resolved && typeof resolved == 'string') {
6065
if (scope.isSource(resolved.name || resolved) || scope.isSource(value.name || value)) {
@@ -72,6 +77,8 @@ Scope.prototype.track = function(variable) {
7277
};
7378

7479
// returns a value for a variable if one exists
80+
// if a = b
81+
// resolve(a) will result in b
7582
Scope.prototype.resolve = function(name) {
7683
if (!name || typeof name != 'string')
7784
return false;
@@ -119,14 +126,19 @@ Scope.prototype.resolveStatement = function(node) {
119126

120127
var ceName = scope.resolve(ce.name);
121128

122-
var t = 'CES';
129+
var t = 'CES'; // Call Expression Statement (I.E. a function)
123130

124131
if (ce.arguments)
132+
// for all arguments, check if it is a source
125133
ce.arguments.some(function (arg) {
134+
// we don't want to look at the arg if it is a function declaration
126135
if (!arg || (arg.scope && arg.params && arg.body))
127136
return false;
128137
var resolved = scope.resolve(arg);
129138
var source = resolved;
139+
// Ugly ultimate check if the arg is a source.
140+
// the ugly part comes from checking a Binary Expression
141+
// and determing what part is the source
130142
if (scope.isSource(arg.name || arg) || scope.isSource(resolved.name || resolved) ||
131143
(traverseJSON(arg, function (a) {
132144
if (!a) return false;

0 commit comments

Comments
 (0)