11package vulnerabilities .ssrf ;
22
3+ import dev .aikido .agent_api .background .Endpoint ;
34import dev .aikido .agent_api .collectors .RedirectCollector ;
45import dev .aikido .agent_api .collectors .URLCollector ;
56import dev .aikido .agent_api .context .Context ;
1819
1920import static org .junit .jupiter .api .Assertions .*;
2021import static utils .EmptyAPIResponses .emptyAPIResponse ;
22+ import static utils .EmptyAPIResponses .setEmptyConfigWithEndpointList ;
2123
2224public class SSRFDetectorTest {
2325 @ BeforeAll
@@ -34,7 +36,18 @@ private void setContextAndLifecycle(String url) {
3436 Context .set (new EmptySampleContextObject (url ));
3537 ServiceConfigStore .updateFromAPIResponse (emptyAPIResponse );
3638 }
37-
39+ private void setContextAndLifecycle (String url , String route ) {
40+ ServiceConfigStore .updateFromAPIResponse (emptyAPIResponse );
41+ setEmptyConfigWithEndpointList (List .of (
42+ new Endpoint (
43+ /* method */ "*" , /* route */ "/api2/*" ,
44+ /* rlm params */ 0 , 0 ,
45+ /* Allowed IPs */ List .of (), /* graphql */ false ,
46+ /* forceProtectionOff */ true , /* rlm */ false
47+ )
48+ ));
49+ Context .set (new EmptySampleContextObject (url , "http://localhost:3000" + route ));
50+ }
3851
3952 @ Test
4053 @ SetEnvironmentVariable (key = "AIKIDO_TOKEN" , value = "invalid-token" )
@@ -144,4 +157,21 @@ public void testSsrfDetectorWithServiceHostnameInRedirect() throws MalformedURLE
144157
145158 assertNull (attackData );
146159 }
160+
161+ @ Test
162+ @ SetEnvironmentVariable (key = "AIKIDO_TOKEN" , value = "invalid-token" )
163+ public void testSsrfDetectorForcedProtectionOff () throws MalformedURLException {
164+ // Setup context :
165+ setContextAndLifecycle ("http://ssrf-redirects.testssandbox.com/" , "/api2/forced-off-route" );
166+
167+ URLCollector .report (new URL ("http://ssrf-redirects.testssandbox.com/ssrf-test" ));
168+ RedirectCollector .report (new URL ("http://ssrf-redirects.testssandbox.com/ssrf-test" ), new URL ("http://localhost" ));
169+ Attack attackData = SSRFDetector .run (
170+ "localhost" , 80 ,
171+ List .of ("127.0.0.1" ),
172+ "test2nd_op"
173+ );
174+
175+ assertNull (attackData );
176+ }
147177}
0 commit comments