@@ -22,15 +22,15 @@ protected static function getEnvs()
22
22
]);
23
23
}
24
24
25
- protected function assertEvent (string $ value , $ traces , $ ssrf = false )
25
+ protected function assertEvent (string $ value , $ traces , string $ rasp_rule )
26
26
{
27
27
$ events = AppsecStatus::getInstance ()->getEvents ();
28
28
$ this ->assertEquals (1 , count ($ events ));
29
29
$ this ->assertEquals (1 , count ($ events [0 ][0 ]));
30
- $ key = ! $ ssrf ? "server.io.fs.file " : "server.io.net.url " ;
30
+ $ key = $ rasp_rule == " lfi " ? "server.io.fs.file " : "server.io.net.url " ;
31
31
$ this ->assertEquals ($ value , $ events [0 ][0 ][$ key ]);
32
32
$ this ->assertEquals ('push_addresses ' , $ events [0 ]['eventName ' ]);
33
- $ this ->assertTrue ( $ events [0 ]['rasp ' ]);
33
+ $ this ->assertEquals ( $ rasp_rule , $ events [0 ]['rasp_rule ' ]);
34
34
}
35
35
36
36
public function ssrfProtocols ()
@@ -54,7 +54,7 @@ public function testSsrfProtocols($protocol)
54
54
TestCase::assertSame ('OK ' , $ response );
55
55
});
56
56
57
- $ this ->assertEvent ($ url , $ traces , true );
57
+ $ this ->assertEvent ($ url , $ traces , " ssrf " );
58
58
}
59
59
60
60
public function testInvalidProtocol ()
@@ -80,19 +80,21 @@ public function wrappedFunctions()
80
80
}
81
81
82
82
/**
83
+ * With no protocol all default to files system wrapper and therefore lfi
83
84
* @dataProvider wrappedFunctions
84
85
*/
85
86
public function testNoProtocol ($ targetFunction , $ ssrf )
86
87
{
87
88
$ traces = $ this ->tracesFromWebRequest (function () use ($ targetFunction ) {
88
89
$ response = $ this ->call (GetSpec::create ('Root ' , '/?function= ' .$ targetFunction .'&path=./somefile ' ));
89
-
90
+ //The str_replace replace is because the content of the file is sent to the output on some functions only
90
91
TestCase::assertSame ('OK ' , str_replace ('some content ' , '' , $ response ));
91
92
});
92
- $ this ->assertEvent ('./somefile ' , $ traces , false );
93
+ $ this ->assertEvent ('./somefile ' , $ traces , " lfi " );
93
94
}
94
95
95
96
/**
97
+ * With file protocol always use LFI
96
98
* @dataProvider wrappedFunctions
97
99
*/
98
100
public function testWithFileProtocol ($ targetFunction , $ ssrf )
@@ -101,10 +103,11 @@ public function testWithFileProtocol($targetFunction, $ssrf)
101
103
$ response = $ this ->call (GetSpec::create ('Root ' , '/?function= ' .$ targetFunction .'&path=file://somefile ' ));
102
104
TestCase::assertSame ('OK ' , $ response );
103
105
});
104
- $ this ->assertEvent ('file://somefile ' , $ traces , false );
106
+ $ this ->assertEvent ('file://somefile ' , $ traces , " lfi " );
105
107
}
106
108
107
109
/**
110
+ * HTTP protocol is valid for SSRF
108
111
* @dataProvider wrappedFunctions
109
112
*/
110
113
public function testWithHttpProtocol ($ targetFunction , $ ssrf )
@@ -113,10 +116,9 @@ public function testWithHttpProtocol($targetFunction, $ssrf)
113
116
$ response = $ this ->call (GetSpec::create ('Root ' , '/?function= ' .$ targetFunction .'&path=http://some.url ' ));
114
117
TestCase::assertSame ('OK ' , $ response );
115
118
});
116
- $ events = AppsecStatus::getInstance ()->getEvents ();
117
119
if ($ ssrf ) {
118
- $ this ->assertEvent ('http://some.url ' , $ traces , $ ssrf );
119
- } else { //Only lfi and non valid protocol
120
+ $ this ->assertEvent ('http://some.url ' , $ traces , " ssrf " );
121
+ } else {
120
122
$ this ->assertEquals (0 , count (AppsecStatus::getInstance ()->getEvents ()));
121
123
}
122
124
}
0 commit comments