Changeset 3068973
- Timestamp:
- 04/11/2024 12:22:12 PM (20 months ago)
- Location:
- timber-library/trunk/lib
- Files:
-
- 6 edited
-
Admin.php (modified) (2 diffs)
-
Image.php (modified) (1 diff)
-
Image/Operation/ToJpg.php (modified) (1 diff)
-
Image/Operation/ToWebp.php (modified) (2 diffs)
-
ImageHelper.php (modified) (7 diffs)
-
Timber.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
timber-library/trunk/lib/Admin.php
r2981863 r3068973 74 74 protected static function update_message_major() { 75 75 $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();79 76 return $m; 80 77 } … … 119 116 if ( $upgrade_magnitude == 'milestone' ) { 120 117 $message = self::update_message_milestone(); 121 echo '<br />' .sprintf($message);118 echo '<br />' . ($message); 122 119 return; 123 120 } elseif ( $upgrade_magnitude == 'major' ) { 124 121 //major version 125 122 $message = self::update_message_major(); 126 echo '<br />' .sprintf($message);123 echo '<br />' . ($message); 127 124 return; 128 125 } 129 126 $message = self::update_message_minor(); 130 echo '<br />' .($message);127 echo '<br />' . ($message); 131 128 return; 132 129 -
timber-library/trunk/lib/Image.php
r2800949 r3068973 129 129 return $this->get_dimensions_loaded($dim); 130 130 } 131 132 if (!ImageHelper::is_protocol_allowed($this->file_loc) ) { 133 throw new \InvalidArgumentException('The output file scheme is not supported.'); 134 } 135 131 136 if ( file_exists($this->file_loc) && filesize($this->file_loc) ) { 132 137 if ( ImageHelper::is_svg( $this->file_loc ) ) { -
timber-library/trunk/lib/Image/Operation/ToJpg.php
r1942747 r3068973 43 43 */ 44 44 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 } 45 48 46 49 if ( !file_exists($load_filename) ) { 47 50 return false; 48 51 } 49 52 50 53 // Attempt to check if SVG. 51 54 if ( ImageHelper::is_svg($load_filename) ) { -
timber-library/trunk/lib/Image/Operation/ToWebp.php
r1999260 r3068973 8 8 9 9 /** 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. 11 11 * If webp is not enabled, Timber will generate webp images instead 12 12 * @codeCoverageIgnore … … 43 43 */ 44 44 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 45 49 if (!is_file($load_filename)) { 46 50 return false; -
timber-library/trunk/lib/ImageHelper.php
r2603908 r3068973 33 33 static $home_url; 34 34 35 protected const ALLOWED_PROTOCOLS = ['file', 'http', 'https']; 36 37 protected const WINDOWS_LOCAL_FILENAME_REGEX = '/^[a-z]:(?:[\\\\\/]?(?:[\w\s!#()-]+|[\.]{1,2})+)*[\\\\\/]?/i'; 38 35 39 public static function init() { 36 40 self::$home_url = get_home_url(); … … 122 126 return false; 123 127 } 128 129 if (!ImageHelper::is_protocol_allowed($file) ) { 130 throw new \InvalidArgumentException('The output file scheme is not supported.'); 131 } 132 124 133 //its a gif so test 125 134 if ( !($fh = @fopen($file, 'rb')) ) { … … 151 160 */ 152 161 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 ) ) { 154 171 return false; 155 172 } … … 367 384 public static function sideload_image( $file ) { 368 385 $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 369 391 if ( file_exists($loc) ) { 370 392 return URLHelper::file_system_to_url($loc); … … 577 599 } 578 600 601 if (!ImageHelper::is_protocol_allowed($src) ) { 602 throw new \InvalidArgumentException('The output file scheme is not supported.'); 603 } 604 579 605 $allow_fs_write = apply_filters('timber/allow_fs_write', true); 580 606 … … 582 608 return $src; 583 609 } 584 610 585 611 $external = false; 586 612 // if external image, load it first … … 683 709 return $new_path; 684 710 } 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 } 685 742 } -
timber-library/trunk/lib/Timber.php
r2981863 r3068973 36 36 class Timber { 37 37 38 public static $version = '1.23. 0';38 public static $version = '1.23.1'; 39 39 public static $locations; 40 40 public static $dirname = 'views';
Note: See TracChangeset
for help on using the changeset viewer.