dtdattacks has asked for the wisdom of the Perl Monks concerning the following question:
Configuration: perl: 5.022000 OS: MSWin32 - MSWin32 required XML::Parser : 2.44 Der Befehl "xmlwf" ist entweder falsch geschrieben oder konnte nicht gefunden werden. expat : <no version information found> Strongly Recommended Scalar::Util : 1.42 (for improved memory man +agement) Encode : 2.73 (for encoding conversion +s) Modules providing additional features XML::XPathEngine : <not available> (to use XML::Twig::XPath +) XML::XPath : <not available> (to use XML::Twig::XPath + if Tree::XPathEngine not available) LWP : 6.13 (for the parseurl method +) HTML::TreeBuilder : 5.03 (to use parse_html and p +arsefile_html) HTML::Entities::Numbered : <not available> (to allow parsing of HTM +L containing named entities) HTML::Tidy : <not available> (to use parse_html and p +arsefile_html with the use_tidy option) HTML::Entities : 3.69 (for the html_encode fil +ter) Tie::IxHash : <not available> (for the keep_atts_order + option) Text::Wrap : 2013.0523 (to use the "wrapped" op +tion for pretty_print) Modules used only by the auto tests Test : 1.26 Test::Pod : 1.50 XML::Simple : 2.20 XML::Handler::YAWriter : <not available> XML::SAX::Writer : <not available> XML::Filter::BufferText : <not available> IO::Scalar : 2.111 IO::CaptureOutput : 1.1104 Please add this information to bug reports (you can run t\zz_dump_conf +ig.t to get it) if you are upgrading the module from a previous version, make sure you + read the Changes file for bug fixes, new features and the occasional COMPATIBIL +ITY WARNING 1..1 ok 1
The file parameterEntity_core.dtd:<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE data [ <!ENTITY % start "<![CDATA["> <!ENTITY % goodies SYSTEM "C:/code/xml_files_windows/xxe.txt"> <!ENTITY % end "]]>"> <!ENTITY % dtd SYSTEM "http://127.0.0.1:5000/parameterEntity_core.dtd" +> %dtd; ]> <data>&all;</data>
The file xxe.txt<!ENTITY all '%start;%goodies;%end;'>
I have a local webserver running on port 5000 where the corresponding files are hosted.it_works
However the parser quits with an exception stating#!/usr/bin/perl use strict; use XML::Twig; my $t= XML::Twig->new(); $t->parsefile('../../xml_files_windows/parameterEntity_core.xml', Pars +eParamEnt => 1); my $root = $t->root; my $content = $root->first_child->text; print $content;
cannot expand %dtd; - cannot load 'http://127.0.0.1:5000/parameterEnti +ty_core.dtd' at C:/Strawberry/perl/vendor/lib/XML/Parser/Expat.pm lin +e 474.
It seems to me that the error message is generated depending on the fact if the variable "$ent_content" is defined.sub _twig_extern_ent { # warn " in _twig_extern_ent...I (", $_[0]->original_string, ")\n +"; # DEBUG handler my( $p, $base, $sysid, $pubid)= @_; my $t= $p->{twig}; if( $t->{twig_no_expand}) { my $ent_name= $t->{twig_keep_encoding} ? $p->original_string : + $p->recognized_string; _twig_insert_ent( $t, $ent_name); return ''; } my $ent_content= eval { $t->{twig_ext_ent_handler}->( $p, $base, $ +sysid) }; if( ! defined $ent_content) { my $ent_name = $p->recognized_string; my $file = _based_filename( $sysid, $base); my $error_message= "cannot expand $ent_name - cannot load '$fi +le'"; if( $t->{twig_extern_ent_nofail}) { return "<!-- $error_messag +e -->"; } else { _croak( $error_message); + } } return $ent_content; }
Now I checked those handlers "initial_ext_ent_handler" and "file_ext_ent_handler" in Parser.pm. As the name indicates "file_ext_ent_handler" does not seem to be able to handle resources provided by http.if( !$args{NoLWP} && ! _use( 'URI') && ! _use( 'URI::File') && ! _u +se( 'LWP')) { $self->{twig_ext_ent_handler}= \&XML::Parser::initial_ext_ent_ +handler } elsif( $args{NoXxe}) { $self->{twig_ext_ent_handler}= sub { my($xp, $base, $path) = @_; $xp->{ErrorMessage}.= "can +not use entities in document when the no_xxe option is on"; return un +def; }; } else { $self->{twig_ext_ent_handler}= \&XML::Parser::file_ext_ent_han +dler }
At first I use no optional parameters/features.$t->parsefile('../../xml_files_windows/parameterEntity_core.xml');
toif( !$args{NoLWP} && ! _use( 'URI') && ! _use( 'URI::File') && ! _use( + 'LWP'))
if( !$args{NoLWP} )
2) The code line 538 is left in the modified version.$t->parsefile('../../xml_files_windows/parameterEntity_core.xml', Pars +eParamEnt => 1);
if( !$args{NoLWP} )
2) For each test run I change the condition to a), b) and c). a)$t->parsefile('../../xml_files_windows/parameterEntity_core.xml', Pars +eParamEnt => 1);
if( !$args{NoLWP} && ! _use( 'URI') )
if( !$args{NoLWP} && ! _use( 'URI::File') )
if( !$args{NoLWP} && ! _use( 'LWP'))
2) I change the handler in both cases to "file_ext_ent_handler" Modified code:if( !$args{NoLWP} && ! _use( 'URI') && ! _use( 'URI::File') && ! _use( + 'LWP'))
3) I call XML::Twig using the ParseParamEnt featureif( !$args{NoLWP} && ! _use( 'URI') && ! _use( 'URI::File') && ! _ +use( 'LWP')) { $self->{twig_ext_ent_handler}= \&XML::Parser::file_ext_ent_han +dler }
$t->parsefile('../../xml_files_windows/parameterEntity_core.xml', Pars +eParamEnt => 1);
2) I call XML::Twig using the ParseParamEnt featureif( !$args{NoLWP} && ! _use( 'URI') && ! _use( 'URI::File') && ! +_use( 'LWP')) { $self->{twig_ext_ent_handler}= \&XML::Parser::file_ext_ent_han +dler } elsif( $args{NoXxe}) { $self->{twig_ext_ent_handler}= sub { my($xp, $base, $path) = @_; $xp->{ErrorMessage}.= "can +not use entities in document when the no_xxe option is on"; return un +def; }; } else { $self->{twig_ext_ent_handler}= \&XML::Parser::initial_ext_ent_ +handler }
$t->parsefile('../../xml_files_windows/parameterEntity_core.xml', Pars +eParamEnt => 1);
is never true on my system and a handler is used which does not support http?if( !$args{NoLWP} && ! _use( 'URI') && ! _use( 'URI::File') && ! _u +se( 'LWP'))
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig Support for Parameter Entities (installed?)
by tye (Sage) on Aug 13, 2015 at 03:45 UTC | |
by Anonymous Monk on Aug 13, 2015 at 03:48 UTC | |
by tye (Sage) on Aug 13, 2015 at 04:05 UTC | |
by shmem (Chancellor) on Aug 13, 2015 at 07:03 UTC | |
by tye (Sage) on Aug 13, 2015 at 07:16 UTC | |
| |
by dtdattacks (Initiate) on Aug 13, 2015 at 07:49 UTC | |
|
Re: XML::Twig Support for Parameter Entities
by Anonymous Monk on Aug 13, 2015 at 00:59 UTC | |
by dtdattacks (Initiate) on Aug 13, 2015 at 07:52 UTC | |
by Anonymous Monk on Aug 13, 2015 at 08:01 UTC |