From 2cbde4df2a1c084c669cd91c57e9560a87626773 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Mar 2026 03:08:41 +0100 Subject: [PATCH] Report fix of v23 --- htdocs/core/lib/functions.lib.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b487a4efb50..4bb0f3363c7 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1622,7 +1622,7 @@ if (!function_exists('dol_getprefix')) { * To link to a module file from a module file, use include './mymodulefile'; * To link to a module file from a core file, then this function can be used (call by hook / trigger / speciales pages) * - * @param string $relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...) + * @param string $relpath Relative path to file (Ie: mydir/myfile, ...) * @param string $classname Class name (deprecated) * @return bool True if load is a success, False if it fails */ @@ -1630,6 +1630,17 @@ function dol_include_once($relpath, $classname = '') { global $conf, $langs, $user, $mysoc; // Do not remove this. They must be defined for files we make "include". Other globals var must be retrieved with $GLOBALS['var'] + if (strpos($relpath, '..') !== false) { + // Found a not valid path + dol_syslog('functions::dol_include_once Tried to load a file with a path including a forbidden sequence ".." : ' . $relpath, LOG_WARNING); + return false; + } + if (!preg_match('/\.php$/', $relpath)) { + // Found a not valid path + dol_syslog('functions::dol_include_once Tried to load a file that is not a PHP file : ' . $relpath, LOG_WARNING); + return false; + } + $fullpath = dol_buildpath($relpath); if (!file_exists($fullpath)) {