Plugin Directory

Changeset 3068973


Ignore:
Timestamp:
04/11/2024 12:22:12 PM (20 months ago)
Author:
jarednova
Message:

Update to 1.23.1

Location:
timber-library/trunk/lib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • timber-library/trunk/lib/Admin.php

    r2981863 r3068973  
    7474    protected static function update_message_major() {
    7575        $m = '<br><b>Warning:</b> This new version of Timber introduces some major new features which might have unknown effects on your site.';
    76 
    77 
    78         $m .= self::disable_update();
    7976        return $m;
    8077    }
     
    119116        if ( $upgrade_magnitude == 'milestone' ) {
    120117            $message = self::update_message_milestone();
    121             echo '<br />'.sprintf($message);
     118            echo '<br />' . ($message);
    122119            return;
    123120        } elseif ( $upgrade_magnitude == 'major' ) {
    124121            //major version
    125122            $message = self::update_message_major();
    126             echo '<br />'.sprintf($message);
     123            echo '<br />' . ($message);
    127124            return;
    128125        }
    129126        $message = self::update_message_minor();
    130         echo '<br />'.($message);
     127        echo '<br />' . ($message);
    131128        return;
    132129
  • timber-library/trunk/lib/Image.php

    r2800949 r3068973  
    129129            return $this->get_dimensions_loaded($dim);
    130130        }
     131
     132        if (!ImageHelper::is_protocol_allowed($this->file_loc) ) {
     133            throw new \InvalidArgumentException('The output file scheme is not supported.');
     134        }
     135
    131136        if ( file_exists($this->file_loc) && filesize($this->file_loc) ) {
    132137            if ( ImageHelper::is_svg( $this->file_loc ) ) {
  • timber-library/trunk/lib/Image/Operation/ToJpg.php

    r1942747 r3068973  
    4343     */
    4444    public function run( $load_filename, $save_filename ) {
     45        if  (!ImageHelper::is_protocol_allowed($load_filename) ) {
     46            throw new \InvalidArgumentException('The output file scheme is not supported.');
     47        }
    4548
    4649        if ( !file_exists($load_filename) ) {
    4750            return false;
    4851        }
    49        
     52
    5053        // Attempt to check if SVG.
    5154        if ( ImageHelper::is_svg($load_filename) ) {
  • timber-library/trunk/lib/Image/Operation/ToWebp.php

    r1999260 r3068973  
    88
    99/**
    10  * This class is used to process webp images. Not all server configurations support webp. 
     10 * This class is used to process webp images. Not all server configurations support webp.
    1111 * If webp is not enabled, Timber will generate webp images instead
    1212 * @codeCoverageIgnore
     
    4343     */
    4444    public function run( $load_filename, $save_filename ) {
     45        if (!ImageHelper::is_protocol_allowed($load_filename)) {
     46            throw new \InvalidArgumentException('The output file scheme is not supported.');
     47        }
     48
    4549        if (!is_file($load_filename)) {
    4650            return false;
  • timber-library/trunk/lib/ImageHelper.php

    r2603908 r3068973  
    3333    static $home_url;
    3434
     35    protected const ALLOWED_PROTOCOLS = ['file', 'http', 'https'];
     36
     37    protected const WINDOWS_LOCAL_FILENAME_REGEX = '/^[a-z]:(?:[\\\\\/]?(?:[\w\s!#()-]+|[\.]{1,2})+)*[\\\\\/]?/i';
     38
    3539    public static function init() {
    3640        self::$home_url = get_home_url();
     
    122126            return false;
    123127        }
     128
     129        if (!ImageHelper::is_protocol_allowed($file) ) {
     130            throw new \InvalidArgumentException('The output file scheme is not supported.');
     131        }
     132
    124133        //its a gif so test
    125134        if ( !($fh = @fopen($file, 'rb')) ) {
     
    151160     */
    152161    public static function is_svg( $file_path ) {
    153         if ( ! isset( $file_path ) || '' === $file_path || ! file_exists( $file_path ) ) {
     162        if ( ! isset( $file_path ) || '' === $file_path ) {
     163            return false;
     164        }
     165
     166        if (!ImageHelper::is_protocol_allowed($file_path) ) {
     167            throw new \InvalidArgumentException('The output file scheme is not supported.');
     168        }
     169
     170        if ( ! file_exists( $file_path ) ) {
    154171            return false;
    155172        }
     
    367384    public static function sideload_image( $file ) {
    368385        $loc = self::get_sideloaded_file_loc($file);
     386
     387        if  (!ImageHelper::is_protocol_allowed($file) ) {
     388            throw new \InvalidArgumentException('The output file scheme is not supported.');
     389        }
     390
    369391        if ( file_exists($loc) ) {
    370392            return URLHelper::file_system_to_url($loc);
     
    577599        }
    578600
     601        if  (!ImageHelper::is_protocol_allowed($src) ) {
     602            throw new \InvalidArgumentException('The output file scheme is not supported.');
     603        }
     604
    579605        $allow_fs_write = apply_filters('timber/allow_fs_write', true);
    580606
     
    582608            return $src;
    583609        }
    584        
     610
    585611        $external = false;
    586612        // if external image, load it first
     
    683709        return $new_path;
    684710    }
     711
     712    /**
     713     * Checks if the protocol of the given filename is allowed.
     714     *
     715     * This fixes a security issue with a PHAR deserialization vulnerability
     716     * with file_exists() in PHP < 8.0.0.
     717     *
     718     * @param  string $filepath File path.
     719     * @return bool
     720     */
     721    public static function is_protocol_allowed($filepath) {
     722        $parsed_url = \parse_url($filepath);
     723
     724        if (false === $parsed_url) {
     725            throw new \InvalidArgumentException('The filename is not valid.');
     726        }
     727
     728        $protocol = isset($parsed_url['scheme'])
     729            ? \mb_strtolower($parsed_url['scheme'])
     730            : 'file';
     731
     732        if (
     733            \PHP_OS_FAMILY === 'Windows'
     734            && \strlen($protocol) === 1
     735            && \preg_match(self::WINDOWS_LOCAL_FILENAME_REGEX, $filepath)
     736        ) {
     737            $protocol = 'file';
     738        }
     739
     740        return \in_array($protocol, self::ALLOWED_PROTOCOLS, true);
     741    }
    685742}
  • timber-library/trunk/lib/Timber.php

    r2981863 r3068973  
    3636class Timber {
    3737
    38     public static $version = '1.23.0';
     38    public static $version = '1.23.1';
    3939    public static $locations;
    4040    public static $dirname = 'views';
Note: See TracChangeset for help on using the changeset viewer.