File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ module.exports = {
17
17
'detect-buffer-noassert' : require ( './rules/detect-buffer-noassert' ) ,
18
18
'detect-child-process' : require ( './rules/detect-child-process' ) ,
19
19
'detect-disable-mustache-escape' : require ( './rules/detect-disable-mustache-escape' ) ,
20
- 'detect-object-injection' : require ( './rules/detect-object-injection' )
20
+ 'detect-object-injection' : require ( './rules/detect-object-injection' ) ,
21
+ 'detect-new-buffer' : require ( './rules/detect-new-buffer' )
21
22
} ,
22
23
rulesConfig : {
23
24
'detect-unsafe-regex' : 0 ,
@@ -31,6 +32,7 @@ module.exports = {
31
32
'detect-buffer-noassert' : 0 ,
32
33
'detect-child-process' : 0 ,
33
34
'detect-disable-mustache-escape' : 0 ,
34
- 'detect-object-injection' : 0
35
+ 'detect-object-injection' : 0 ,
36
+ 'detect-new-buffer' : 0
35
37
}
36
38
} ;
Original file line number Diff line number Diff line change
1
+ module . exports = function ( context ) {
2
+
3
+ var getSource = function ( node ) {
4
+ var token = context . getTokens ( node ) [ 0 ] ;
5
+ return token . loc . start . line + ': ' + context . getSourceLines ( ) . slice ( token . loc . start . line - 1 , token . loc . end . line ) . join ( '\n\t' ) ;
6
+ }
7
+
8
+
9
+ // Detects instances of new Buffer(argument)
10
+ // where argument is any non literal value.
11
+ return {
12
+ "NewExpression" : function ( node ) {
13
+ if ( node . callee . name === 'Buffer' &&
14
+ node . arguments [ 0 ] &&
15
+ node . arguments [ 0 ] . type != 'Literal' ) {
16
+
17
+ return context . report ( node , "Found new Buffer\n\t" + getSource ( node ) ) ;
18
+ }
19
+
20
+
21
+
22
+ }
23
+ } ;
24
+
25
+ }
26
+
You can’t perform that action at this time.
0 commit comments