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>
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) {