From 6aee1f378336b778cddff4863e4bbc087ef93407 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 15 Nov 2019 13:19:50 +0000 Subject: [PATCH] Bug 23290: Add test Koha/XSLT/Security.t Content-Type: text/plain; charset=utf-8 Test plan: Run it! --- t/db_dependent/Koha/XSLT/Security.t | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 t/db_dependent/Koha/XSLT/Security.t diff --git a/t/db_dependent/Koha/XSLT/Security.t b/t/db_dependent/Koha/XSLT/Security.t new file mode 100644 index 0000000000..bf0cc335dc --- /dev/null +++ b/t/db_dependent/Koha/XSLT/Security.t @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +# Copyright 2019 Rijksmuseum +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use File::Temp qw/tempfile/; +use Test::More tests => 3; +use Test::Warn; + +use Koha::XSLT::Base; +use t::lib::Mocks; + +t::lib::Mocks::mock_config( 'koha_xslt_security', { expand_entities => 1 } ); +my $engine=Koha::XSLT::Base->new; + +my $secret_file = mytempfile('Big secret'); +my $xslt=<<"EOT"; +]> + + + &secret; + + + + +EOT +my $xslt_file = mytempfile($xslt); + +my $output= $engine->transform( "", $xslt_file ); +like($output, qr/Big secret/, 'external entity got through'); + +t::lib::Mocks::mock_config( 'koha_xslt_security', { expand_entities => 0 } ); +$engine=Koha::XSLT::Base->new; +$output= $engine->transform( "", $xslt_file ); +unlike($output, qr/Big secret/, 'external entity did not get through'); + +# Adding a document call to trigger callback for read_file +# Does not depend on expand_entities; we are not in strict mode now +$xslt=<<"EOT"; + + + + + + +EOT +$xslt_file = mytempfile($xslt); +warning_like { $output= $engine->transform( "", $xslt_file ); } + qr/read_file called in XML::LibXSLT/, + 'Triggered security callback'; + +sub mytempfile { + my ( $fh, $fn ) = tempfile( SUFFIX => '.xsl', UNLINK => 1 ); + print $fh $_[0]//''; + close $fh; + return $fn; +} -- 2.11.0