Skip to content

Commit 95c72aa

Browse files
committed
Add extra test case for IMDS but with no context set
1 parent 40ccf10 commit 95c72aa

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

agent_api/src/test/java/collectors/DNSRecordCollectorTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package collectors;
22

3+
import dev.aikido.agent_api.background.cloud.api.events.DetectedAttack;
34
import dev.aikido.agent_api.collectors.DNSRecordCollector;
45
import dev.aikido.agent_api.context.Context;
56
import dev.aikido.agent_api.context.ContextObject;
7+
import dev.aikido.agent_api.storage.AttackQueue;
68
import dev.aikido.agent_api.storage.Hostnames;
79
import dev.aikido.agent_api.storage.HostnamesStore;
810
import dev.aikido.agent_api.storage.ServiceConfigStore;
11+
import dev.aikido.agent_api.vulnerabilities.Attack;
912
import dev.aikido.agent_api.vulnerabilities.ssrf.SSRFException;
1013
import dev.aikido.agent_api.vulnerabilities.ssrf.StoredSSRFException;
1114
import org.junit.jupiter.api.*;
@@ -29,12 +32,14 @@ void setup() throws UnknownHostException {
2932
inetAddress1 = InetAddress.getByName("1.1.1.1");
3033
inetAddress2 = InetAddress.getByName("127.0.0.1");
3134
imdsAddress1 = InetAddress.getByName("169.254.169.254");
35+
AttackQueue.clear();
3236
}
3337

3438
@AfterEach
3539
public void cleanup() {
3640
HostnamesStore.clear();
3741
Context.set(null);
42+
AttackQueue.clear();
3843
}
3944

4045
@Test
@@ -129,4 +134,31 @@ public void testHostnameSameWithContextAsAStoredSSRFAttack() {
129134
});
130135
});
131136
}
137+
138+
@Test
139+
public void testStoredSSRFWithNoContext() throws InterruptedException {
140+
ServiceConfigStore.updateBlocking(true);
141+
142+
Context.set(null);
143+
144+
Exception exception = assertThrows(StoredSSRFException.class, () -> {
145+
DNSRecordCollector.report("dev.aikido", new InetAddress[]{
146+
imdsAddress1, inetAddress2
147+
});
148+
});
149+
DetectedAttack.DetectedAttackEvent event = (DetectedAttack.DetectedAttackEvent) AttackQueue.get();
150+
assertEquals("stored_ssrf", event.attack().kind());
151+
assertNull(event.request());
152+
153+
assertEquals("Aikido Zen has blocked a stored server-side request forgery", exception.getMessage());
154+
155+
assertDoesNotThrow(() -> {
156+
DNSRecordCollector.report("metadata.goog", new InetAddress[]{
157+
imdsAddress1, inetAddress2
158+
});
159+
DNSRecordCollector.report("metadata.google.internal", new InetAddress[]{
160+
imdsAddress1, inetAddress2
161+
});
162+
});
163+
}
132164
}

0 commit comments

Comments
 (0)