@@ -8,7 +8,8 @@ var yargs = require('yargs')
8
8
. describe ( 'o' , 'if -j, will output json into a file: <file>_log. If a file is given, outputs to that it. Default is false.' )
9
9
. showHelpOnFail ( false ) ;
10
10
11
- var check = require ( '../check.js' ) ,
11
+ var check = require ( '../check.js' ) ,
12
+ Scope = require ( '../scope.js' ) ,
12
13
colors = require ( 'colors' ) ,
13
14
fs = require ( 'fs' ) ,
14
15
path = require ( 'path' ) ,
@@ -37,9 +38,6 @@ if (argv.h) {
37
38
process . exit ( ) ;
38
39
}
39
40
40
- var sinks = module . exports . sinks = require ( '../danger.json' ) . sinks ;
41
- var sources = module . exports . sources = require ( '../danger.json' ) . sources ;
42
-
43
41
check . flags . verbose = argv . v ;
44
42
check . flags . recursive = argv . r ;
45
43
if ( argv . j )
@@ -48,75 +46,16 @@ if (argv.j)
48
46
if ( ! argv . j )
49
47
console . log ( ' ---- ' . yellow , file . white ) ;
50
48
51
- var scope = new check . Scope ( {
52
- sources : sources , sinks : sinks ,
49
+ var scope = new Scope ( {
53
50
file : file
54
51
} ) ;
55
52
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
-
114
53
var ast = check . astFromFile ( scope . file ) ;
115
54
check . traverse ( ast , scope ) ;
116
55
117
56
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 ) ) ;
120
59
else
121
60
console . log ( colors . green ( 'No vulneralbities found' ) ) ;
122
61
}
0 commit comments