33const { expect } = require ( 'chai' )
44const proxyquire = require ( 'proxyquire' )
55const 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+ } =
712 require ( '../../../../src/appsec/iast/taint-tracking/origin-types' )
813
914describe ( 'unvalidated-redirect-analyzer' , ( ) => {
1015 const NOT_TAINTED_LOCATION = 'url.com'
1116 const TAINTED_LOCATION = 'evil.com'
1217
1318 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'
1523
1624 const REFERER_RANGE = {
1725 iinfo : {
@@ -31,21 +39,40 @@ describe('unvalidated-redirect-analyzer', () => {
3139 parameterName : 'param2'
3240 }
3341 }
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+ }
3454
3555 const TaintTrackingMock = {
3656 isTainted : ( iastContext , string ) => {
3757 return string === TAINTED_LOCATION
3858 } ,
3959
4060 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 ]
4976 }
5077 }
5178 }
@@ -103,8 +130,26 @@ describe('unvalidated-redirect-analyzer', () => {
103130 expect ( report ) . to . not . be . called
104131 } )
105132
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+
106151 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 )
108153
109154 expect ( report ) . to . be . called
110155 } )
0 commit comments