From 4bfe5d2d4ae87bb741c609328a4c5d4dab278227 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Mar 2026 01:03:34 +0100 Subject: [PATCH] Protect includes (in case dol_include is used without harcoded filename) --- htdocs/core/lib/functions.lib.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index eca46434bcc..d1c1c303e89 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1603,6 +1603,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)) {