Skip to content

Commit 1cbe12d

Browse files
committed
N°8632 - param files must be outside iTop
1 parent 924bdab commit 1cbe12d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

application/utils.inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ class utils
181181

182182
protected static function LoadParamFile($sParamFile)
183183
{
184+
if (utils::RealPath($sParamFile, APPROOT) !== false) {
185+
throw new Exception("File '".utils::HtmlEntities($sParamFile)."' should be outside iTop");
186+
}
184187
if (!file_exists($sParamFile)) {
185188
throw new Exception("Could not find the parameter file: '".utils::HtmlEntities($sParamFile)."'");
186189
}

tests/php-unit-tests/unitary-tests/application/utilsTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,27 @@ public function VSprintfProvider()
999999

10001000
public function testLoadParamFile()
10011001
{
1002-
$sTmpFileInsideItop = APPROOT.'env-production/itop-backup/backup.params.distrib';
1003-
$sParamName = 'auth_user';
1004-
$sParamValue = 'admin';
1002+
$sTmpFileInsideItop = APPROOT.'data/test/testLoadParamFile.params';
1003+
$sDir = dirname($sTmpFileInsideItop);
1004+
if (!is_dir($sDir)) {
1005+
mkdir($sDir, 0777, true);
1006+
}
1007+
$sParamName = 'IP1';
1008+
$sParamValue = 'IV1';
1009+
$sParams = <<<INI
1010+
# comment
1011+
$sParamName = $sParamValue
1012+
INI;
1013+
file_put_contents($sTmpFileInsideItop, $sParams);
1014+
1015+
$this->expectException(\Exception::class);
1016+
$this->expectExceptionMessage("File '$sTmpFileInsideItop' should be outside iTop");
1017+
self::InvokeNonPublicStaticMethod(utils::class, 'LoadParamFile', [$sTmpFileInsideItop]);
1018+
self::assertNotEquals($sParamValue, utils::ReadParam($sParamName, null), "utils::LoadParamFile() should NOT have loaded the file: $sTmpFileInsideItop");
1019+
1020+
1021+
$sParamName = 'OP2';
1022+
$sParamValue = 'OV2';
10051023

10061024
$sTmpFileOutsideItop = tempnam(sys_get_temp_dir(), 'utils-test');
10071025
$sParams = <<<INI

0 commit comments

Comments
 (0)