Skip to content

Commit d0e8dd1

Browse files
committed
Remove global phar config and add checks for allowed protocols
1 parent ea258d4 commit d0e8dd1

File tree

6 files changed

+52
-19
lines changed

6 files changed

+52
-19
lines changed

CHANGELOG.TXT

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
6.9.3 (2025-04-20)
2+
- New fix for "Deserialization of untrusted data" (check on valid protocols).
3+
- Removed global phar configuration.
4+
15
6.9.2 (2025-04-18)
2-
- Fixed "Deserialization of untrusted data" security vulnerability reported by Positive Technologies.
6+
- Quick fix for "Deserialization of untrusted data" security vulnerability reported by Positive Technologies.
7+
- Disable phar protocol globally.
38

49
6.9.1 (2025-04-03)
510
- Fixed "Path Traversal" security vulnerability reported by Positive Technologies.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.9.2
1+
6.9.3

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"barcodes"
1313
],
1414
"homepage": "http://www.tcpdf.org/",
15-
"version": "6.9.2",
15+
"version": "6.9.3",
1616
"license": "LGPL-3.0-or-later",
1717
"authors": [
1818
{

include/tcpdf_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TCPDF_STATIC {
5555
* Current TCPDF version.
5656
* @private static
5757
*/
58-
private static $tcpdf_version = '6.9.2';
58+
private static $tcpdf_version = '6.9.3';
5959

6060
/**
6161
* String alias for total number of pages.

tcpdf.php

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
//============================================================+
33
// File name : tcpdf.php
4-
// Version : 6.9.2
4+
// Version : 6.9.3
55
// Begin : 2002-08-03
66
// Last Update : 2025-04-18
77
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - [email protected]
@@ -104,7 +104,7 @@
104104
* Tools to encode your unicode fonts are on fonts/utils directory.</p>
105105
* @package com.tecnick.tcpdf
106106
* @author Nicola Asuni
107-
* @version 6.9.2
107+
* @version 6.9.3
108108
*/
109109

110110
// TCPDF configuration
@@ -128,7 +128,7 @@
128128
* 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>
129129
* @package com.tecnick.tcpdf
130130
* @brief PHP class for generating PDF documents without requiring external extensions.
131-
* @version 6.9.2
131+
* @version 6.9.3
132132
* @author Nicola Asuni - [email protected]
133133
* @IgnoreAnnotation("protected")
134134
* @IgnoreAnnotation("public")
@@ -6989,7 +6989,7 @@ public function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='', $
69896989
unset($imgdata);
69906990
$imsize = @getimagesize($file);
69916991
if ($imsize === FALSE) {
6992-
unlink($file);
6992+
$this->_unlink($file);
69936993
$file = $original_file;
69946994
}
69956995
}
@@ -7222,7 +7222,7 @@ public function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='', $
72227222
$tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id);
72237223
$img->writeImage($tempname);
72247224
$info = TCPDF_IMAGES::_parsejpeg($tempname);
7225-
unlink($tempname);
7225+
$this->_unlink($tempname);
72267226
$img->destroy();
72277227
} catch(Exception $e) {
72287228
$info = false;
@@ -7858,15 +7858,16 @@ public function _destroy($destroyall=false, $preserve_objcopy=false) {
78587858
if ($handle = @opendir(K_PATH_CACHE)) {
78597859
while ( false !== ( $file_name = readdir( $handle ) ) ) {
78607860
if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0) {
7861-
unlink(K_PATH_CACHE.$file_name);
7861+
$this->_unlink(K_PATH_CACHE.$file_name);
78627862
}
78637863
}
78647864
closedir($handle);
78657865
}
78667866
if (isset($this->imagekeys)) {
78677867
foreach($this->imagekeys as $file) {
7868-
if (strpos($file, K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_') === 0 && TCPDF_STATIC::file_exists($file)) {
7869-
@unlink($file);
7868+
if ((strpos($file, K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_') === 0)
7869+
&& TCPDF_STATIC::file_exists($file)) {
7870+
$this->_unlink($file);
78707871
}
78717872
}
78727873
}
@@ -18875,10 +18876,22 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal
1887518876
* @protected
1887618877
* @since 6.9.1
1887718878
*/
18878-
protected function isRelativePath($path) {
18879+
protected function isRelativePath($path) {
1887918880
return (strpos(str_ireplace('%2E', '.', $this->unhtmlentities($path)), '..') !== false);
1888018881
}
1888118882

18883+
/**
18884+
* Check if it contains a non-allowed external protocol.
18885+
* @param string $path path to check
18886+
* @return boolean true if the protocol is not allowed.
18887+
* @protected
18888+
* @since 6.9.3
18889+
*/
18890+
protected function hasExtForbiddenProtocol($path) {
18891+
return ((strpos($path, '://') !== false)
18892+
&& (preg_match('|^https?://|', $path) !== 1));
18893+
}
18894+
1888218895
/**
1888318896
* Process opening tags.
1888418897
* @param array $dom html dom array
@@ -19078,6 +19091,8 @@ protected function openHTMLTagHandler($dom, $key, $cell) {
1907819091
// get image type from a local file path
1907919092
$imgsrc = substr($imgsrc, 7);
1908019093
$type = TCPDF_IMAGES::getImageFileType($imgsrc);
19094+
} elseif ($this->hasExtForbiddenProtocol($imgsrc)) {
19095+
break;
1908119096
} else {
1908219097
if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
1908319098
// fix image path
@@ -24478,8 +24493,7 @@ protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()
2447824493
$img = '@'.base64_decode(substr($img, strlen($m[0])));
2447924494
} else {
2448024495
// fix image path
24481-
if ($this->isRelativePath($img)) {
24482-
// accessing parent folders is not allowed
24496+
if ($this->isRelativePath($img) || $this->hasExtForbiddenProtocol($img)) {
2448324497
break;
2448424498
}
2448524499
if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) {
@@ -24802,6 +24816,20 @@ protected function fileExists($file)
2480224816
return TCPDF_STATIC::file_exists($file);
2480324817
}
2480424818

24819+
/**
24820+
* Wrapper for unlink with disabled protocols.
24821+
* @param string $file
24822+
* @return bool
24823+
*/
24824+
protected function _unlink($file)
24825+
{
24826+
if ((strpos($file, '://') !== false) && ((substr($file, 0, 7) !== 'file://') || (!$this->allowLocalFiles))) {
24827+
// forbidden protocol
24828+
return false;
24829+
}
24830+
return @unlink($file);
24831+
}
24832+
2480524833
} // END OF TCPDF CLASS
2480624834

2480724835
//============================================================+

tcpdf_autoconfig.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
* @version 1.2.1
4141
*/
4242

43-
// Disable phar stream wrapper to prevent deserialization vulnerability.
44-
if (in_array('phar', stream_get_wrappers(), true)) {
45-
stream_wrapper_unregister('phar');
46-
}
43+
// Disable phar stream wrapper globally.
44+
// if (in_array('phar', stream_get_wrappers(), true)) {
45+
// stream_wrapper_unregister('phar');
46+
// }
4747

4848
// DOCUMENT_ROOT fix for IIS Webserver
4949
if ((!isset($_SERVER['DOCUMENT_ROOT'])) OR (empty($_SERVER['DOCUMENT_ROOT']))) {

0 commit comments

Comments
 (0)