Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static boolean hostnameInUserInput(String userInput, String hostname, int
if (userInputUrl == null || userInputUrl.getHost() == null) {
continue;
}
if (userInputUrl.getHost().equals(hostnameUrl.getHost())) {
if (userInputUrl.getHost().equalsIgnoreCase(hostnameUrl.getHost())) {
if (userInputUrl.getPort() == -1 || port == -1) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ void testItParsesHostnameFromUserInputWithPathBehindIt() {
assertTrue(hostnameInUserInput("http://localhost/path", "localhost", 80));
}

@Test
void testHostnameCapitalizationIsNotImportant() {
assertTrue(hostnameInUserInput("http://Localhost/path", "localhost", 80));
}

@Test
void testHostnameCapitalizationIsNotImportant2() {
assertTrue(hostnameInUserInput("http://localhost/path", "LOCALHOST", 80));
}


@Test
void testItDoesNotParseHostnameFromUserInputWithMisspelledProtocol() {
assertFalse(hostnameInUserInput("http:/localhost", "localhost", 80));
Expand Down
24 changes: 24 additions & 0 deletions agent_api/src/test/java/vulnerabilities/ssrf/SSRFDetectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ public void testSsrfDetectorWithRedirectTo127IP() throws MalformedURLException {
assertEquals("8080", attackData.metadata.get("port"));
}

@Test
@SetEnvironmentVariable(key = "AIKIDO_TOKEN", value = "invalid-token")
public void testSsrfDetectorWithRedirectTo127IPButHostnameCapitalizationDifferent() throws MalformedURLException {
// Setup context :
setContextAndLifecycle("http://Ssrf-redirects.testssandbox.com/ssrf-test");

URLCollector.report(new URL("http://Ssrf-redirects.testssandbox.com/ssrf-test"));
RedirectCollector.report(new URL("http://ssrf-Redirects.testssandbox.com/ssrf-test"), new URL("http://127.0.0.1:8080"));
Attack attackData = new SSRFDetector().run(
"127.0.0.1", 8080,
List.of("127.0.0.1"),
"testop"
);

assertNotNull(attackData);
assertEquals("testop", attackData.operation);
assertEquals("ssrf", attackData.kind);
assertEquals("query", attackData.source);
assertEquals("http://Ssrf-redirects.testssandbox.com/ssrf-test", attackData.payload);
assertEquals(".arg.[0]", attackData.pathToPayload);
assertEquals("127.0.0.1", attackData.metadata.get("hostname"));
assertEquals("8080", attackData.metadata.get("port"));
}

@Test
@SetEnvironmentVariable(key = "AIKIDO_TOKEN", value = "invalid-token")
public void testSsrfDetectorWithRedirectToLocalhost() throws MalformedURLException {
Expand Down