Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion LibXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ use constant {
};

our $XML_LIBXML_PARSE_DEFAULTS = ( XML_PARSE_NODICT );
if ( XML::LibXML::DEFAULT_NONET() ) {
$XML_LIBXML_PARSE_DEFAULTS |= XML_PARSE_NONET;
}

# this hash is made global so that applications can add names for new
# libxml2 parser flags as temporary workaround
Expand Down Expand Up @@ -1088,7 +1091,7 @@ sub _html_options {
$flags |= 64 if $opts->{suppress_warnings};
$flags |= 128 if exists $opts->{pedantic_parser} ? $opts->{pedantic_parser} : $self->pedantic_parser;
$flags |= 256 if exists $opts->{no_blanks} ? $opts->{no_blanks} : !$self->keep_blanks;
$flags |= 2048 if exists $opts->{no_network} ? $opts->{no_network} : !$self->no_network;
$flags |= 2048 if exists $opts->{no_network} ? $opts->{no_network} : 1;
$flags |= 16384 if $opts->{no_cdata};
$flags |= 65536 if $opts->{compact}; # compact small text nodes; no modification
# of the tree allowed afterwards
Expand Down
13 changes: 13 additions & 0 deletions LibXML.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,19 @@ HAVE_READER()
OUTPUT:
RETVAL

# Whether Makefile.PL was run with -DLIBXML_DEFAULT_NONET (user chose
# secure defaults at build time).
int
DEFAULT_NONET()
CODE:
#ifdef LIBXML_DEFAULT_NONET
RETVAL = 1;
#else
RETVAL = 0;
#endif
OUTPUT:
RETVAL

int
HAVE_THREAD_SUPPORT()
CODE:
Expand Down
23 changes: 22 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ my %xsbuild_concat = (
if ($ENV{DEVELOPER}) {
$xsbuild_concat{DEFINE} .= ' -Wall -Wextra -Wno-unused-parameter -Werror=implicit-function-declaration';
}

# Offer to compile with no_network => 1 as the default for all parsers.
# Env var lets automated builds skip the interactive prompt.
if (defined $ENV{XML_LIBXML_DEFAULT_NONET}) {
if ($ENV{XML_LIBXML_DEFAULT_NONET}) {
$xsbuild_concat{DEFINE} .= ' -DLIBXML_DEFAULT_NONET';
print "XML_LIBXML_DEFAULT_NONET=$ENV{XML_LIBXML_DEFAULT_NONET}: enabling no_network by default\n";
}
} else {
my $ans = prompt(
"\nXML::LibXML can forbid network access during XML parsing by default\n"
. "(DTD fetches, entity resolution, schema imports). This is more secure\n"
. "but MAY BREAK existing code that expects network access to be on.\n"
. "Enable no_network by default?",
"n"
);
if (lc($ans) =~ /^y/) {
$xsbuild_concat{DEFINE} .= ' -DLIBXML_DEFAULT_NONET';
}
}

my %xsbuild = Alien::Base::Wrapper->mm_args; # Might contain a definition of DEFINE, must thus concatenate.
while (my ($k, $v) = each %xsbuild_concat) {
my $base_val = $xsbuild{$k};
Expand All @@ -99,7 +120,7 @@ my %WriteMakefileArgs = (
"MIN_PERL_VERSION" => '5.008001',
"VERSION_FROM" => "LibXML.pm",
'META_MERGE' => {
'dynamic_config' => 0,
'dynamic_config' => 1,
'meta-spec' => {version => 2},
'no_index' => {directory => ['xt']},
'resources' => {
Expand Down
18 changes: 13 additions & 5 deletions docs/libxml.dbk
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,13 @@ $parser->input_callbacks($c);
<term>no_network</term>
<listitem>
<para>/parser, html, reader/</para>
<para>Forbid network access; possible values are 0 and 1</para>
<para>Forbid network access; possible values are 0 and 1.
Defaults to 0 unless XML::LibXML was built with
<literal>-DLIBXML_DEFAULT_NONET</literal> (the
<literal>perl Makefile.PL</literal> prompt "Enable no_network
by default?" was answered yes, or
<literal>XML_LIBXML_DEFAULT_NONET=1</literal> was set in the
environment), in which case it defaults to 1.</para>
<para>If set to true, all
attempts to fetch non-local resources (such as
DTD or external entities) will fail (unless
Expand Down Expand Up @@ -5801,8 +5807,9 @@ $rngschema = XML::LibXML::RelaxNG-&gt;new( DOM =&gt; $doc, no_network =&gt; 1 );
</funcsynopsis>

<para>The constructor of XML::LibXML::RelaxNG needs to be called with list of parameters. At least location, string or DOM parameter is required to
specify source of schema. Optional parameter no_network set to 1 cause that parser would not access network and optional parameter recover
set 1 cause that parser would not call die() on errors.</para>
specify source of schema. Optional parameter no_network set to 1 causes the parser to forbid network access (this is already the default
when XML::LibXML was built with <literal>LIBXML_DEFAULT_NONET</literal>). Optional parameter recover
set to 1 causes the parser to not call die() on errors.</para>

<para>It is important, that each schema only have a single source.</para>

Expand Down Expand Up @@ -5868,8 +5875,9 @@ $xmlschema = XML::LibXML::Schema-&gt;new( string =&gt; $xmlschemastring, no_netw
</funcsynopsis>

<para>The constructor of XML::LibXML::Schema needs to be called with list of parameters. At least location or string parameter is required to
specify source of schema. Optional parameter no_network set to 1 cause that parser would not access network and optional parameter recover
set 1 cause that parser would not call die() on errors.</para>
specify source of schema. Optional parameter no_network set to 1 causes the parser to forbid network access (this is already the default
when XML::LibXML was built with <literal>LIBXML_DEFAULT_NONET</literal>). Optional parameter recover
set to 1 causes the parser to not call die() on errors.</para>

<para>It is important, that each schema only have a single source.</para>

Expand Down
3 changes: 2 additions & 1 deletion lib/XML/LibXML/Parser.pod
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ do not generate XINCLUDE START/END nodes; possible values are 0 and 1

/parser, html, reader/

Forbid network access; possible values are 0 and 1
Forbid network access; possible values are 0 and 1. Defaults to 0 unless
XML::LibXML was built with C<<<<<< -DLIBXML_DEFAULT_NONET >>>>>> (the C<<<<<< perl Makefile.PL >>>>>> prompt "Enable no_network by default?" was answered yes, or C<<<<<< XML_LIBXML_DEFAULT_NONET=1 >>>>>> was set in the environment), in which case it defaults to 1.

If set to true, all attempts to fetch non-local resources (such as DTD or
external entities) will fail (unless custom callbacks are defined).
Expand Down
7 changes: 4 additions & 3 deletions lib/XML/LibXML/RelaxNG.pod
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ validation.

The constructor of XML::LibXML::RelaxNG needs to be called with list of
parameters. At least location, string or DOM parameter is required to specify
source of schema. Optional parameter no_network set to 1 cause that parser
would not access network and optional parameter recover set 1 cause that parser
would not call die() on errors.
source of schema. Optional parameter no_network set to 1 causes the parser to
forbid network access (this is already the default when XML::LibXML was built
with C<<<<<< LIBXML_DEFAULT_NONET >>>>>>). Optional parameter recover set to 1 causes the parser to not call die() on
errors.

It is important, that each schema only have a single source.

Expand Down
6 changes: 3 additions & 3 deletions lib/XML/LibXML/Schema.pod
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ validation. As of 2.6.32, libxml2 only supports decimal types up to 24 digits

The constructor of XML::LibXML::Schema needs to be called with list of
parameters. At least location or string parameter is required to specify source
of schema. Optional parameter no_network set to 1 cause that parser would not
access network and optional parameter recover set 1 cause that parser would not
call die() on errors.
of schema. Optional parameter no_network set to 1 causes the parser to forbid
network access (this is already the default when XML::LibXML was built with C<<<<<< LIBXML_DEFAULT_NONET >>>>>>). Optional parameter recover set to 1 causes the parser to not call die() on
errors.

It is important, that each schema only have a single source.

Expand Down
3 changes: 2 additions & 1 deletion t/43options.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ no_network


{
my $nonet_default = XML::LibXML::DEFAULT_NONET();
my $p = XML::LibXML->new();
for my $opt (@all) {
my $ret = 0;
my $ret = ($opt eq 'no_network' && $nonet_default) ? 1 : 0;
# TEST*$all
ok(
($p->get_option($opt)||0) == $ret
Expand Down
Loading