@@ -203,6 +203,62 @@ public void testSSRFStillRunsWhenPendingPortIsZero() {
203203 assertEquals ("Aikido Zen has blocked a server-side request forgery" , exception .getMessage ());
204204 }
205205
206+ @ Test
207+ public void testPrivateIpLiteralWithNoPendingPortNotRecorded () {
208+ Context .set (null );
209+ DNSRecordCollector .report ("10.20.11.143" , new InetAddress []{inetAddress2 });
210+ assertEquals (0 , HostnamesStore .getHostnamesAsList ().length );
211+ }
212+
213+ @ Test
214+ public void testPrivateIpLiteralWithNoPendingPortNotRecordedButBlockedInLockdown () {
215+ ServiceConfigStore .updateFromAPIResponse (new APIResponse (
216+ true , null , 0L , null , null , null , true , List .of (), true , true , List .of ()
217+ ));
218+ Context .set (null );
219+ assertThrows (BlockedOutboundException .class , () ->
220+ DNSRecordCollector .report ("10.20.11.143" , new InetAddress []{inetAddress2 })
221+ );
222+ assertEquals (0 , HostnamesStore .getHostnamesAsList ().length );
223+ }
224+
225+ @ Test
226+ public void testPrivateIpLiteralWithPendingPortStillRecordedAndBlockedInLockdown () {
227+ ServiceConfigStore .updateFromAPIResponse (new APIResponse (
228+ true , null , 0L , null , null , null , true , List .of (), true , true , List .of ()
229+ ));
230+ PendingHostnamesStore .add ("10.20.11.143" , 443 );
231+ Context .set (mock (ContextObject .class ));
232+
233+ assertThrows (BlockedOutboundException .class , () ->
234+ DNSRecordCollector .report ("10.20.11.143" , new InetAddress []{inetAddress2 })
235+ );
236+ Hostnames .HostnameEntry [] entries = HostnamesStore .getHostnamesAsList ();
237+ assertEquals (1 , entries .length );
238+ assertEquals (443 , entries [0 ].getPort ());
239+ }
240+
241+ @ Test
242+ public void testSsrfStillDetectedForPrivateIpLiteralWithPendingPort () {
243+ ServiceConfigStore .updateBlocking (true );
244+ PendingHostnamesStore .add ("169.254.169.254" , 80 );
245+ Context .set (new EmptySampleContextObject ("http://169.254.169.254:80/latest/meta-data/" ));
246+
247+ Exception exception = assertThrows (SSRFException .class , () ->
248+ DNSRecordCollector .report ("169.254.169.254" , new InetAddress []{imdsAddress1 })
249+ );
250+ assertEquals ("Aikido Zen has blocked a server-side request forgery" , exception .getMessage ());
251+ }
252+
253+ @ Test
254+ public void testNamedHostnameResolvingToPrivateIpWithNoPendingPortStillRecorded () {
255+ Context .set (null );
256+ DNSRecordCollector .report ("internal-service.local" , new InetAddress []{inetAddress2 });
257+ Hostnames .HostnameEntry [] entries = HostnamesStore .getHostnamesAsList ();
258+ assertEquals (1 , entries .length );
259+ assertEquals ("internal-service.local" , entries [0 ].getHostname ());
260+ }
261+
206262 @ Test
207263 public void testStoredSSRFWithNoContext () throws InterruptedException {
208264 ServiceConfigStore .updateBlocking (true );
0 commit comments