@@ -6,9 +6,7 @@ const path = require('path')
6
6
7
7
const { UNVALIDATED_REDIRECT } = require ( '../../../../src/appsec/iast/vulnerabilities' )
8
8
const { prepareTestServerForIastInExpress } = require ( '../utils' )
9
- const { storage } = require ( '../../../../../datadog-core' )
10
- const iastContextFunctions = require ( '../../../../src/appsec/iast/iast-context' )
11
- const { newTaintedString } = require ( '../../../../src/appsec/iast/taint-tracking/operations' )
9
+ const Axios = require ( 'axios' )
12
10
13
11
describe ( 'Unvalidated Redirect vulnerability' , ( ) => {
14
12
let redirectFunctions
@@ -24,58 +22,85 @@ describe('Unvalidated Redirect vulnerability', () => {
24
22
fs . unlinkSync ( redirectFunctionsPath )
25
23
} )
26
24
25
+ function getAxiosInstance ( config ) {
26
+ return Axios . create ( {
27
+ baseURL : `http://localhost:${ config . port } `
28
+ } )
29
+ }
30
+
27
31
withVersions ( 'express' , 'express' , version => {
28
32
prepareTestServerForIastInExpress ( 'in express' , version ,
29
33
( testThatRequestHasVulnerability , testThatRequestHasNoVulnerability ) => {
30
34
testThatRequestHasVulnerability ( ( req , res ) => {
31
- const store = storage ( 'legacy' ) . getStore ( )
32
- const iastCtx = iastContextFunctions . getIastContext ( store )
33
- const location = newTaintedString ( iastCtx , 'https://app.com?id=tron' , 'param' , 'Request' )
35
+ const location = req . query . location
34
36
redirectFunctions . insecureWithResHeaderMethod ( 'location' , location , res )
35
37
} , UNVALIDATED_REDIRECT , {
36
38
occurrences : 1 ,
37
39
location : {
38
40
path : redirectFunctionsFilename ,
39
41
line : 4
40
42
}
43
+ } , null , ( done , config ) => {
44
+ getAxiosInstance ( config ) . get ( '/?location=https://app.com?id=tron' ) . catch ( done )
41
45
} )
42
46
43
47
testThatRequestHasVulnerability ( ( req , res ) => {
44
- const store = storage ( 'legacy' ) . getStore ( )
45
- const iastCtx = iastContextFunctions . getIastContext ( store )
46
- const location = newTaintedString ( iastCtx , 'http://user@app.com/' , 'param' , 'Request' )
47
- redirectFunctions . insecureWithResRedirectMethod ( location , res )
48
+ redirectFunctions . insecureWithResRedirectMethod ( req . query . location , res )
48
49
} , UNVALIDATED_REDIRECT , {
49
50
occurrences : 1 ,
50
51
location : {
51
52
path : redirectFunctionsFilename ,
52
53
line : 8
53
54
}
55
+ } , null , ( done , config ) => {
56
+ getAxiosInstance ( config ) . get ( '/?location=http://user@app.com/' ) . catch ( done )
54
57
} )
55
58
56
59
testThatRequestHasVulnerability ( ( req , res ) => {
57
- const store = storage ( 'legacy' ) . getStore ( )
58
- const iastCtx = iastContextFunctions . getIastContext ( store )
59
- const location = newTaintedString ( iastCtx , 'http://user@app.com/' , 'param' , 'Request' )
60
- redirectFunctions . insecureWithResLocationMethod ( location , res )
60
+ redirectFunctions . insecureWithResLocationMethod ( req . query . location , res )
61
61
} , UNVALIDATED_REDIRECT , {
62
62
occurrences : 1 ,
63
63
location : {
64
64
path : redirectFunctionsFilename ,
65
65
line : 12
66
66
}
67
+ } , null , ( done , config ) => {
68
+ getAxiosInstance ( config ) . get ( '/?location=http://user@app.com/' ) . catch ( done )
69
+ } )
70
+
71
+ testThatRequestHasVulnerability ( ( req , res ) => {
72
+ redirectFunctions . insecureWithResLocationMethod ( req . body . location , res )
73
+ } , UNVALIDATED_REDIRECT , {
74
+ occurrences : 1 ,
75
+ location : {
76
+ path : redirectFunctionsFilename ,
77
+ line : 12
78
+ }
79
+ } , null , ( done , config ) => {
80
+ getAxiosInstance ( config ) . post ( '' , {
81
+ location : 'http://user@app.com/'
82
+ } ) . catch ( done )
67
83
} )
68
84
69
85
testThatRequestHasNoVulnerability ( ( req , res ) => {
70
- const store = storage ( 'legacy' ) . getStore ( )
71
- const iastCtx = iastContextFunctions . getIastContext ( store )
72
- const location = newTaintedString ( iastCtx , 'http://user@app.com/' , 'pathParam' , 'Request' )
73
- res . header ( 'X-test' , location )
74
- } , UNVALIDATED_REDIRECT )
86
+ res . header ( 'X-test' , req . query . location )
87
+ } , UNVALIDATED_REDIRECT , ( done , config ) => {
88
+ getAxiosInstance ( config ) . get ( '/?location=http://user@app.com/' ) . catch ( done )
89
+ } )
75
90
76
91
testThatRequestHasNoVulnerability ( ( req , res ) => {
77
92
redirectFunctions . insecureWithResHeaderMethod ( 'location' , 'http://user@app.com/' , res )
78
93
} , UNVALIDATED_REDIRECT )
94
+
95
+ testThatRequestHasNoVulnerability ( ( req , res ) => {
96
+ redirectFunctions . insecureWithResLocationMethod ( req . headers . redirectlocation , res )
97
+ } , UNVALIDATED_REDIRECT , ( done , config ) => {
98
+ getAxiosInstance ( config ) . get ( '' , {
99
+ headers : {
100
+ redirectlocation : 'http://user@app.com/'
101
+ }
102
+ } ) . catch ( done )
103
+ } )
79
104
} )
80
105
} )
81
106
} )
0 commit comments