Skip to content

Commit e3a90b3

Browse files
Merge pull request #228 from AikidoSec/stored-ssrf-fix-valid-imds-case
If the hostname is an IP, skip the stored ssrf vulnerability
2 parents bc94f98 + e36f90c commit e3a90b3

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

agent_api/src/main/java/dev/aikido/agent_api/vulnerabilities/ssrf/imds/Resolver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public static String resolvesToImdsIp(Set<String> resolvedIpAddresses, String ho
1414
return null;
1515
}
1616
for (String ip : resolvedIpAddresses) {
17+
if (hostname.trim().equals(ip.trim())) {
18+
// If the hostname is the IP, that means no resolving is happening
19+
// so the request is safe.
20+
continue;
21+
}
1722
if (IMDSAddresses.isImdsIpAddress(ip)) {
1823
return ip;
1924
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ void testResolvesToImdsIp_WithImdsIp() {
2727
assertEquals("169.254.169.254", Resolver.resolvesToImdsIp(resolvedIps, "example.com"));
2828
}
2929

30+
@Test
31+
void testDoesntResolveToImdsIp_WithHostnameImdsIp() {
32+
Set<String> resolvedIps = new HashSet<>();
33+
resolvedIps.add("169.254.169.254"); // IMDS IP
34+
35+
assertNull(Resolver.resolvesToImdsIp(resolvedIps, " 169.254.169.254 "));
36+
}
37+
3038
@Test
3139
void testResolvesToImdsIp_WithMultipleResolvedIps_OneImdsIp() {
3240
Set<String> resolvedIps = new HashSet<>();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ void run_WhenIpIsIpv6ImdsIp_ReturnsAttack() {
7070
assertNull(result.user);
7171
}
7272

73+
@Test
74+
void run_WhenIpIsIpv6ImdsIp_ReturnsAttackNotWhenIpIsHostname() {
75+
Attack result = detector.run("fd00:ec2::254", List.of("fd00:ec2::254"), "testOperation");
76+
assertNull(result);
77+
}
78+
79+
7380
@Test
7481
void run_WhenIpIsNotImdsIp_ReturnsNull() {
7582
Attack result = detector.run("test.example.com", List.of("192.168.1.1"), "testOperation");

0 commit comments

Comments
 (0)