Check for external XML entities in NCIP.pm.
authorJason Stephenson <jason@sigio.com>
Thu, 3 Nov 2016 14:12:19 +0000 (10:12 -0400)
committerJason Stephenson <jason@sigio.com>
Thu, 3 Nov 2016 14:12:19 +0000 (10:12 -0400)
Add an external entity handler to DOM creation in the main NCIP
module's handle_initiation function.  This handler dies and the error
processing catches that error, logs that a possible XXE attack was
detected and then returns undef.

Signed-off-by: Jason Stephenson <jason@sigio.com>
lib/NCIP.pm

index bc61682..7d6bfad 100644 (file)
@@ -103,9 +103,14 @@ sub handle_initiation {
     my $dom;
     my $log = Log::Log4perl->get_logger("NCIP");
 
-    eval { $dom = XML::LibXML->load_xml( string => $xml ); };
+    eval { $dom = XML::LibXML->load_xml( string => $xml, ext_ent_handler => sub { die('XXE'); } ); };
     if ($@) {
+        if ($@ eq 'XXE') {
+            $log->warn('Possible XML External Entity Attack...Bailing out');
+            return;
+        }
         $log->info("Invalid xml we can not parse it ");
+
     }
     if ($dom) {