[Koha-bugs] [Bug 12758] Failure when loading or parsing XSLT stylesheets over HTTPS

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Jul 1 11:23:46 CEST 2022


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=12758

--- Comment #18 from Marcel de Rooy <m.de.rooy at rijksmuseum.nl> ---
My plan was somehting like this (unfinished on itself):
Still had to set the flag when I found a https ref.
And check for commented refs.
But this is just way too much imo.


sub _convert_https {
    my ( $self, $code, $key, $params ) = @_;
    my $level = $params->{level} // 0; # to limit recursion level

    if( $level > $self->max_recursion_level ) {
        die; #FIXME Exception
    }

    # Find refs and resolve recursively
    my ( $href, $tmp_name, $new_code, $flag, @replaces, $changed );
    while( $code =~
/<(?:xsl):(?:import|include)\s*href\s*=\s*['"]([^'"]+)['"]/gcs ) {
        $href = $1;
        if( $include_cache->{$href} ) {
            $new_code = $include_cache->{$href};
            $changed = 1;
        } else {
            $new_code = $self->_get_code( $href );
            ( $new_code, $flag )  = $self->_convert_https( $new_code, $href, {
level => $level + 1 } );
            $changed = 1 if $flag;
        }
        next unless $changed;
        $tmpname = MIME::Base64::encode_base64url( $href, q{} );
        if( !$self->{_tempdir} || !-e $self->{_tempdir}. '/'. $tmpname ) {
            $self->{_tempdir} //= File::Temp->newdir;
            write_file( $self->{_tempdir}. '/'. $tmpname, { binmode => ':utf8'
}, Encode::encode_utf8($new_code) );
        }
        push @replaces, { href => $href, file => $self->{_tempdir}. '/'.
$tmpname };
    }

    # Replace refs
    foreach my $h ( @replaces ) {
        $code =~
s/(?=<(?:xsl):(?:import|include)\s*href\s*=\s*)(['"])${h->{href}}['"]/$1${h->{file}}$1/;
    }

    # Finalize
    $include_cache->{$key} = $code if !$self->disable_caching && $changed &&
$key;
    return ( $code, $changed // 0 );
}

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list