|
1 | 1 | <?php |
2 | 2 | //============================================================+ |
3 | 3 | // File name : tcpdf.php |
4 | | -// Version : 6.9.1 |
| 4 | +// Version : 6.9.3 |
5 | 5 | // Begin : 2002-08-03 |
6 | | -// Last Update : 2025-04-03 |
| 6 | +// Last Update : 2025-04-18 |
7 | 7 | // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com |
8 | 8 | // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html) |
9 | 9 | // ------------------------------------------------------------------- |
|
104 | 104 | * Tools to encode your unicode fonts are on fonts/utils directory.</p> |
105 | 105 | * @package com.tecnick.tcpdf |
106 | 106 | * @author Nicola Asuni |
107 | | - * @version 6.9.1 |
| 107 | + * @version 6.9.3 |
108 | 108 | */ |
109 | 109 |
|
110 | 110 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
115 | 115 | * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br> |
116 | 116 | * @package com.tecnick.tcpdf |
117 | 117 | * @brief PHP class for generating PDF documents without requiring external extensions. |
118 | | - * @version 6.9.1 |
| 118 | + * @version 6.9.3 |
119 | 119 | * @author Nicola Asuni - info@tecnick.com |
120 | 120 | * @IgnoreAnnotation("protected") |
121 | 121 | * @IgnoreAnnotation("public") |
@@ -7024,7 +7024,7 @@ public function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='', $ |
7024 | 7024 | unset($imgdata); |
7025 | 7025 | $imsize = @getimagesize($file); |
7026 | 7026 | if ($imsize === FALSE) { |
7027 | | - unlink($file); |
| 7027 | + $this->_unlink($file); |
7028 | 7028 | $file = $original_file; |
7029 | 7029 | } |
7030 | 7030 | } |
@@ -7257,7 +7257,7 @@ public function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='', $ |
7257 | 7257 | $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id); |
7258 | 7258 | $img->writeImage($tempname); |
7259 | 7259 | $info = TCPDF_IMAGES::_parsejpeg($tempname); |
7260 | | - unlink($tempname); |
| 7260 | + $this->_unlink($tempname); |
7261 | 7261 | $img->destroy(); |
7262 | 7262 | } catch(Exception $e) { |
7263 | 7263 | $info = false; |
@@ -7892,16 +7892,17 @@ public function _destroy($destroyall=false, $preserve_objcopy=false) { |
7892 | 7892 | // remove all temporary files |
7893 | 7893 | if ($handle = @opendir(K_PATH_CACHE)) { |
7894 | 7894 | while ( false !== ( $file_name = readdir( $handle ) ) ) { |
7895 | | - if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0 && @TCPDF_STATIC::file_exists(K_PATH_CACHE . $file_name)) { |
7896 | | - @unlink(K_PATH_CACHE . $file_name); |
| 7895 | + if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0) { |
| 7896 | + $this->_unlink(K_PATH_CACHE.$file_name); |
7897 | 7897 | } |
7898 | 7898 | } |
7899 | 7899 | closedir($handle); |
7900 | 7900 | } |
7901 | 7901 | if (isset($this->imagekeys)) { |
7902 | 7902 | foreach($this->imagekeys as $file) { |
7903 | | - if (strpos($file, K_PATH_CACHE) === 0 && TCPDF_STATIC::file_exists($file)) { |
7904 | | - @unlink($file); |
| 7903 | + if ((strpos($file, K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_') === 0) |
| 7904 | + && TCPDF_STATIC::file_exists($file)) { |
| 7905 | + $this->_unlink($file); |
7905 | 7906 | } |
7906 | 7907 | } |
7907 | 7908 | } |
@@ -18929,10 +18930,22 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal |
18929 | 18930 | * @protected |
18930 | 18931 | * @since 6.9.1 |
18931 | 18932 | */ |
18932 | | - protected function isRelativePath($path) { |
| 18933 | + protected function isRelativePath($path) { |
18933 | 18934 | return (strpos(str_ireplace('%2E', '.', $this->unhtmlentities($path)), '..') !== false); |
18934 | 18935 | } |
18935 | 18936 |
|
| 18937 | + /** |
| 18938 | + * Check if it contains a non-allowed external protocol. |
| 18939 | + * @param string $path path to check |
| 18940 | + * @return boolean true if the protocol is not allowed. |
| 18941 | + * @protected |
| 18942 | + * @since 6.9.3 |
| 18943 | + */ |
| 18944 | + protected function hasExtForbiddenProtocol($path) { |
| 18945 | + return ((strpos($path, '://') !== false) |
| 18946 | + && (preg_match('|^https?://|', $path) !== 1)); |
| 18947 | + } |
| 18948 | + |
18936 | 18949 | /** |
18937 | 18950 | * Process opening tags. |
18938 | 18951 | * @param array $dom html dom array |
@@ -19129,11 +19142,13 @@ protected function openHTMLTagHandler($dom, $key, $cell) { |
19129 | 19142 | // accessing parent folders is not allowed |
19130 | 19143 | break; |
19131 | 19144 | } elseif ( $this->allowLocalFiles && substr($imgsrc, 0, 7) === 'file://') { |
19132 | | - // get image type from a local file path |
19133 | | - $imgsrc = substr($imgsrc, 7); |
19134 | | - $type = TCPDF_IMAGES::getImageFileType($imgsrc); |
19135 | | - } else { |
19136 | | - if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/') |
| 19145 | + // get image type from a local file path |
| 19146 | + $imgsrc = substr($imgsrc, 7); |
| 19147 | + $type = TCPDF_IMAGES::getImageFileType($imgsrc); |
| 19148 | + } elseif ($this->hasExtForbiddenProtocol($imgsrc)) { |
| 19149 | + break; |
| 19150 | + } else { |
| 19151 | + if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/') |
19137 | 19152 | AND !@TCPDF_STATIC::file_exists($imgsrc) |
19138 | 19153 | ) { |
19139 | 19154 | // fix image path |
@@ -24534,8 +24549,7 @@ protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array() |
24534 | 24549 | $img = '@'.base64_decode(substr($img, strlen($m[0]))); |
24535 | 24550 | } else { |
24536 | 24551 | // fix image path |
24537 | | - if ($this->isRelativePath($img)) { |
24538 | | - // accessing parent folders is not allowed |
| 24552 | + if ($this->isRelativePath($img) || $this->hasExtForbiddenProtocol($img)) { |
24539 | 24553 | break; |
24540 | 24554 | } |
24541 | 24555 | if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) { |
@@ -24848,6 +24862,20 @@ protected function fileExists($file) |
24848 | 24862 | return TCPDF_STATIC::file_exists($file); |
24849 | 24863 | } |
24850 | 24864 |
|
| 24865 | + /** |
| 24866 | + * Wrapper for unlink with disabled protocols. |
| 24867 | + * @param string $file |
| 24868 | + * @return bool |
| 24869 | + */ |
| 24870 | + protected function _unlink($file) |
| 24871 | + { |
| 24872 | + if ((strpos($file, '://') !== false) && ((substr($file, 0, 7) !== 'file://') || (!$this->allowLocalFiles))) { |
| 24873 | + // forbidden protocol |
| 24874 | + return false; |
| 24875 | + } |
| 24876 | + return @unlink($file); |
| 24877 | + } |
| 24878 | + |
24851 | 24879 | } // END OF TCPDF CLASS |
24852 | 24880 |
|
24853 | 24881 | //============================================================+ |
|
0 commit comments