3
3
const { expect } = require ( 'chai' )
4
4
const proxyquire = require ( 'proxyquire' )
5
5
const overheadController = require ( '../../../../src/appsec/iast/overhead-controller' )
6
- const { HTTP_REQUEST_HEADER_VALUE , HTTP_REQUEST_PARAMETER } =
6
+ const {
7
+ HTTP_REQUEST_HEADER_VALUE ,
8
+ HTTP_REQUEST_PARAMETER ,
9
+ HTTP_REQUEST_PATH ,
10
+ HTTP_REQUEST_PATH_PARAM
11
+ } =
7
12
require ( '../../../../src/appsec/iast/taint-tracking/origin-types' )
8
13
9
14
describe ( 'unvalidated-redirect-analyzer' , ( ) => {
10
15
const NOT_TAINTED_LOCATION = 'url.com'
11
16
const TAINTED_LOCATION = 'evil.com'
12
17
13
18
const TAINTED_HEADER_REFERER_ONLY = 'TAINTED_HEADER_REFERER_ONLY'
14
- const TAINTED_HEADER_REFERER_AMONG_OTHERS = 'TAINTED_HEADER_REFERER_ONLY_AMONG_OTHERS'
19
+ const TAINTED_PATH_PARAMS_ONLY = 'TAINTED_PATH_PARAMS_ONLY'
20
+ const TAINTED_URL_ONLY = 'TAINTED_URL_ONLY'
21
+ const TAINTED_SAFE_RANGES = 'TAINTED_SAFE_RANGES'
22
+ const TAINTED_SAFE_RANGES_AMONG_OTHERS = 'TAINTED_SAFE_RANGES_AMONG_OTHERS'
15
23
16
24
const REFERER_RANGE = {
17
25
iinfo : {
@@ -31,21 +39,40 @@ describe('unvalidated-redirect-analyzer', () => {
31
39
parameterName : 'param2'
32
40
}
33
41
}
42
+ const PATH_PARAM_RANGE = {
43
+ iinfo : {
44
+ type : HTTP_REQUEST_PATH_PARAM ,
45
+ parameterName : 'path_param'
46
+ }
47
+ }
48
+ const URL_RANGE = {
49
+ iinfo : {
50
+ type : HTTP_REQUEST_PATH ,
51
+ parameterName : 'path'
52
+ }
53
+ }
34
54
35
55
const TaintTrackingMock = {
36
56
isTainted : ( iastContext , string ) => {
37
57
return string === TAINTED_LOCATION
38
58
} ,
39
59
40
60
getRanges : ( iastContext , value ) => {
41
- if ( value === NOT_TAINTED_LOCATION ) return null
42
-
43
- if ( value === TAINTED_HEADER_REFERER_ONLY ) {
44
- return [ REFERER_RANGE ]
45
- } else if ( value === TAINTED_HEADER_REFERER_AMONG_OTHERS ) {
46
- return [ REFERER_RANGE , PARAMETER1_RANGE ]
47
- } else {
48
- return [ PARAMETER1_RANGE , PARAMETER2_RANGE ]
61
+ switch ( value ) {
62
+ case NOT_TAINTED_LOCATION :
63
+ return null
64
+ case TAINTED_HEADER_REFERER_ONLY :
65
+ return [ REFERER_RANGE ]
66
+ case TAINTED_PATH_PARAMS_ONLY :
67
+ return [ PATH_PARAM_RANGE ]
68
+ case TAINTED_URL_ONLY :
69
+ return [ URL_RANGE ]
70
+ case TAINTED_SAFE_RANGES :
71
+ return [ REFERER_RANGE , PATH_PARAM_RANGE , URL_RANGE ]
72
+ case TAINTED_SAFE_RANGES_AMONG_OTHERS :
73
+ return [ REFERER_RANGE , PATH_PARAM_RANGE , URL_RANGE , PARAMETER1_RANGE ]
74
+ default :
75
+ return [ PARAMETER1_RANGE , PARAMETER2_RANGE ]
49
76
}
50
77
}
51
78
}
@@ -103,8 +130,26 @@ describe('unvalidated-redirect-analyzer', () => {
103
130
expect ( report ) . to . not . be . called
104
131
} )
105
132
133
+ it ( 'should not report if tainted origin is path param exclusively' , ( ) => {
134
+ unvalidatedRedirectAnalyzer . analyze ( 'Location' , TAINTED_PATH_PARAMS_ONLY )
135
+
136
+ expect ( report ) . to . not . be . called
137
+ } )
138
+
139
+ it ( 'should not report if tainted origin is url exclusively' , ( ) => {
140
+ unvalidatedRedirectAnalyzer . analyze ( 'Location' , TAINTED_URL_ONLY )
141
+
142
+ expect ( report ) . to . not . be . called
143
+ } )
144
+
145
+ it ( 'should not report if all tainted origin are safe' , ( ) => {
146
+ unvalidatedRedirectAnalyzer . analyze ( 'Location' , TAINTED_SAFE_RANGES )
147
+
148
+ expect ( report ) . to . not . be . called
149
+ } )
150
+
106
151
it ( 'should report if tainted origin contains referer header among others' , ( ) => {
107
- unvalidatedRedirectAnalyzer . analyze ( 'Location' , TAINTED_HEADER_REFERER_AMONG_OTHERS )
152
+ unvalidatedRedirectAnalyzer . analyze ( 'Location' , TAINTED_SAFE_RANGES_AMONG_OTHERS )
108
153
109
154
expect ( report ) . to . be . called
110
155
} )
0 commit comments