Skip to content

Commit a3d0fe1

Browse files
committed
SSRFDetector add test case for forcedProtectionOff
1 parent 8669912 commit a3d0fe1

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

agent_api/src/test/java/vulnerabilities/ssrf/SSRFDetectorTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package vulnerabilities.ssrf;
22

3+
import dev.aikido.agent_api.background.Endpoint;
34
import dev.aikido.agent_api.collectors.RedirectCollector;
45
import dev.aikido.agent_api.collectors.URLCollector;
56
import dev.aikido.agent_api.context.Context;
@@ -18,6 +19,7 @@
1819

1920
import static org.junit.jupiter.api.Assertions.*;
2021
import static utils.EmptyAPIResponses.emptyAPIResponse;
22+
import static utils.EmptyAPIResponses.setEmptyConfigWithEndpointList;
2123

2224
public 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

Comments
 (0)