11package collectors ;
22
3+ import dev .aikido .agent_api .background .cloud .api .events .DetectedAttack ;
34import dev .aikido .agent_api .collectors .DNSRecordCollector ;
45import dev .aikido .agent_api .context .Context ;
56import dev .aikido .agent_api .context .ContextObject ;
7+ import dev .aikido .agent_api .storage .AttackQueue ;
68import dev .aikido .agent_api .storage .Hostnames ;
79import dev .aikido .agent_api .storage .HostnamesStore ;
810import dev .aikido .agent_api .storage .ServiceConfigStore ;
11+ import dev .aikido .agent_api .vulnerabilities .Attack ;
912import dev .aikido .agent_api .vulnerabilities .ssrf .SSRFException ;
1013import dev .aikido .agent_api .vulnerabilities .ssrf .StoredSSRFException ;
1114import 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