Skip to content

Commit 1a4078e

Browse files
committed
Prevent internal subset entity expansion with XML::Parser
1 parent 29e437a commit 1a4078e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/XML/Simple.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,9 @@ sub build_tree_xml_parser {
453453
sub new_xml_parser {
454454
my($self) = @_;
455455

456-
my $xp = XML::Parser->new(Style => 'Tree', @{$self->{opt}->{parseropts}});
457-
$xp->setHandlers(ExternEnt => sub {return ''});
456+
my $xp = XML::Parser->new(Style => 'Tree', NoExpand => 1,
457+
@{$self->{opt}->{parseropts}});
458+
$xp->setHandlers(ExternEnt => sub {return ''}, Default => sub {});
458459

459460
return $xp;
460461
}

t/E_Internal_Entities.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use strict;
2+
use warnings;
3+
use Test::More;
4+
5+
eval { require XML::Parser; };
6+
if($@) {
7+
plan skip_all => 'no XML::Parser';
8+
}
9+
10+
plan tests => 2;
11+
12+
use XML::Simple;
13+
14+
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
15+
16+
my $xml = qq(<?xml version="1.0"?>
17+
<!DOCTYPE foo [
18+
<!ENTITY b "XML bomb" >]>
19+
<foo>&b;</foo>
20+
);
21+
22+
my $opt = XMLin($xml);
23+
isnt($opt, 'XML bomb', 'Internal subset entity not expanded');
24+
is_deeply($opt, {}, 'Internal subset entity left as empty');
25+
26+
exit(0);

0 commit comments

Comments
 (0)